From 4445c3c4a71d0b4d976c9c0f8d2c20c457fb01b0 Mon Sep 17 00:00:00 2001 From: Intelli Date: Tue, 22 Feb 2022 21:15:45 -0700 Subject: [PATCH] Fixed inventory rollbacks not always returning correct item for placed blocks --- .../java/net/coreprotect/command/LookupCommand.java | 3 ++- src/main/java/net/coreprotect/database/Rollback.java | 3 ++- src/main/java/net/coreprotect/utility/Util.java | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/coreprotect/command/LookupCommand.java b/src/main/java/net/coreprotect/command/LookupCommand.java index 638ed36..7d81d50 100755 --- a/src/main/java/net/coreprotect/command/LookupCommand.java +++ b/src/main/java/net/coreprotect/command/LookupCommand.java @@ -873,7 +873,8 @@ public class LookupCommand { int amount = Integer.parseInt(data[10]); String rbd = ((Integer.parseInt(data[8]) == 2 || Integer.parseInt(data[8]) == 3) ? Color.STRIKETHROUGH : ""); String timeago = Util.getTimeSince(Integer.parseInt(time), unixtimestamp, true); - String dname = Util.nameFilter(Util.getType(Integer.parseInt(dtype)).name().toLowerCase(Locale.ROOT), ddata); + Material blockType = Util.itemFilter(Util.getType(Integer.parseInt(dtype))); + String dname = Util.nameFilter(blockType.name().toLowerCase(Locale.ROOT), ddata); String selector = Selector.FIRST; String tag = Color.WHITE + "-"; diff --git a/src/main/java/net/coreprotect/database/Rollback.java b/src/main/java/net/coreprotect/database/Rollback.java index 6587718..1b8dd4b 100644 --- a/src/main/java/net/coreprotect/database/Rollback.java +++ b/src/main/java/net/coreprotect/database/Rollback.java @@ -1037,6 +1037,7 @@ public class Rollback extends Queue { int rolledBackInventory = Util.rolledBack((Integer) row[9], true); if (rowType != null) { if (inventoryRollback && ((rollbackType == 0 && rolledBackInventory == 0) || (rollbackType == 1 && rolledBackInventory == 1))) { + Material inventoryItem = Util.itemFilter(rowType); int rowUserId = (Integer) row[2]; String rowUser = ConfigHandler.playerIdCacheReversed.get(rowUserId); if (rowUser == null) { @@ -1065,7 +1066,7 @@ public class Rollback extends Queue { } int action = rollbackType == 0 ? (inventoryAction ^ 1) : inventoryAction; - ItemStack itemstack = new ItemStack(rowType, rowAmount, (short) rowData); + ItemStack itemstack = new ItemStack(inventoryItem, rowAmount, (short) rowData); Object[] populatedStack = populateItemStack(itemstack, rowMetadata); if (rowAction == ItemLogger.ITEM_REMOVE_ENDER || rowAction == ItemLogger.ITEM_ADD_ENDER) { modifyContainerItems(containerType, player.getEnderChest(), (Integer) populatedStack[0], ((ItemStack) populatedStack[2]).clone(), action ^ 1); diff --git a/src/main/java/net/coreprotect/utility/Util.java b/src/main/java/net/coreprotect/utility/Util.java index 2457219..a11d9f5 100755 --- a/src/main/java/net/coreprotect/utility/Util.java +++ b/src/main/java/net/coreprotect/utility/Util.java @@ -1105,6 +1105,18 @@ public class Util extends Queue { Chat.sendComponent(consoleSender, Color.RESET + "[CoreProtect] " + string + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP + "| | " + Chat.COMPONENT_TAG_CLOSE); } + public static Material itemFilter(Material material) { + if (material == null) { + return material; + } + + if (!material.isItem() && material.name().contains("WALL_")) { + material = Material.valueOf(material.name().replace("WALL_", "")); + } + + return material; + } + public static String nameFilter(String name, int data) { if (name.equals("stone")) { switch (data) {