From ad28a427d3ce68e69a46f406d6b90b719b803549 Mon Sep 17 00:00:00 2001 From: Flarp Date: Sat, 30 Dec 2023 12:20:02 -0500 Subject: Added ability to keep track of barrels and shulker boxes, as well as correctly track Shift-Click events from player inventory --- .../dev/deeve/containeraudit/ChestListener.java | 81 +++++++++++++--------- 1 file changed, 50 insertions(+), 31 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/dev/deeve/containeraudit/ChestListener.java b/src/main/java/dev/deeve/containeraudit/ChestListener.java index bc93b9c..0ed9000 100644 --- a/src/main/java/dev/deeve/containeraudit/ChestListener.java +++ b/src/main/java/dev/deeve/containeraudit/ChestListener.java @@ -26,47 +26,66 @@ public class ChestListener implements Listener { ChestListener.ignore = ignore; } + public static boolean isContainer(InventoryType type) { + return + type == InventoryType.CHEST || + type == InventoryType.BARREL || + type == InventoryType.SHULKER_BOX; + } + + public static boolean isContainer(Material material) { + return + material == Material.CHEST || + material == Material.BARREL || + material.getKey().toString().endsWith("shulker_box"); + }; + @EventHandler public final void onInventoryClick(InventoryClickEvent event) { String playerName = event.getWhoClicked().getName(); Inventory inventory = event.getClickedInventory(); + Inventory otherInventory; - if (inventory == null || ignore.contains(playerName)) return; + Location loc; - - - Location loc = inventory.getLocation(); + if (inventory == null || ignore.contains(playerName)) return; InventoryAction action = event.getAction(); - if (inventory.getType() == InventoryType.CHEST && (action == InventoryAction.COLLECT_TO_CURSOR || - action == InventoryAction.PICKUP_ALL || - action == InventoryAction.PICKUP_HALF || - action == InventoryAction.PICKUP_ONE || - action == InventoryAction.PICKUP_SOME || - action == InventoryAction.MOVE_TO_OTHER_INVENTORY)) { + if (ChestListener.isContainer(inventory.getType())) { + loc = inventory.getLocation(); - // we are taking from the chest - Database.logInventoryEvent(playerName, true, loc, event.getCurrentItem()); - - } else if (inventory.getType() == InventoryType.CHEST && (action == InventoryAction.PLACE_ALL || - action == InventoryAction.PLACE_ONE || - action == InventoryAction.PLACE_SOME || - action == InventoryAction.HOTBAR_MOVE_AND_READD || - action == InventoryAction.HOTBAR_SWAP)) { - - // we are placing into the chest - Database.logInventoryEvent(playerName, false, loc, event.getCursor()); - - } else if (inventory.getType() == InventoryType.CHEST && (action == InventoryAction.SWAP_WITH_CURSOR)) { - - // we are swapping what is in our cursor with what is in the given slot, reverse - Database.logInventoryEvent(playerName, true, loc, event.getCursor()); - Database.logInventoryEvent(playerName, false, loc, event.getCurrentItem()); + if (action == InventoryAction.COLLECT_TO_CURSOR || + action == InventoryAction.PICKUP_ALL || + action == InventoryAction.PICKUP_HALF || + action == InventoryAction.PICKUP_ONE || + action == InventoryAction.PICKUP_SOME || + action == InventoryAction.MOVE_TO_OTHER_INVENTORY) { + + // we are taking from the chest + Database.logInventoryEvent(playerName, true, loc, event.getCurrentItem()); + } else if (action == InventoryAction.PLACE_ALL || + action == InventoryAction.PLACE_ONE || + action == InventoryAction.PLACE_SOME || + action == InventoryAction.HOTBAR_MOVE_AND_READD || + action == InventoryAction.HOTBAR_SWAP) { + + // we are placing into the chest + Database.logInventoryEvent(playerName, false, loc, event.getCursor()); + } else if (action == InventoryAction.SWAP_WITH_CURSOR) { + + // we are swapping what is in our cursor with what is in the given slot, reverse + Database.logInventoryEvent(playerName, true, loc, event.getCursor()); + Database.logInventoryEvent(playerName, false, loc, event.getCurrentItem()); + } + } else if (inventory.getType() == InventoryType.PLAYER && + (otherInventory = event.getView().getTopInventory()) != null && + ChestListener.isContainer(otherInventory.getType()) && + action == InventoryAction.MOVE_TO_OTHER_INVENTORY) { + loc = otherInventory.getLocation(); + Database.logInventoryEvent(playerName, false, loc, event.getCurrentItem()); } - - } @EventHandler @@ -76,7 +95,7 @@ public class ChestListener implements Listener { if (ignore.contains(playerName)) return; - if (placedBlock.getType() == Material.CHEST) + if (ChestListener.isContainer(placedBlock.getType())) Database.logBlockEvent(playerName, "PLACE", placedBlock.getLocation()); } @@ -88,7 +107,7 @@ public class ChestListener implements Listener { if (ignore.contains(playerName)) return; - if (placedBlock.getType() == Material.CHEST) + if (ChestListener.isContainer(placedBlock.getType())) Database.logBlockEvent(playerName, "BREAK", placedBlock.getLocation()); } -- cgit v1.2.3