From fe7e24489855b5c00192c2eceee453f99618f727 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Thu, 18 Mar 2021 21:25:10 +0100 Subject: [PATCH 1/8] Do not scroll in a result set when we don't have to --- .../java/de/diddiz/LogBlock/CommandsHandler.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/diddiz/LogBlock/CommandsHandler.java b/src/main/java/de/diddiz/LogBlock/CommandsHandler.java index 5052cb0..d3cd581 100755 --- a/src/main/java/de/diddiz/LogBlock/CommandsHandler.java +++ b/src/main/java/de/diddiz/LogBlock/CommandsHandler.java @@ -517,13 +517,12 @@ public class CommandsHandler implements CommandExecutor { state = conn.createStatement(); rs = executeQuery(state, params.getQuery()); sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle() + ":"); - if (rs.next()) { - rs.beforeFirst(); - final List blockchanges = new ArrayList<>(); - final LookupCacheElementFactory factory = new LookupCacheElementFactory(params, sender instanceof Player ? 2 / 3f : 1); - while (rs.next()) { - blockchanges.add(factory.getLookupCacheElement(rs)); - } + final List blockchanges = new ArrayList<>(); + final LookupCacheElementFactory factory = new LookupCacheElementFactory(params, sender instanceof Player ? 2 / 3f : 1); + while (rs.next()) { + blockchanges.add(factory.getLookupCacheElement(rs)); + } + if (!blockchanges.isEmpty()) { LookupCacheElement[] blockChangeArray = blockchanges.toArray(new LookupCacheElement[blockchanges.size()]); if (!params.noCache) { getSession(sender).lookupCache = blockChangeArray; From c20b677507df7eba33ffb54194a50367b01bd3ad Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 13 Apr 2021 18:24:54 +0200 Subject: [PATCH 2/8] Improve table creation logic --- src/main/java/de/diddiz/LogBlock/Updater.java | 14 +++++++++----- .../java/de/diddiz/LogBlock/config/Config.java | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/diddiz/LogBlock/Updater.java b/src/main/java/de/diddiz/LogBlock/Updater.java index 67ca04a..36b4b29 100644 --- a/src/main/java/de/diddiz/LogBlock/Updater.java +++ b/src/main/java/de/diddiz/LogBlock/Updater.java @@ -842,11 +842,15 @@ class Updater { } private void createTable(DatabaseMetaData dbm, Statement state, String table, String query) throws SQLException { - if (!dbm.getTables(null, null, table, null).next()) { - logblock.getLogger().log(Level.INFO, "Creating table " + table + "."); - state.execute("CREATE TABLE `" + table + "` " + query); - if (!dbm.getTables(null, null, table, null).next()) { - throw new SQLException("Table " + table + " not found and failed to create"); + try (ResultSet tableResult = dbm.getTables(Config.mysqlDatabase, null, table, null)) { + if (!tableResult.next()) { + logblock.getLogger().log(Level.INFO, "Creating table " + table + "."); + state.execute("CREATE TABLE `" + table + "` " + query); + try (ResultSet tableResultNew = dbm.getTables(Config.mysqlDatabase, null, table, null)) { + if (!tableResultNew.next()) { + throw new SQLException("Table " + table + " not found and failed to create"); + } + } } } } diff --git a/src/main/java/de/diddiz/LogBlock/config/Config.java b/src/main/java/de/diddiz/LogBlock/config/Config.java index 38e9950..a30f422 100644 --- a/src/main/java/de/diddiz/LogBlock/config/Config.java +++ b/src/main/java/de/diddiz/LogBlock/config/Config.java @@ -25,6 +25,7 @@ public class Config { private static LoggingEnabledMapping superWorldConfig; private static Map worldConfigs; public static String url, user, password; + public static String mysqlDatabase; public static boolean mysqlUseSSL; public static boolean mysqlRequireSSL; public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun; @@ -175,7 +176,8 @@ public class Config { ComparableVersion configVersion = new ComparableVersion(config.getString("version")); boolean oldConfig = configVersion.compareTo(new ComparableVersion(CURRENT_CONFIG_VERSION)) < 0; - url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database"); + mysqlDatabase = getStringIncludingInts(config, "mysql.database"); + url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + mysqlDatabase; user = getStringIncludingInts(config, "mysql.user"); password = getStringIncludingInts(config, "mysql.password"); mysqlUseSSL = config.getBoolean("mysql.useSSL", true); From 0fd3266c7b47851a528bb3fbf558cfb4d6a76d8e Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 13 Apr 2021 18:32:16 +0200 Subject: [PATCH 3/8] Load the new mysql driver class if available --- src/main/java/de/diddiz/LogBlock/LogBlock.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/diddiz/LogBlock/LogBlock.java b/src/main/java/de/diddiz/LogBlock/LogBlock.java index 36a849e..e45b204 100644 --- a/src/main/java/de/diddiz/LogBlock/LogBlock.java +++ b/src/main/java/de/diddiz/LogBlock/LogBlock.java @@ -73,7 +73,11 @@ public class LogBlock extends JavaPlugin { } try { getLogger().info("Connecting to " + user + "@" + url + "..."); - Class.forName("com.mysql.jdbc.Driver"); + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + } catch (ClassNotFoundException ignored) { + Class.forName("com.mysql.jdbc.Driver"); + } pool = new MySQLConnectionPool(url, user, password, mysqlUseSSL, mysqlRequireSSL); final Connection conn = getConnection(true); if (conn == null) { From 87074da8a12f742a4a83bcd3ed52b7388f7fbec4 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 13 Apr 2021 20:53:56 +0200 Subject: [PATCH 4/8] Release Logblock 1.16.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 78d6c6d..2337c74 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.diddiz logblock - 1.16.1.2-SNAPSHOT + 1.16.5 jar LogBlock From 8148386e3ed3c64187e7b22cd0cee8c9c1606855 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 13 Apr 2021 21:01:37 +0200 Subject: [PATCH 5/8] Back to snapshots --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2337c74..25214fd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.diddiz logblock - 1.16.5 + 1.16.5.1-SNAPSHOT jar LogBlock From 2049a7a7a45b604750a248bab418ec9d51a438eb Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Wed, 14 Apr 2021 18:52:06 +0200 Subject: [PATCH 6/8] Use a different way to check for existing tables --- src/main/java/de/diddiz/LogBlock/Updater.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/diddiz/LogBlock/Updater.java b/src/main/java/de/diddiz/LogBlock/Updater.java index 36b4b29..294de53 100644 --- a/src/main/java/de/diddiz/LogBlock/Updater.java +++ b/src/main/java/de/diddiz/LogBlock/Updater.java @@ -808,9 +808,8 @@ class Updater { throw new SQLException("No connection"); } final Statement state = conn.createStatement(); - final DatabaseMetaData dbm = conn.getMetaData(); conn.setAutoCommit(true); - createTable(dbm, state, "lb-players", "(playerid INT UNSIGNED NOT NULL AUTO_INCREMENT, UUID varchar(36) NOT NULL, playername varchar(32) NOT NULL, firstlogin DATETIME NOT NULL, lastlogin DATETIME NOT NULL, onlinetime INT UNSIGNED NOT NULL, ip varchar(255) NOT NULL, PRIMARY KEY (playerid), INDEX (UUID), INDEX (playername)) DEFAULT CHARSET " + charset); + createTable(state, "lb-players", "(playerid INT UNSIGNED NOT NULL AUTO_INCREMENT, UUID varchar(36) NOT NULL, playername varchar(32) NOT NULL, firstlogin DATETIME NOT NULL, lastlogin DATETIME NOT NULL, onlinetime INT UNSIGNED NOT NULL, ip varchar(255) NOT NULL, PRIMARY KEY (playerid), INDEX (UUID), INDEX (playername)) DEFAULT CHARSET " + charset); // Players table must not be empty or inserts won't work - bug #492 final ResultSet rs = state.executeQuery("SELECT NULL FROM `lb-players` LIMIT 1;"); if (!rs.next()) { @@ -818,35 +817,35 @@ class Updater { } if (isLogging(Logging.CHAT) || isLogging(Logging.PLAYER_COMMANDS) || isLogging(Logging.CONSOLE_COMMANDS) || isLogging(Logging.COMMANDBLOCK_COMMANDS)) { try { - createTable(dbm, state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, message VARCHAR(256) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid), FULLTEXT message (message)) DEFAULT CHARSET " + charset); + createTable(state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, message VARCHAR(256) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid), FULLTEXT message (message)) DEFAULT CHARSET " + charset); } catch (SQLException e) { - createTable(dbm, state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, message VARCHAR(256) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid)) DEFAULT CHARSET " + charset); + createTable(state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, message VARCHAR(256) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid)) DEFAULT CHARSET " + charset); } } - createTable(dbm, state, "lb-materials", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset); - createTable(dbm, state, "lb-blockstates", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset); - createTable(dbm, state, "lb-entitytypes", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset); + createTable(state, "lb-materials", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset); + createTable(state, "lb-blockstates", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset); + createTable(state, "lb-entitytypes", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset); for (final WorldConfig wcfg : getLoggedWorlds()) { - createTable(dbm, state, wcfg.table + "-blocks", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, replaced SMALLINT UNSIGNED NOT NULL, replacedData SMALLINT NOT NULL, type SMALLINT UNSIGNED NOT NULL, typeData SMALLINT NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT UNSIGNED NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))"); - createTable(dbm, state, wcfg.table + "-chestdata", "(id INT UNSIGNED NOT NULL, item MEDIUMBLOB, itemremove TINYINT, itemtype SMALLINT NOT NULL DEFAULT '0', PRIMARY KEY (id))"); - createTable(dbm, state, wcfg.table + "-state", "(id INT UNSIGNED NOT NULL, replacedState MEDIUMBLOB NULL, typeState MEDIUMBLOB NULL, PRIMARY KEY (id))"); + createTable(state, wcfg.table + "-blocks", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, replaced SMALLINT UNSIGNED NOT NULL, replacedData SMALLINT NOT NULL, type SMALLINT UNSIGNED NOT NULL, typeData SMALLINT NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT UNSIGNED NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))"); + createTable(state, wcfg.table + "-chestdata", "(id INT UNSIGNED NOT NULL, item MEDIUMBLOB, itemremove TINYINT, itemtype SMALLINT NOT NULL DEFAULT '0', PRIMARY KEY (id))"); + createTable(state, wcfg.table + "-state", "(id INT UNSIGNED NOT NULL, replacedState MEDIUMBLOB NULL, typeState MEDIUMBLOB NULL, PRIMARY KEY (id))"); if (wcfg.isLogging(Logging.KILL)) { - createTable(dbm, state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer INT UNSIGNED, victim INT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id))"); + createTable(state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer INT UNSIGNED, victim INT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id))"); } - createTable(dbm, state, wcfg.table + "-entityids", "(entityid INT UNSIGNED NOT NULL AUTO_INCREMENT, entityuuid VARCHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, PRIMARY KEY (entityid), UNIQUE KEY (entityuuid))"); - createTable(dbm, state, wcfg.table + "-entities", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, entityid INT UNSIGNED NOT NULL, entitytypeid INT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, action TINYINT UNSIGNED NOT NULL, data MEDIUMBLOB NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid), KEY entityid (entityid))"); + createTable(state, wcfg.table + "-entityids", "(entityid INT UNSIGNED NOT NULL AUTO_INCREMENT, entityuuid VARCHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, PRIMARY KEY (entityid), UNIQUE KEY (entityuuid))"); + createTable(state, wcfg.table + "-entities", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, entityid INT UNSIGNED NOT NULL, entitytypeid INT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, action TINYINT UNSIGNED NOT NULL, data MEDIUMBLOB NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid), KEY entityid (entityid))"); } state.close(); conn.close(); } - private void createTable(DatabaseMetaData dbm, Statement state, String table, String query) throws SQLException { - try (ResultSet tableResult = dbm.getTables(Config.mysqlDatabase, null, table, null)) { + private void createTable(Statement state, String table, String query) throws SQLException { + try (ResultSet tableResult = state.executeQuery("SHOW TABLES LIKE '" + table + "'")) { if (!tableResult.next()) { logblock.getLogger().log(Level.INFO, "Creating table " + table + "."); state.execute("CREATE TABLE `" + table + "` " + query); - try (ResultSet tableResultNew = dbm.getTables(Config.mysqlDatabase, null, table, null)) { + try (ResultSet tableResultNew = state.executeQuery("SHOW TABLES LIKE '" + table + "'")) { if (!tableResultNew.next()) { throw new SQLException("Table " + table + " not found and failed to create"); } From 1df380741ba4ed4557410d48fa51ffc99749c60f Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Thu, 15 Apr 2021 03:19:14 +0200 Subject: [PATCH 7/8] Release 1.16.5.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 25214fd..1abab87 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.diddiz logblock - 1.16.5.1-SNAPSHOT + 1.16.5.1 jar LogBlock From cb1231eab532d81c9aba4f05e96ae8696037e98b Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Thu, 15 Apr 2021 03:23:55 +0200 Subject: [PATCH 8/8] Snapshots --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1abab87..bd8e951 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.diddiz logblock - 1.16.5.1 + 1.16.5.2-SNAPSHOT jar LogBlock