diff options
author | Flarp <flurpdadurp@gmail.com> | 2023-12-30 12:20:02 -0500 |
---|---|---|
committer | Flarp <flurpdadurp@gmail.com> | 2023-12-30 12:20:02 -0500 |
commit | ad28a427d3ce68e69a46f406d6b90b719b803549 (patch) | |
tree | 9e5952f3f3495a70c062dcc2b9bcad283d0c3f79 /src | |
parent | ecfecaf19410e91437764cf42e9a61276ae6a09b (diff) | |
download | container-audit-ad28a427d3ce68e69a46f406d6b90b719b803549.tar.gz |
Added ability to keep track of barrels and shulker boxes, as well as correctly track Shift-Click events from player inventory
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/dev/deeve/containeraudit/ChestListener.java | 81 | ||||
-rw-r--r-- | src/main/resources/plugin.yml | 2 |
2 files changed, 51 insertions, 32 deletions
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()); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7f6135b..e0a43fa 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,4 @@ main: dev.deeve.containeraudit.Plugin name: ContainerAudit -version: 0.0.1 +version: 0.0.2 api-version: 1.19
\ No newline at end of file |