From 5aac2d712b6052f9f04fc496c80aa588cc360c04 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 17 Aug 2021 05:47:37 +0200 Subject: [PATCH] Fix logging blocks below 0 Fixes #834 --- src/main/java/de/diddiz/LogBlock/Consumer.java | 8 ++++---- src/main/java/de/diddiz/LogBlock/Updater.java | 17 ++++++++++++++++- .../java/de/diddiz/LogBlock/config/Config.java | 2 +- src/main/java/de/diddiz/util/LoggingUtil.java | 12 ++++++------ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/diddiz/LogBlock/Consumer.java b/src/main/java/de/diddiz/LogBlock/Consumer.java index 0e696b9..b075a7d 100644 --- a/src/main/java/de/diddiz/LogBlock/Consumer.java +++ b/src/main/java/de/diddiz/LogBlock/Consumer.java @@ -1135,11 +1135,11 @@ public class Consumer extends Thread { private int safeY(Location loc) { int safeY = loc.getBlockY(); - if (safeY < 0) { - safeY = 0; + if (safeY < Short.MIN_VALUE) { + safeY = Short.MIN_VALUE; } - if (safeY > 65535) { - safeY = 65535; + if (safeY > Short.MAX_VALUE) { + safeY = Short.MAX_VALUE; } return safeY; } diff --git a/src/main/java/de/diddiz/LogBlock/Updater.java b/src/main/java/de/diddiz/LogBlock/Updater.java index e547e87..53e605b 100644 --- a/src/main/java/de/diddiz/LogBlock/Updater.java +++ b/src/main/java/de/diddiz/LogBlock/Updater.java @@ -730,6 +730,7 @@ class Updater { } if (configVersion.compareTo(new ComparableVersion("1.16.0")) < 0) { + logblock.getLogger().info("Updating tables to 1.16.0 ..."); try (Connection conn = logblock.getConnection()) { conn.setAutoCommit(true); final Statement st = conn.createStatement(); @@ -742,6 +743,20 @@ class Updater { } config.set("version", "1.16.0"); } + if (configVersion.compareTo(new ComparableVersion("1.17.0")) < 0) { + logblock.getLogger().info("Updating tables to 1.17.0 ..."); + try (Connection conn = logblock.getConnection()) { + conn.setAutoCommit(true); + final Statement st = conn.createStatement(); + for (final WorldConfig wcfg : getLoggedWorlds()) { + st.executeUpdate("ALTER TABLE `" + wcfg.table + "-blocks` CHANGE `y` `y` SMALLINT(5) NOT NULL"); + } + st.close(); + } catch (final SQLException ex) { + logblock.getLogger().log(Level.SEVERE, "[Updater] Warning: Could not alter table", ex); + } + config.set("version", "1.17.0"); + } if (configVersion.compareTo(new ComparableVersion(Config.CURRENT_CONFIG_VERSION)) < 0) { config.set("version", Config.CURRENT_CONFIG_VERSION); @@ -827,7 +842,7 @@ class Updater { 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(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 + "-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 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)) { diff --git a/src/main/java/de/diddiz/LogBlock/config/Config.java b/src/main/java/de/diddiz/LogBlock/config/Config.java index a30f422..085e680 100644 --- a/src/main/java/de/diddiz/LogBlock/config/Config.java +++ b/src/main/java/de/diddiz/LogBlock/config/Config.java @@ -60,7 +60,7 @@ public class Config { // Not loaded from config - checked at runtime public static boolean mb4 = false; - public static final String CURRENT_CONFIG_VERSION = "1.16.0"; + public static final String CURRENT_CONFIG_VERSION = "1.17.0"; public static enum LogKillsLevel { PLAYERS, diff --git a/src/main/java/de/diddiz/util/LoggingUtil.java b/src/main/java/de/diddiz/util/LoggingUtil.java index afdf0ba..77df123 100644 --- a/src/main/java/de/diddiz/util/LoggingUtil.java +++ b/src/main/java/de/diddiz/util/LoggingUtil.java @@ -52,15 +52,15 @@ public class LoggingUtil { int initialy = loc.getBlockY(); int y = initialy; int z = loc.getBlockZ(); - while (y > 0 && BukkitUtils.canFallIn(loc.getWorld(), x, (y - 1), z)) { + while (y > loc.getWorld().getMinHeight() && BukkitUtils.canFallIn(loc.getWorld(), x, (y - 1), z)) { y--; } if (initialy != y && !BukkitUtils.isEmpty(replaced.getType())) { // this is not the final location but the block got removed (vines etc) consumer.queueBlockBreak(actor, replaced); } - // If y is 0 then the block fell out of the world :( - if (y != 0) { + // If y is minHeight then the block fell out of the world :( + if (y > loc.getWorld().getMinHeight()) { // Run this check to avoid false positives Location finalLoc = new Location(loc.getWorld(), x, y, z); if (y == initialy || !BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) { @@ -94,11 +94,11 @@ public class LoggingUtil { int x = loc.getBlockX(); int y = loc.getBlockY(); int z = loc.getBlockZ(); - while (y > 0 && BukkitUtils.canFallIn(loc.getWorld(), x, (y - 1), z)) { + while (y > loc.getWorld().getMinHeight() && BukkitUtils.canFallIn(loc.getWorld(), x, (y - 1), z)) { y--; } - // If y is 0 then the sand block fell out of the world :( - if (y != 0) { + // If y is minHeight then the sand block fell out of the world :( + if (y > loc.getWorld().getMinHeight()) { Location finalLoc = new Location(loc.getWorld(), x, y, z); // Run this check to avoid false positives if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {