From 4e43a42662fe84351ae718478f23870cb6b84425 Mon Sep 17 00:00:00 2001 From: Intelli Date: Wed, 12 Jul 2023 15:17:14 -0600 Subject: [PATCH] Added logging and rollback support for double sided signs --- .../net/coreprotect/bukkit/BukkitAdapter.java | 36 ++++- .../coreprotect/bukkit/BukkitInterface.java | 12 +- .../net/coreprotect/bukkit/Bukkit_v1_17.java | 14 +- .../net/coreprotect/bukkit/Bukkit_v1_20.java | 54 ++++++++ .../java/net/coreprotect/consumer/Queue.java | 4 +- .../consumer/process/SignTextProcess.java | 2 +- .../consumer/process/SignUpdateProcess.java | 4 +- .../net/coreprotect/database/Database.java | 10 +- .../java/net/coreprotect/database/Lookup.java | 41 +++++- .../database/logger/SignTextLogger.java | 18 ++- .../database/lookup/SignMessageLookup.java | 41 +++++- .../database/statement/SignStatement.java | 54 +++++--- .../listener/block/BlockBreakListener.java | 16 ++- .../listener/block/BlockExplodeListener.java | 25 +++- .../listener/block/BlockPlaceListener.java | 27 ++-- .../player/PlayerInteractListener.java | 61 ++++++--- .../listener/player/SignChangeListener.java | 72 ++++++++-- .../net/coreprotect/paper/PaperAdapter.java | 9 +- .../net/coreprotect/paper/Paper_v1_20.java | 21 +++ .../coreprotect/patch/script/__2_22_0.java | 127 ++++++++++++++++++ .../net/coreprotect/spigot/SpigotAdapter.java | 34 ++++- .../coreprotect/spigot/SpigotInterface.java | 8 ++ .../net/coreprotect/spigot/Spigot_v1_20.java | 38 ++++++ .../java/net/coreprotect/utility/Util.java | 19 +++ .../worldedit/WorldEditLogger.java | 22 +-- 25 files changed, 660 insertions(+), 109 deletions(-) create mode 100644 src/main/java/net/coreprotect/paper/Paper_v1_20.java create mode 100644 src/main/java/net/coreprotect/patch/script/__2_22_0.java create mode 100644 src/main/java/net/coreprotect/spigot/Spigot_v1_20.java diff --git a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java index 292f625b..4a9b9c8d 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java @@ -3,6 +3,8 @@ import java.util.List; import java.util.Map; +import org.bukkit.Color; +import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -131,13 +133,13 @@ public Class getFrameClass(Material material) { } @Override - public boolean isGlowing(Sign sign) { + public boolean isGlowing(Sign sign, boolean isFront) { return false; } @Override - public void setGlowing(Sign sign, boolean set) { - return; + public boolean isWaxed(Sign sign) { + return false; } @Override @@ -150,4 +152,32 @@ public ItemStack adjustIngredient(MerchantRecipe recipe, ItemStack itemStack) { return null; } + @Override + public void setGlowing(Sign sign, boolean isFront, boolean isGlowing) { + return; + } + + @Override + public void setColor(Sign sign, boolean isFront, int color) { + if (!isFront) { + return; + } + + sign.setColor(DyeColor.getByColor(Color.fromRGB(color))); + } + + @Override + public void setWaxed(Sign sign, boolean isWaxed) { + return; + } + + @Override + public int getColor(Sign sign, boolean isFront) { + if (isFront) { + return sign.getColor().getColor().asRGB(); + } + + return 0; + } + } diff --git a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java index 818029a9..110013c5 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java @@ -43,14 +43,22 @@ public interface BukkitInterface { public boolean isItemFrame(Material material); - public boolean isGlowing(Sign sign); + public boolean isGlowing(Sign sign, boolean isFront); public boolean isInvisible(Material material); + public boolean isWaxed(Sign sign); + public int getMinHeight(World world); public int getLegacyBlockId(Material material); - public void setGlowing(Sign sign, boolean b); + public void setGlowing(Sign sign, boolean isFront, boolean isGlowing); + + public void setColor(Sign sign, boolean isFront, int color); + + public void setWaxed(Sign sign, boolean isWaxed); + + public int getColor(Sign sign, boolean isFront); } diff --git a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java index 0dfb6265..595fc794 100644 --- a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java +++ b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java @@ -218,13 +218,21 @@ public Class getFrameClass(Material material) { } @Override - public boolean isGlowing(Sign sign) { + public boolean isGlowing(Sign sign, boolean isFront) { + if (!isFront) { + return false; + } + return sign.isGlowingText(); } @Override - public void setGlowing(Sign sign, boolean set) { - sign.setGlowingText(set); + public void setGlowing(Sign sign, boolean isFront, boolean isGlowing) { + if (!isFront) { + return; + } + + sign.setGlowingText(isGlowing); } @Override diff --git a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java index 46609e84..f672ff99 100644 --- a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java +++ b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java @@ -3,7 +3,11 @@ import java.util.Arrays; import java.util.HashSet; +import org.bukkit.Color; +import org.bukkit.DyeColor; import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; import net.coreprotect.model.BlockGroup; @@ -14,4 +18,54 @@ public Bukkit_v1_20() { BlockGroup.UPDATE_STATE = new HashSet<>(Arrays.asList(Material.TORCH, Material.WALL_TORCH, Material.REDSTONE_WIRE, Material.RAIL, Material.POWERED_RAIL, Material.DETECTOR_RAIL, Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER, Material.LEVER, Material.REDSTONE_TORCH, Material.REDSTONE_WALL_TORCH, Material.GLOWSTONE, Material.JACK_O_LANTERN, Material.REPEATER, Material.REDSTONE_LAMP, Material.BEACON, Material.COMPARATOR, Material.DAYLIGHT_DETECTOR, Material.REDSTONE_BLOCK, Material.HOPPER, Material.CHEST, Material.TRAPPED_CHEST, Material.ACTIVATOR_RAIL, Material.SOUL_TORCH, Material.SOUL_WALL_TORCH, Material.SHROOMLIGHT, Material.RESPAWN_ANCHOR, Material.CRYING_OBSIDIAN, Material.TARGET, Material.SMALL_AMETHYST_BUD, Material.MEDIUM_AMETHYST_BUD, Material.LARGE_AMETHYST_BUD, Material.AMETHYST_CLUSTER, Material.CAVE_VINES, Material.CAVE_VINES_PLANT, Material.GLOW_LICHEN, Material.LIGHT, Material.LAVA_CAULDRON, Material.CHISELED_BOOKSHELF)); } + @Override + public void setGlowing(Sign sign, boolean isFront, boolean isGlowing) { + if (isFront) { + sign.getSide(Side.FRONT).setGlowingText(isGlowing); + } + else { + sign.getSide(Side.BACK).setGlowingText(isGlowing); + } + } + + @Override + public void setColor(Sign sign, boolean isFront, int color) { + if (isFront) { + sign.getSide(Side.FRONT).setColor(DyeColor.getByColor(Color.fromRGB(color))); + } + else { + sign.getSide(Side.BACK).setColor(DyeColor.getByColor(Color.fromRGB(color))); + } + } + + @Override + public void setWaxed(Sign sign, boolean isWaxed) { + sign.setWaxed(isWaxed); + } + + @Override + public int getColor(Sign sign, boolean isFront) { + if (isFront) { + return sign.getSide(Side.FRONT).getColor().getColor().asRGB(); + } + else { + return sign.getSide(Side.BACK).getColor().getColor().asRGB(); + } + } + + @Override + public boolean isGlowing(Sign sign, boolean isFront) { + if (isFront) { + return sign.getSide(Side.FRONT).isGlowingText(); + } + else { + return sign.getSide(Side.BACK).isGlowingText(); + } + } + + @Override + public boolean isWaxed(Sign sign) { + return sign.isWaxed(); + } + } diff --git a/src/main/java/net/coreprotect/consumer/Queue.java b/src/main/java/net/coreprotect/consumer/Queue.java index 660a0589..e3e0219b 100755 --- a/src/main/java/net/coreprotect/consumer/Queue.java +++ b/src/main/java/net/coreprotect/consumer/Queue.java @@ -352,7 +352,7 @@ protected static void queueRollbackUpdate(String user, Location location, List signs = Consumer.consumerSigns.get(processId); if (signs.get(id) != null) { Object[] SIGN_DATA = signs.get(id); - SignTextLogger.log(preparedStmt, batchCount, user, location, action, color, (Integer) SIGN_DATA[0], (String) SIGN_DATA[1], (String) SIGN_DATA[2], (String) SIGN_DATA[3], (String) SIGN_DATA[4], forceData); + SignTextLogger.log(preparedStmt, batchCount, user, location, action, color, (Integer) SIGN_DATA[0], (Integer) SIGN_DATA[1], (Boolean) SIGN_DATA[2], (Boolean) SIGN_DATA[3], (String) SIGN_DATA[4], (String) SIGN_DATA[5], (String) SIGN_DATA[6], (String) SIGN_DATA[7], (String) SIGN_DATA[8], (String) SIGN_DATA[9], (String) SIGN_DATA[10], (String) SIGN_DATA[11], forceData); signs.remove(id); } } diff --git a/src/main/java/net/coreprotect/consumer/process/SignUpdateProcess.java b/src/main/java/net/coreprotect/consumer/process/SignUpdateProcess.java index 51838369..c410d98c 100644 --- a/src/main/java/net/coreprotect/consumer/process/SignUpdateProcess.java +++ b/src/main/java/net/coreprotect/consumer/process/SignUpdateProcess.java @@ -26,10 +26,10 @@ static void process(Statement statement, Object object, String user, int action, int userid = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT)); String query = ""; if (action == 0) { - query = "SELECT color, data, line_1, line_2, line_3, line_4 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time < '" + time + "' ORDER BY rowid DESC LIMIT 0, 1"; + query = "SELECT color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time < '" + time + "' ORDER BY rowid DESC LIMIT 0, 1"; } else { - query = "SELECT color, data, line_1, line_2, line_3, line_4 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time >= '" + time + "' ORDER BY rowid ASC LIMIT 0, 1"; + query = "SELECT color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time >= '" + time + "' ORDER BY rowid ASC LIMIT 0, 1"; } SignStatement.getData(statement, block, query); Util.updateBlock(block); diff --git a/src/main/java/net/coreprotect/database/Database.java b/src/main/java/net/coreprotect/database/Database.java index da6dd3ac..29f733d8 100755 --- a/src/main/java/net/coreprotect/database/Database.java +++ b/src/main/java/net/coreprotect/database/Database.java @@ -215,7 +215,7 @@ else if (table == 2) { public static PreparedStatement prepareStatement(Connection connection, int type, boolean keys) { PreparedStatement preparedStatement = null; try { - String signInsert = "INSERT INTO " + ConfigHandler.prefix + "sign (time, user, wid, x, y, z, action, color, data, line_1, line_2, line_3, line_4) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + String signInsert = "INSERT INTO " + ConfigHandler.prefix + "sign (time, user, wid, x, y, z, action, color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; String blockInsert = "INSERT INTO " + ConfigHandler.prefix + "block (time, user, wid, x, y, z, type, data, meta, blockdata, action, rolled_back) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; String skullInsert = "INSERT INTO " + ConfigHandler.prefix + "skull (time, owner) VALUES (?, ?)"; String containerInsert = "INSERT INTO " + ConfigHandler.prefix + "container (time, user, wid, x, y, z, type, data, amount, metadata, action, rolled_back) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -348,7 +348,7 @@ public static void createDatabaseTables(String prefix, boolean purge) { index = ", INDEX(time), INDEX(user,time), INDEX(wid,x,z,time)"; statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "command(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int, user int, wid int, x int, y int (3), z int, message varchar(16000)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)"; - statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data int, amount int, metadata blob, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); + statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data int, amount int, slot tinyint, metadata blob, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)"; statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data blob, amount int, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "database_lock(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),status tinyint,time int) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); @@ -362,7 +362,7 @@ public static void createDatabaseTables(String prefix, boolean purge) { index = ", INDEX(wid,x,z,time), INDEX(action,time), INDEX(user,time), INDEX(time)"; statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "session(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int, user int, wid int, x int, y int (3), z int, action tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(time)"; - statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int, user int, wid int, x int, y int, z int, action tinyint, color int, data tinyint, line_1 varchar(100), line_2 varchar(100), line_3 varchar(100), line_4 varchar(100)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); + statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int, user int, wid int, x int, y int, z int, action tinyint, color int, color_secondary int, data tinyint, waxed tinyint, face tinyint, line_1 varchar(100), line_2 varchar(100), line_3 varchar(100), line_4 varchar(100), line_5 varchar(100), line_6 varchar(100), line_7 varchar(100), line_8 varchar(100)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "skull(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, owner varchar(64)) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); index = ", INDEX(user), INDEX(uuid)"; statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "user(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int,user varchar(100),uuid varchar(64)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4"); @@ -426,7 +426,7 @@ else if (type.equalsIgnoreCase("index")) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "command (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, message TEXT);"); } if (!tableData.contains(prefix + "container")) { - statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data INTEGER, amount INTEGER, metadata BLOB, action INTEGER, rolled_back INTEGER);"); + statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data INTEGER, amount INTEGER, slot INTEGER, metadata BLOB, action INTEGER, rolled_back INTEGER);"); } if (!tableData.contains(prefix + "item")) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data BLOB, amount INTEGER, action INTEGER, rolled_back INTEGER);"); @@ -450,7 +450,7 @@ else if (type.equalsIgnoreCase("index")) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "session (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER);"); } if (!tableData.contains(prefix + "sign")) { - statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER, color INTEGER, data INTEGER, line_1 TEXT, line_2 TEXT, line_3 TEXT, line_4 TEXT);"); + statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER, color INTEGER, color_secondary INTEGER, data INTEGER, waxed INTEGER, face INTEGER, line_1 TEXT, line_2 TEXT, line_3 TEXT, line_4 TEXT, line_5 TEXT, line_6 TEXT, line_7 TEXT, line_8 TEXT);"); } if (!tableData.contains(prefix + "skull")) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "skull (id INTEGER PRIMARY KEY ASC, time INTEGER, owner TEXT);"); diff --git a/src/main/java/net/coreprotect/database/Lookup.java b/src/main/java/net/coreprotect/database/Lookup.java index 4e8dd3a5..93b9b2b9 100755 --- a/src/main/java/net/coreprotect/database/Lookup.java +++ b/src/main/java/net/coreprotect/database/Lookup.java @@ -191,36 +191,65 @@ else if (actionList.contains(10)) { int resultX = results.getInt("x"); int resultY = results.getInt("y"); int resultZ = results.getInt("z"); + boolean isFront = results.getInt("face") == 0; String line1 = results.getString("line_1"); String line2 = results.getString("line_2"); String line3 = results.getString("line_3"); String line4 = results.getString("line_4"); + String line5 = results.getString("line_5"); + String line6 = results.getString("line_6"); + String line7 = results.getString("line_7"); + String line8 = results.getString("line_8"); StringBuilder message = new StringBuilder(); - if (line1 != null && line1.length() > 0) { + if (isFront && line1 != null && line1.length() > 0) { message.append(line1); if (!line1.endsWith(" ")) { message.append(" "); } } - if (line2 != null && line2.length() > 0) { + if (isFront && line2 != null && line2.length() > 0) { message.append(line2); if (!line2.endsWith(" ")) { message.append(" "); } } - if (line3 != null && line3.length() > 0) { + if (isFront && line3 != null && line3.length() > 0) { message.append(line3); if (!line3.endsWith(" ")) { message.append(" "); } } - if (line4 != null && line4.length() > 0) { + if (isFront && line4 != null && line4.length() > 0) { message.append(line4); if (!line4.endsWith(" ")) { message.append(" "); } } + if (!isFront && line5 != null && line5.length() > 0) { + message.append(line5); + if (!line5.endsWith(" ")) { + message.append(" "); + } + } + if (!isFront && line6 != null && line6.length() > 0) { + message.append(line6); + if (!line6.endsWith(" ")) { + message.append(" "); + } + } + if (!isFront && line7 != null && line7.length() > 0) { + message.append(line7); + if (!line7.endsWith(" ")) { + message.append(" "); + } + } + if (!isFront && line8 != null && line8.length() > 0) { + message.append(line8); + if (!line8.endsWith(" ")) { + message.append(" "); + } + } Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultWorldId, resultX, resultY, resultZ, message.toString() }; list.add(dataArray); @@ -596,7 +625,7 @@ else if (inventoryQuery || actionExclude.length() > 0 || includeBlock.length() > } if (actionList.contains(10)) { - queryBlock = queryBlock + " action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) AND"; + queryBlock = queryBlock + " action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0 OR LENGTH(line_5) > 0 OR LENGTH(line_6) > 0 OR LENGTH(line_7) > 0 OR LENGTH(line_8) > 0) AND"; } if (queryBlock.length() > 0) { @@ -649,7 +678,7 @@ else if (actionList.contains(9)) { } else if (actionList.contains(10)) { queryTable = "sign"; - rows = "rowid as id,time,user,wid,x,y,z,line_1,line_2,line_3,line_4"; + rows = "rowid as id,time,user,wid,x,y,z,face,line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8"; } else if (actionList.contains(11)) { queryTable = "item"; diff --git a/src/main/java/net/coreprotect/database/logger/SignTextLogger.java b/src/main/java/net/coreprotect/database/logger/SignTextLogger.java index f9152968..aa4ef064 100644 --- a/src/main/java/net/coreprotect/database/logger/SignTextLogger.java +++ b/src/main/java/net/coreprotect/database/logger/SignTextLogger.java @@ -18,7 +18,7 @@ private SignTextLogger() { throw new IllegalStateException("Database class"); } - public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int action, int color, int data, String line1, String line2, String line3, String line4, int timeOffset) { + public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int action, int color, int colorSecondary, int data, boolean isWaxed, boolean isFront, String line1, String line2, String line3, String line4, String line5, String line6, String line7, String line8, int timeOffset) { try { if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { return; @@ -33,7 +33,21 @@ public static void log(PreparedStatement preparedStmt, int batchCount, String us int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - SignStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action, color, data, line1, line2, line3, line4); + + if (line1.isEmpty() && line2.isEmpty() && line3.isEmpty() && line4.isEmpty()) { + line1 = null; + line2 = null; + line3 = null; + line4 = null; + } + if (line5.isEmpty() && line6.isEmpty() && line7.isEmpty() && line8.isEmpty()) { + line5 = null; + line6 = null; + line7 = null; + line8 = null; + } + + SignStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action, color, colorSecondary, data, isWaxed ? 1 : 0, isFront ? 0 : 1, line1, line2, line3, line4, line5, line6, line7, line8); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java b/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java index e0df0b74..1d19a505 100644 --- a/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java +++ b/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java @@ -55,7 +55,7 @@ else if (commandSender.hasPermission("coreprotect.coreprotect")) { int rowMax = page * limit; int pageStart = rowMax - limit; - String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) LIMIT 0, 1"; + String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0 OR LENGTH(line_5) > 0 OR LENGTH(line_6) > 0 OR LENGTH(line_7) > 0 OR LENGTH(line_8) > 0) LIMIT 0, 1"; ResultSet results = statement.executeQuery(query); while (results.next()) { @@ -65,7 +65,7 @@ else if (commandSender.hasPermission("coreprotect.coreprotect")) { int totalPages = (int) Math.ceil(count / (limit + 0.0)); - query = "SELECT time,user,line_1,line_2,line_3,line_4 FROM " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + ""; + query = "SELECT time,user,face,line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8 FROM " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0 OR LENGTH(line_5) > 0 OR LENGTH(line_6) > 0 OR LENGTH(line_7) > 0 OR LENGTH(line_8) > 0) ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + ""; results = statement.executeQuery(query); while (results.next()) { @@ -75,32 +75,61 @@ else if (commandSender.hasPermission("coreprotect.coreprotect")) { String line2 = results.getString("line_2"); String line3 = results.getString("line_3"); String line4 = results.getString("line_4"); + String line5 = results.getString("line_5"); + String line6 = results.getString("line_6"); + String line7 = results.getString("line_7"); + String line8 = results.getString("line_8"); + boolean isFront = results.getInt("face") == 0; StringBuilder message = new StringBuilder(); - if (line1 != null && line1.length() > 0) { + if (isFront && line1 != null && line1.length() > 0) { message.append(line1); if (!line1.endsWith(" ")) { message.append(" "); } } - if (line2 != null && line2.length() > 0) { + if (isFront && line2 != null && line2.length() > 0) { message.append(line2); if (!line2.endsWith(" ")) { message.append(" "); } } - if (line3 != null && line3.length() > 0) { + if (isFront && line3 != null && line3.length() > 0) { message.append(line3); if (!line3.endsWith(" ")) { message.append(" "); } } - if (line4 != null && line4.length() > 0) { + if (isFront && line4 != null && line4.length() > 0) { message.append(line4); if (!line4.endsWith(" ")) { message.append(" "); } } + if (!isFront && line5 != null && line5.length() > 0) { + message.append(line5); + if (!line5.endsWith(" ")) { + message.append(" "); + } + } + if (!isFront && line6 != null && line6.length() > 0) { + message.append(line6); + if (!line6.endsWith(" ")) { + message.append(" "); + } + } + if (!isFront && line7 != null && line7.length() > 0) { + message.append(line7); + if (!line7.endsWith(" ")) { + message.append(" "); + } + } + if (!isFront && line8 != null && line8.length() > 0) { + message.append(line8); + if (!line8.endsWith(" ")) { + message.append(" "); + } + } String parsedMessage = message.toString(); if (parsedMessage.contains("§x")) { diff --git a/src/main/java/net/coreprotect/database/statement/SignStatement.java b/src/main/java/net/coreprotect/database/statement/SignStatement.java index 4a712d48..d53b6f43 100644 --- a/src/main/java/net/coreprotect/database/statement/SignStatement.java +++ b/src/main/java/net/coreprotect/database/statement/SignStatement.java @@ -4,12 +4,12 @@ import java.sql.ResultSet; import java.sql.Statement; -import org.bukkit.Color; -import org.bukkit.DyeColor; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import net.coreprotect.bukkit.BukkitAdapter; +import net.coreprotect.spigot.SpigotAdapter; +import net.coreprotect.utility.Util; public class SignStatement { @@ -17,7 +17,7 @@ private SignStatement() { throw new IllegalStateException("Database class"); } - public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int action, int color, int data, String line1, String line2, String line3, String line4) { + public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int action, int color, int colorSecondary, int data, int waxed, int face, String line1, String line2, String line3, String line4, String line5, String line6, String line7, String line8) { try { preparedStmt.setInt(1, time); preparedStmt.setInt(2, id); @@ -27,11 +27,18 @@ public static void insert(PreparedStatement preparedStmt, int batchCount, int ti preparedStmt.setInt(6, z); preparedStmt.setInt(7, action); preparedStmt.setInt(8, color); - preparedStmt.setInt(9, data); - preparedStmt.setString(10, line1); - preparedStmt.setString(11, line2); - preparedStmt.setString(12, line3); - preparedStmt.setString(13, line4); + preparedStmt.setInt(9, colorSecondary); + preparedStmt.setInt(10, data); + preparedStmt.setInt(11, waxed); + preparedStmt.setInt(12, face); + preparedStmt.setString(13, line1); + preparedStmt.setString(14, line2); + preparedStmt.setString(15, line3); + preparedStmt.setString(16, line4); + preparedStmt.setString(17, line5); + preparedStmt.setString(18, line6); + preparedStmt.setString(19, line7); + preparedStmt.setString(20, line8); preparedStmt.addBatch(); if (batchCount > 0 && batchCount % 1000 == 0) { @@ -54,24 +61,39 @@ public static void getData(Statement statement, BlockState block, String query) while (resultSet.next()) { int color = resultSet.getInt("color"); + int colorSecondary = resultSet.getInt("color_secondary"); int data = resultSet.getInt("data"); + boolean isWaxed = resultSet.getInt("waxed") == 1; + // boolean isFront = resultSet.getInt("face") == 0; String line1 = resultSet.getString("line_1"); String line2 = resultSet.getString("line_2"); String line3 = resultSet.getString("line_3"); String line4 = resultSet.getString("line_4"); + String line5 = resultSet.getString("line_5"); + String line6 = resultSet.getString("line_6"); + String line7 = resultSet.getString("line_7"); + String line8 = resultSet.getString("line_8"); if (color > 0) { - sign.setColor(DyeColor.getByColor(Color.fromRGB(color))); + BukkitAdapter.ADAPTER.setColor(sign, true, color); } - - if (data > 0) { - BukkitAdapter.ADAPTER.setGlowing(sign, (data == 1 ? true : false)); + if (colorSecondary > 0) { + BukkitAdapter.ADAPTER.setColor(sign, false, colorSecondary); } - sign.setLine(0, line1); - sign.setLine(1, line2); - sign.setLine(2, line3); - sign.setLine(3, line4); + boolean frontGlowing = Util.isSideGlowing(true, data); + boolean backGlowing = Util.isSideGlowing(false, data); + BukkitAdapter.ADAPTER.setGlowing(sign, true, frontGlowing); + BukkitAdapter.ADAPTER.setGlowing(sign, false, backGlowing); + SpigotAdapter.ADAPTER.setLine(sign, 0, line1); + SpigotAdapter.ADAPTER.setLine(sign, 1, line2); + SpigotAdapter.ADAPTER.setLine(sign, 2, line3); + SpigotAdapter.ADAPTER.setLine(sign, 3, line4); + SpigotAdapter.ADAPTER.setLine(sign, 4, line5); + SpigotAdapter.ADAPTER.setLine(sign, 5, line6); + SpigotAdapter.ADAPTER.setLine(sign, 6, line7); + SpigotAdapter.ADAPTER.setLine(sign, 7, line8); + BukkitAdapter.ADAPTER.setWaxed(sign, isWaxed); } resultSet.close(); diff --git a/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java b/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java index c6393d6c..d1a3c99d 100644 --- a/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java +++ b/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java @@ -283,9 +283,19 @@ else if (!isAttached(block, scanBlock, scanMin)) { String line2 = PaperAdapter.ADAPTER.getLine(sign, 1); String line3 = PaperAdapter.ADAPTER.getLine(sign, 2); String line4 = PaperAdapter.ADAPTER.getLine(sign, 3); - int color = sign.getColor().getColor().asRGB(); - boolean isGlowing = BukkitAdapter.ADAPTER.isGlowing(sign); - Queue.queueSignText(user, location, 0, color, isGlowing, line1, line2, line3, line4, 5); + String line5 = PaperAdapter.ADAPTER.getLine(sign, 4); + String line6 = PaperAdapter.ADAPTER.getLine(sign, 5); + String line7 = PaperAdapter.ADAPTER.getLine(sign, 6); + String line8 = PaperAdapter.ADAPTER.getLine(sign, 7); + + boolean isFront = true; + int color = BukkitAdapter.ADAPTER.getColor(sign, isFront); + int colorSecondary = BukkitAdapter.ADAPTER.getColor(sign, !isFront); + boolean frontGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, isFront); + boolean backGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, !isFront); + boolean isWaxed = BukkitAdapter.ADAPTER.isWaxed(sign); + + Queue.queueSignText(user, location, 0, color, colorSecondary, frontGlowing, backGlowing, isWaxed, isFront, line1, line2, line3, line4, line5, line6, line7, line8, 5); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/coreprotect/listener/block/BlockExplodeListener.java b/src/main/java/net/coreprotect/listener/block/BlockExplodeListener.java index 859ff0bb..32dba8f8 100644 --- a/src/main/java/net/coreprotect/listener/block/BlockExplodeListener.java +++ b/src/main/java/net/coreprotect/listener/block/BlockExplodeListener.java @@ -26,6 +26,7 @@ import net.coreprotect.consumer.Queue; import net.coreprotect.database.Database; import net.coreprotect.model.BlockGroup; +import net.coreprotect.paper.PaperAdapter; public final class BlockExplodeListener extends Queue implements Listener { @@ -118,13 +119,23 @@ else if (scanType.hasGravity() && Config.getConfig(world).BLOCK_MOVEMENT) { try { Location location = blockState.getLocation(); Sign sign = (Sign) blockState; - String line1 = sign.getLine(0); - String line2 = sign.getLine(1); - String line3 = sign.getLine(2); - String line4 = sign.getLine(3); - int color = sign.getColor().getColor().asRGB(); - boolean isGlowing = BukkitAdapter.ADAPTER.isGlowing(sign); - Queue.queueSignText(user, location, 0, color, isGlowing, line1, line2, line3, line4, 5); + String line1 = PaperAdapter.ADAPTER.getLine(sign, 0); + String line2 = PaperAdapter.ADAPTER.getLine(sign, 1); + String line3 = PaperAdapter.ADAPTER.getLine(sign, 2); + String line4 = PaperAdapter.ADAPTER.getLine(sign, 3); + String line5 = PaperAdapter.ADAPTER.getLine(sign, 4); + String line6 = PaperAdapter.ADAPTER.getLine(sign, 5); + String line7 = PaperAdapter.ADAPTER.getLine(sign, 6); + String line8 = PaperAdapter.ADAPTER.getLine(sign, 7); + + boolean isFront = true; + int color = BukkitAdapter.ADAPTER.getColor(sign, isFront); + int colorSecondary = BukkitAdapter.ADAPTER.getColor(sign, !isFront); + boolean frontGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, isFront); + boolean backGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, !isFront); + boolean isWaxed = BukkitAdapter.ADAPTER.isWaxed(sign); + + Queue.queueSignText(user, location, 0, color, colorSecondary, frontGlowing, backGlowing, isWaxed, isFront, line1, line2, line3, line4, line5, line6, line7, line8, 5); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/coreprotect/listener/block/BlockPlaceListener.java b/src/main/java/net/coreprotect/listener/block/BlockPlaceListener.java index f716237c..20ad6ee6 100644 --- a/src/main/java/net/coreprotect/listener/block/BlockPlaceListener.java +++ b/src/main/java/net/coreprotect/listener/block/BlockPlaceListener.java @@ -28,6 +28,7 @@ import net.coreprotect.consumer.Queue; import net.coreprotect.listener.player.InventoryChangeListener; import net.coreprotect.model.BlockGroup; +import net.coreprotect.paper.PaperAdapter; import net.coreprotect.utility.Util; public final class BlockPlaceListener extends Queue implements Listener { @@ -111,14 +112,24 @@ else if (BlockGroup.LIGHTABLES.contains(blockType) && blockType == blockReplaced try { Location location = blockState.getLocation(); Sign sign = (Sign) blockState; - String line1 = sign.getLine(0); - String line2 = sign.getLine(1); - String line3 = sign.getLine(2); - String line4 = sign.getLine(3); - int color = sign.getColor().getColor().asRGB(); - boolean isGlowing = BukkitAdapter.ADAPTER.isGlowing(sign); - if (line1.length() > 0 || line2.length() > 0 || line3.length() > 0 || line4.length() > 0) { - Queue.queueSignText(player.getName(), location, 1, color, isGlowing, line1, line2, line3, line4, 0); + String line1 = PaperAdapter.ADAPTER.getLine(sign, 0); + String line2 = PaperAdapter.ADAPTER.getLine(sign, 1); + String line3 = PaperAdapter.ADAPTER.getLine(sign, 2); + String line4 = PaperAdapter.ADAPTER.getLine(sign, 3); + String line5 = PaperAdapter.ADAPTER.getLine(sign, 4); + String line6 = PaperAdapter.ADAPTER.getLine(sign, 5); + String line7 = PaperAdapter.ADAPTER.getLine(sign, 6); + String line8 = PaperAdapter.ADAPTER.getLine(sign, 7); + + boolean isFront = true; + int color = BukkitAdapter.ADAPTER.getColor(sign, isFront); + int colorSecondary = BukkitAdapter.ADAPTER.getColor(sign, !isFront); + boolean frontGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, isFront); + boolean backGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, !isFront); + boolean isWaxed = BukkitAdapter.ADAPTER.isWaxed(sign); + + if (line1.length() > 0 || line2.length() > 0 || line3.length() > 0 || line4.length() > 0 || line5.length() > 0 || line6.length() > 0 || line7.length() > 0 || line8.length() > 0) { + Queue.queueSignText(player.getName(), location, 1, color, colorSecondary, frontGlowing, backGlowing, isWaxed, isFront, line1, line2, line3, line4, line5, line6, line7, line8, 0); } } catch (Exception e) { diff --git a/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java b/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java index 06560f7d..1613239f 100755 --- a/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java +++ b/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java @@ -8,7 +8,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.DyeColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -54,6 +53,7 @@ import net.coreprotect.database.lookup.SignMessageLookup; import net.coreprotect.language.Phrase; import net.coreprotect.model.BlockGroup; +import net.coreprotect.paper.PaperAdapter; import net.coreprotect.thread.CacheHandler; import net.coreprotect.thread.Scheduler; import net.coreprotect.utility.Chat; @@ -560,30 +560,47 @@ else if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction() handType = mainHand.getType(); } - if (handType != null && (dyeSet.contains(handType) || handType.name().endsWith("INK_SAC")) && Config.getConfig(block.getWorld()).SIGN_TEXT) { + if (handType != null && (dyeSet.contains(handType) || handType.name().endsWith("INK_SAC") || handType == Material.HONEYCOMB) && Config.getConfig(block.getWorld()).SIGN_TEXT) { BlockState blockState = block.getState(); Sign sign = (Sign) blockState; - String line1 = sign.getLine(0); - String line2 = sign.getLine(1); - String line3 = sign.getLine(2); - String line4 = sign.getLine(3); - int oldColor = sign.getColor().getColor().asRGB(); - int newColor = oldColor; - boolean oldGlowing = BukkitAdapter.ADAPTER.isGlowing(sign); - boolean newGlowing = oldGlowing; - - if (dyeSet.contains(handType)) { - newColor = (DyeColor.valueOf(handType.name().replaceFirst("_DYE", ""))).getColor().asRGB(); - } - else { - newGlowing = (handType != Material.INK_SAC); - } + String line1 = PaperAdapter.ADAPTER.getLine(sign, 0); + String line2 = PaperAdapter.ADAPTER.getLine(sign, 1); + String line3 = PaperAdapter.ADAPTER.getLine(sign, 2); + String line4 = PaperAdapter.ADAPTER.getLine(sign, 3); + String line5 = PaperAdapter.ADAPTER.getLine(sign, 4); + String line6 = PaperAdapter.ADAPTER.getLine(sign, 5); + String line7 = PaperAdapter.ADAPTER.getLine(sign, 6); + String line8 = PaperAdapter.ADAPTER.getLine(sign, 7); + + boolean isFront = true; + int oldColor = BukkitAdapter.ADAPTER.getColor(sign, isFront); + int oldColorSecondary = BukkitAdapter.ADAPTER.getColor(sign, !isFront); + boolean oldFrontGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, isFront); + boolean oldBackGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, !isFront); + boolean oldIsWaxed = BukkitAdapter.ADAPTER.isWaxed(sign); + + if (!oldIsWaxed) { + Scheduler.runTask(CoreProtect.getInstance(), () -> { + BlockState newState = block.getState(); + if (newState instanceof Sign) { + Sign newSign = (Sign) newState; + int newColor = BukkitAdapter.ADAPTER.getColor(newSign, isFront); + int newColorSecondary = BukkitAdapter.ADAPTER.getColor(newSign, !isFront); + boolean newFrontGlowing = BukkitAdapter.ADAPTER.isGlowing(newSign, isFront); + boolean newBackGlowing = BukkitAdapter.ADAPTER.isGlowing(newSign, !isFront); + boolean newIsWaxed = BukkitAdapter.ADAPTER.isWaxed(newSign); + + boolean modifyingFront = oldBackGlowing == newBackGlowing && oldColorSecondary == newColorSecondary; + if (oldColor != newColor || oldColorSecondary != newColorSecondary || oldFrontGlowing != newFrontGlowing || oldBackGlowing != newBackGlowing || oldIsWaxed != newIsWaxed) { + Location location = blockState.getLocation(); + Queue.queueSignText(player.getName(), location, 0, oldColor, oldColorSecondary, oldFrontGlowing, oldBackGlowing, oldIsWaxed, modifyingFront, line1, line2, line3, line4, line5, line6, line7, line8, 1); // 1 second timeOffset + Queue.queueBlockPlace(player.getName(), blockState, block.getType(), blockState, block.getType(), -1, 0, blockState.getBlockData().getAsString()); + Queue.queueSignText(player.getName(), location, 2, newColor, newColorSecondary, newFrontGlowing, newBackGlowing, newIsWaxed, modifyingFront, line1, line2, line3, line4, line5, line6, line7, line8, 0); + } + + } - if (oldGlowing != newGlowing || oldColor != newColor) { - Location location = blockState.getLocation(); - Queue.queueSignText(player.getName(), location, 0, oldColor, oldGlowing, line1, line2, line3, line4, 1); // 1 second timeOffset - Queue.queueBlockPlace(player.getName(), block.getState(), block.getType(), blockState, block.getType(), -1, 0, blockState.getBlockData().getAsString()); - Queue.queueSignText(player.getName(), location, 2, newColor, newGlowing, line1, line2, line3, line4, 0); + }, block.getLocation()); } } } diff --git a/src/main/java/net/coreprotect/listener/player/SignChangeListener.java b/src/main/java/net/coreprotect/listener/player/SignChangeListener.java index 44beaab9..cbbde9e1 100644 --- a/src/main/java/net/coreprotect/listener/player/SignChangeListener.java +++ b/src/main/java/net/coreprotect/listener/player/SignChangeListener.java @@ -12,24 +12,76 @@ import net.coreprotect.bukkit.BukkitAdapter; import net.coreprotect.config.Config; import net.coreprotect.consumer.Queue; +import net.coreprotect.paper.PaperAdapter; +import net.coreprotect.spigot.SpigotAdapter; public final class SignChangeListener extends Queue implements Listener { @EventHandler(priority = EventPriority.MONITOR) protected void onSignChange(SignChangeEvent event) { - String player = event.getPlayer().getName(); Block block = event.getBlock(); + if (event.isCancelled() || !Config.getConfig(block.getWorld()).SIGN_TEXT) { + return; + } + + String player = event.getPlayer().getName(); Location location = block.getLocation(); BlockState blockState = block.getState(); - String line1 = event.getLine(0); - String line2 = event.getLine(1); - String line3 = event.getLine(2); - String line4 = event.getLine(3); - int color = (blockState instanceof Sign) ? ((Sign) blockState).getColor().getColor().asRGB() : 0; - boolean isGlowing = (blockState instanceof Sign) ? BukkitAdapter.ADAPTER.isGlowing((Sign) blockState) : false; - - if (!event.isCancelled() && Config.getConfig(block.getWorld()).SIGN_TEXT) { - Queue.queueSignText(player, location, 1, color, isGlowing, line1, line2, line3, line4, 0); + + String line1 = ""; + String line2 = ""; + String line3 = ""; + String line4 = ""; + String line5 = ""; + String line6 = ""; + String line7 = ""; + String line8 = ""; + int color = 0; + int colorSecondary = 0; + boolean frontGlowing = false; + boolean backGlowing = false; + boolean isWaxed = false; + boolean isFront = SpigotAdapter.ADAPTER.isSignFront(event); + boolean existingText = false; + + if (blockState instanceof Sign) { + Sign sign = (Sign) blockState; + line1 = PaperAdapter.ADAPTER.getLine(sign, 0); + line2 = PaperAdapter.ADAPTER.getLine(sign, 1); + line3 = PaperAdapter.ADAPTER.getLine(sign, 2); + line4 = PaperAdapter.ADAPTER.getLine(sign, 3); + line5 = PaperAdapter.ADAPTER.getLine(sign, 4); + line6 = PaperAdapter.ADAPTER.getLine(sign, 5); + line7 = PaperAdapter.ADAPTER.getLine(sign, 6); + line8 = PaperAdapter.ADAPTER.getLine(sign, 7); + color = BukkitAdapter.ADAPTER.getColor(sign, true); + colorSecondary = BukkitAdapter.ADAPTER.getColor(sign, false); + frontGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, true); + backGlowing = BukkitAdapter.ADAPTER.isGlowing(sign, false); + isWaxed = BukkitAdapter.ADAPTER.isWaxed(sign); + + if (line1.length() > 0 || line2.length() > 0 || line3.length() > 0 || line4.length() > 0 || line5.length() > 0 || line6.length() > 0 || line7.length() > 0 || line8.length() > 0) { + existingText = true; + Queue.queueSignText(player, location, 0, color, colorSecondary, frontGlowing, backGlowing, isWaxed, isFront, line1, line2, line3, line4, line5, line6, line7, line8, 1); + Queue.queueBlockPlace(player, blockState, block.getType(), blockState, block.getType(), -1, 0, blockState.getBlockData().getAsString()); + } + } + + if (isFront) { + line1 = event.getLine(0); + line2 = event.getLine(1); + line3 = event.getLine(2); + line4 = event.getLine(3); + } + else { + line5 = event.getLine(0); + line6 = event.getLine(1); + line7 = event.getLine(2); + line8 = event.getLine(3); + } + + if (existingText || line1.length() > 0 || line2.length() > 0 || line3.length() > 0 || line4.length() > 0 || line5.length() > 0 || line6.length() > 0 || line7.length() > 0 || line8.length() > 0) { + Queue.queueSignText(player, location, 1, color, colorSecondary, frontGlowing, backGlowing, isWaxed, isFront, line1, line2, line3, line4, line5, line6, line7, line8, 0); } } } diff --git a/src/main/java/net/coreprotect/paper/PaperAdapter.java b/src/main/java/net/coreprotect/paper/PaperAdapter.java index 14354ae8..cfba5489 100644 --- a/src/main/java/net/coreprotect/paper/PaperAdapter.java +++ b/src/main/java/net/coreprotect/paper/PaperAdapter.java @@ -9,6 +9,7 @@ import net.coreprotect.bukkit.BukkitAdapter; import net.coreprotect.config.ConfigHandler; +import net.coreprotect.spigot.SpigotAdapter; public class PaperAdapter implements PaperInterface { @@ -21,6 +22,7 @@ public class PaperAdapter implements PaperInterface { public static final int PAPER_V1_17 = BukkitAdapter.BUKKIT_V1_17; public static final int PAPER_V1_18 = BukkitAdapter.BUKKIT_V1_18; public static final int PAPER_V1_19 = BukkitAdapter.BUKKIT_V1_19; + public static final int PAPER_V1_20 = BukkitAdapter.BUKKIT_V1_20; public static void loadAdapter() { int paperVersion = ConfigHandler.SERVER_VERSION; @@ -43,9 +45,12 @@ public static void loadAdapter() { case PAPER_V1_17: case PAPER_V1_18: case PAPER_V1_19: - default: PaperAdapter.ADAPTER = new Paper_v1_17(); break; + case PAPER_V1_20: + default: + PaperAdapter.ADAPTER = new Paper_v1_20(); + break; } } @@ -61,7 +66,7 @@ public boolean isStopping(Server server) { @Override public String getLine(Sign sign, int line) { - return sign.getLine(line); + return SpigotAdapter.ADAPTER.getLine(sign, line); } @Override diff --git a/src/main/java/net/coreprotect/paper/Paper_v1_20.java b/src/main/java/net/coreprotect/paper/Paper_v1_20.java new file mode 100644 index 00000000..c7e22dc0 --- /dev/null +++ b/src/main/java/net/coreprotect/paper/Paper_v1_20.java @@ -0,0 +1,21 @@ +package net.coreprotect.paper; + +import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; + +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public class Paper_v1_20 extends Paper_v1_17 implements PaperInterface { + + @Override + public String getLine(Sign sign, int line) { + // https://docs.adventure.kyori.net/serializer/ + if (line < 4) { + return LegacyComponentSerializer.legacySection().serialize(sign.getSide(Side.FRONT).line(line)); + } + else { + return LegacyComponentSerializer.legacySection().serialize(sign.getSide(Side.BACK).line(line - 4)); + } + } + +} diff --git a/src/main/java/net/coreprotect/patch/script/__2_22_0.java b/src/main/java/net/coreprotect/patch/script/__2_22_0.java new file mode 100644 index 00000000..d88b9e00 --- /dev/null +++ b/src/main/java/net/coreprotect/patch/script/__2_22_0.java @@ -0,0 +1,127 @@ +package net.coreprotect.patch.script; + +import java.sql.Statement; + +import net.coreprotect.config.Config; +import net.coreprotect.config.ConfigHandler; +import net.coreprotect.language.Phrase; +import net.coreprotect.language.Selector; +import net.coreprotect.patch.Patch; +import net.coreprotect.utility.Chat; + +public class __2_22_0 { + + protected static boolean patch(Statement statement) { + try { + if (Config.getGlobal().MYSQL) { + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN line_5 VARCHAR(100), ADD COLUMN line_6 VARCHAR(100), ADD COLUMN line_7 VARCHAR(100), ADD COLUMN line_8 VARCHAR(100), ADD COLUMN color_secondary INT, ADD COLUMN waxed TINYINT DEFAULT 0, ADD COLUMN face TINYINT DEFAULT 0;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + } + else { + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN line_5 TEXT;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + + if (!Patch.continuePatch()) { + return false; + } + + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN line_6 TEXT;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + + if (!Patch.continuePatch()) { + return false; + } + + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN line_7 TEXT;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + + if (!Patch.continuePatch()) { + return false; + } + + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN line_8 TEXT;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + + if (!Patch.continuePatch()) { + return false; + } + + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN color_secondary INTEGER;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + + if (!Patch.continuePatch()) { + return false; + } + + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN waxed TINYINT DEFAULT 0;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + + if (!Patch.continuePatch()) { + return false; + } + + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN face TINYINT DEFAULT 0;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST)); + } + } + + if (!Patch.continuePatch()) { + return false; + } + + if (Config.getGlobal().MYSQL) { + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "container ADD COLUMN slot TINYINT DEFAULT 0;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "container", Selector.FIRST, Selector.FIRST)); + } + } + else { + try { + statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "container ADD COLUMN slot INTEGER DEFAULT 0;"); + } + catch (Exception e) { + Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "container", Selector.FIRST, Selector.FIRST)); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + + return true; + } + +} diff --git a/src/main/java/net/coreprotect/spigot/SpigotAdapter.java b/src/main/java/net/coreprotect/spigot/SpigotAdapter.java index 49f4384b..8cfcfa92 100644 --- a/src/main/java/net/coreprotect/spigot/SpigotAdapter.java +++ b/src/main/java/net/coreprotect/spigot/SpigotAdapter.java @@ -2,7 +2,9 @@ import java.util.regex.Matcher; +import org.bukkit.block.Sign; import org.bukkit.command.CommandSender; +import org.bukkit.event.block.SignChangeEvent; import net.coreprotect.bukkit.BukkitAdapter; import net.coreprotect.config.ConfigHandler; @@ -20,6 +22,7 @@ public class SpigotAdapter implements SpigotInterface { public static final int SPIGOT_V1_17 = BukkitAdapter.BUKKIT_V1_17; public static final int SPIGOT_V1_18 = BukkitAdapter.BUKKIT_V1_18; public static final int SPIGOT_V1_19 = BukkitAdapter.BUKKIT_V1_19; + public static final int SPIGOT_V1_20 = BukkitAdapter.BUKKIT_V1_20; public static void loadAdapter() { int spigotVersion = ConfigHandler.SERVER_VERSION; @@ -40,9 +43,12 @@ public static void loadAdapter() { case SPIGOT_V1_17: case SPIGOT_V1_18: case SPIGOT_V1_19: - default: SpigotAdapter.ADAPTER = new Spigot_v1_16(); break; + case SPIGOT_V1_20: + default: + SpigotAdapter.ADAPTER = new Spigot_v1_20(); + break; } } @@ -81,4 +87,30 @@ public void sendComponent(CommandSender sender, String string, String bypass) { Chat.sendMessage(sender, message.toString()); } + @Override + public String getLine(Sign sign, int line) { + if (line < 4) { + return sign.getLine(line); + } + else { + return ""; + } + } + + @Override + public void setLine(Sign sign, int line, String string) { + if (string == null) { + string = ""; + } + + if (line < 4) { + sign.setLine(line, string); + } + } + + @Override + public boolean isSignFront(SignChangeEvent event) { + return true; + } + } diff --git a/src/main/java/net/coreprotect/spigot/SpigotInterface.java b/src/main/java/net/coreprotect/spigot/SpigotInterface.java index 89e0d88c..889cf68c 100644 --- a/src/main/java/net/coreprotect/spigot/SpigotInterface.java +++ b/src/main/java/net/coreprotect/spigot/SpigotInterface.java @@ -1,6 +1,8 @@ package net.coreprotect.spigot; +import org.bukkit.block.Sign; import org.bukkit.command.CommandSender; +import org.bukkit.event.block.SignChangeEvent; public interface SpigotInterface { @@ -10,4 +12,10 @@ public interface SpigotInterface { public void sendComponent(CommandSender sender, String string, String bypass); + public String getLine(Sign sign, int line); + + public void setLine(Sign sign, int line, String string); + + public boolean isSignFront(SignChangeEvent event); + } diff --git a/src/main/java/net/coreprotect/spigot/Spigot_v1_20.java b/src/main/java/net/coreprotect/spigot/Spigot_v1_20.java new file mode 100644 index 00000000..64ba3f68 --- /dev/null +++ b/src/main/java/net/coreprotect/spigot/Spigot_v1_20.java @@ -0,0 +1,38 @@ +package net.coreprotect.spigot; + +import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; +import org.bukkit.event.block.SignChangeEvent; + +public class Spigot_v1_20 extends Spigot_v1_16 implements SpigotInterface { + + @Override + public String getLine(Sign sign, int line) { + if (line < 4) { + return sign.getSide(Side.FRONT).getLine(line); + } + else { + return sign.getSide(Side.BACK).getLine(line - 4); + } + } + + @Override + public void setLine(Sign sign, int line, String string) { + if (string == null) { + string = ""; + } + + if (line < 4) { + sign.getSide(Side.FRONT).setLine(line, string); + } + else { + sign.getSide(Side.BACK).setLine(line - 4, string); + } + } + + @Override + public boolean isSignFront(SignChangeEvent event) { + return event.getSide().equals(Side.FRONT); + } + +} diff --git a/src/main/java/net/coreprotect/utility/Util.java b/src/main/java/net/coreprotect/utility/Util.java index 12f5fdf1..3897a6d8 100755 --- a/src/main/java/net/coreprotect/utility/Util.java +++ b/src/main/java/net/coreprotect/utility/Util.java @@ -1631,4 +1631,23 @@ public static int toggleRolledBack(int rolledBack, boolean isInventory) { return isInventory ? 2 : 1; } } + + public static int getSignData(boolean frontGlowing, boolean backGlowing) { + if (frontGlowing && backGlowing) { + return 3; + } + else if (backGlowing) { + return 2; + } + else if (frontGlowing) { + return 1; + } + + return 0; + } + + public static boolean isSideGlowing(boolean isFront, int data) { + return ((isFront && (data == 1 || data == 3)) || (!isFront && (data == 2 || data == 3))); + } + } diff --git a/src/main/java/net/coreprotect/worldedit/WorldEditLogger.java b/src/main/java/net/coreprotect/worldedit/WorldEditLogger.java index d99ab9c8..4241b4c6 100644 --- a/src/main/java/net/coreprotect/worldedit/WorldEditLogger.java +++ b/src/main/java/net/coreprotect/worldedit/WorldEditLogger.java @@ -69,14 +69,20 @@ protected static void postProcess(Extent extent, Actor actor, BlockVector3 posit if (baseBlock != null && baseBlock.hasNbtData()) { if (Config.getConfig(location.getWorld()).SIGN_TEXT && Tag.SIGNS.isTagged(oldType)) { CompoundTag compoundTag = baseBlock.getNbtData(); - String line1 = getSignText(compoundTag.getString("Text1")); - String line2 = getSignText(compoundTag.getString("Text2")); - String line3 = getSignText(compoundTag.getString("Text3")); - String line4 = getSignText(compoundTag.getString("Text4")); - int color = DyeColor.valueOf(baseBlock.getNbtData().getString("Color").toUpperCase()).getColor().asRGB(); - boolean isGlowing = (compoundTag.getInt("GlowingText") == 1 ? true : false); - - Queue.queueSignText(actor.getName(), location, 0, color, isGlowing, line1, line2, line3, line4, 5); + if (!compoundTag.containsKey("front_text")) { + String line1 = getSignText(compoundTag.getString("Text1")); + String line2 = getSignText(compoundTag.getString("Text2")); + String line3 = getSignText(compoundTag.getString("Text3")); + String line4 = getSignText(compoundTag.getString("Text4")); + int color = DyeColor.valueOf(baseBlock.getNbtData().getString("Color").toUpperCase()).getColor().asRGB(); + int colorSecondary = 0; + boolean frontGlowing = (compoundTag.getInt("GlowingText") == 1 ? true : false); + boolean backGlowing = false; + boolean isWaxed = false; + boolean isFront = true; + + Queue.queueSignText(actor.getName(), location, 0, color, colorSecondary, frontGlowing, backGlowing, isWaxed, isFront, line1, line2, line3, line4, "", "", "", "", 5); + } } if (oldType == Material.SPAWNER) { String mobType = getMobType(baseBlock);