0

5 Commits
v5.2.1 ... dev

Author SHA1 Message Date
David Panić
855ce84f7a Implemented better MySQL connection handling (NEEDS TESTING!) 2019-04-29 23:50:49 +02:00
David Panić
7d3e2a04b2 Bumped version + added devs as authors 2019-04-17 19:55:42 +02:00
David Panić
ec716782e2 Made versions show directly in chat if you add -v to /modules 2019-02-10 02:16:04 +01:00
David Panić
d67e0015b6 Fixed gradle resources 2019-02-10 01:07:29 +01:00
David Panić
cb4b081672 Added bin folder to gitignore 2019-02-10 00:44:06 +01:00
7 changed files with 68 additions and 19 deletions

1
.gitignore vendored
View File

@@ -123,6 +123,7 @@ hs_err_pid*
### Gradle ###
.gradle
build/
bin/
# Ignore Gradle GUI config
gradle-app.setting

View File

@@ -36,4 +36,16 @@ jar {
task sourceJar(type: Jar, dependsOn: classes) {
classifier 'sources'
from sourceSets.main.allSource
}
sourceSets {
main {
resources {
srcDir 'src/main/java'
include '**/*.cmd'
srcDir 'src/main/resources'
include '**/*.yml'
}
}
}

View File

@@ -4,10 +4,22 @@ command modules {
perm moduleloader.modules.list;
run list;
}
-v {
help Lists all modules and their versions. Color indicates status: §aENABLED §cDISABLED;
perm moduleloader.modules.list;
run listversions;
}
list {
help Lists all modules. Color indicates status: §aENABLED §cDISABLED;
perm moduleloader.modules.list;
run list;
}
list -v {
help Lists all modules and their versions. Color indicates status: §aENABLED §cDISABLED;
perm moduleloader.modules.list;
run listversions;
}
load [string:name...] {
help (Re)-Loads a module. WARNING: Handle with care! This has direct affect on code being executed. This command will temporarily halt the main thread until the class loading operation was completed.;

View File

@@ -561,15 +561,25 @@ public final class ModuleLoader implements CoreModule {
return Main.plugin;
}
@Command (hook = "list", async = AsyncType.ALWAYS)
public boolean listModulesCommand(CommandSender sender) {
return listModules(sender, false);
}
@Command (hook = "listversions", async = AsyncType.ALWAYS)
public boolean listModulesVerionsCommand(CommandSender sender) {
return listModules(sender, true);
}
/**
* This method lists all modules to the specified CommandSender. The modules will be color coded correspondingly to their enabled status.
*
* @param sender The person to send the info to, usually the issuer of the command or the console sender.
* @param showVersions Should we show the versions directly in chat.
*
* @return true.
*/
@Command (hook = "list", async = AsyncType.ALWAYS)
public boolean listModulesCommand(CommandSender sender) {
public boolean listModules(CommandSender sender, boolean showVersions) {
boolean hasCategorys = hasCategories();
Message m = new Message(sender, null);
ModuleInfo ml_info = moduleInfos.get(instance);
@@ -587,7 +597,7 @@ public final class ModuleLoader implements CoreModule {
for (Module mod : mods) {
ModuleInfo info = moduleInfos.get(mod);
m.appendTextHover((modules.get(mod) ? "§a" : "§c") + info.getDisplayName(), info.getModuleInfoHover());
m.appendTextHover((modules.get(mod) ? "§a" : "§c") + info.getDisplayName() + (showVersions ? " &e" + info.getVersion() : ""), info.getModuleInfoHover());
if (curModule != mods.size())
m.appendText("&7, ");

View File

@@ -55,10 +55,10 @@ public class MysqlHandler {
}
public MysqlDatabase getDatabase(String databaseName) {
return new MysqlDatabase(getConnection(databaseName));
return new MysqlDatabase(this, databaseName);
}
private Connection getConnection(String databaseName) throws IllegalStateException {
public Connection getConnection(String databaseName) throws IllegalStateException {
Connection connection = null;
try {
connection = DriverManager.getConnection(url + databaseName, username, password);
@@ -76,7 +76,7 @@ public class MysqlHandler {
ResultSet queryResults = metadata.getCatalogs();
while (queryResults.next()) {
String databaseName = queryResults.getString("TABLE_CAT");
databases.add(new MysqlDatabase(getConnection(databaseName)));
databases.add(new MysqlDatabase(this, databaseName));
}
connection.close();
return databases;

View File

@@ -1,5 +1,6 @@
package com.redstoner.misc.mysql.elements;
import com.redstoner.misc.mysql.MysqlHandler;
import com.redstoner.misc.mysql.MysqlQueryHandler;
import java.sql.Connection;
@@ -10,10 +11,14 @@ import java.util.ArrayList;
import java.util.List;
public class MysqlDatabase {
private Connection connection;
private Connection connection = null;
public MysqlDatabase(Connection connection) {
this.connection = connection;
private final MysqlHandler handler;
private final String databaseName;
public MysqlDatabase(MysqlHandler handler, String databaseName) {
this.handler = handler;
this.databaseName = databaseName;
}
public MysqlTable getTable(String name) {
@@ -21,7 +26,7 @@ public class MysqlDatabase {
}
public boolean createTable(String name, MysqlField... description) {
return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE `" + name + "` " + getDescription(description) + ";");
return MysqlQueryHandler.queryNoResult(getConnection(), "CREATE TABLE `" + name + "` " + getDescription(description) + ";");
}
private String getDescription(MysqlField... description) {
@@ -47,20 +52,20 @@ public class MysqlDatabase {
}
public boolean createTableIfNotExists(String name, MysqlField... description) {
return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE IF NOT EXISTS `" + name + "` " + getDescription(description) + ";");
return MysqlQueryHandler.queryNoResult(getConnection(), "CREATE TABLE IF NOT EXISTS `" + name + "` " + getDescription(description) + ";");
}
public boolean dropTable(String name) {
return MysqlQueryHandler.queryNoResult(connection, "DROP TABLE `" + name + "`;");
return MysqlQueryHandler.queryNoResult(getConnection(), "DROP TABLE `" + name + "`;");
}
public boolean drop() {
return MysqlQueryHandler.queryNoResult(connection, "DROP DATABASE `" + getName() + "`;");
return MysqlQueryHandler.queryNoResult(getConnection(), "DROP DATABASE `" + getName() + "`;");
}
public String getName() {
try {
return connection.getCatalog();
return getConnection().getCatalog();
} catch (SQLException e) {
e.printStackTrace();
return null;
@@ -70,7 +75,7 @@ public class MysqlDatabase {
public List<MysqlTable> getTables() {
try {
List<MysqlTable> tables = new ArrayList<>();
DatabaseMetaData metadata = connection.getMetaData();
DatabaseMetaData metadata = getConnection().getMetaData();
ResultSet queryResults = metadata.getTables(null, null, "%", null);
while (queryResults.next()) {
@@ -84,7 +89,16 @@ public class MysqlDatabase {
}
}
protected Connection getConnection() {
Connection getConnection() {
try {
if (connection == null || connection.isClosed()) {
connection = handler.getConnection(databaseName);
}
} catch (SQLException e) {
e.printStackTrace();
connection = handler.getConnection(databaseName);
}
return connection;
}
}

View File

@@ -1,5 +1,5 @@
name: ModuleLoader
version: 5.2.1
authors: [pepich1851]
version: 5.2.2
authors: [pepich1851, psrcek, LogalDeveloper, Minenash]
main: com.redstoner.misc.Main
softdepend: [Vault]
softdepend: [Vault]