summaryrefslogtreecommitdiff
path: root/src/main/java/dev/deeve
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/dev/deeve')
-rw-r--r--src/main/java/dev/deeve/containeraudit/ChestListener.java81
1 files changed, 50 insertions, 31 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());
}