From aa2ee7225cc7d3a21ccd7396e39d5796fca998dd Mon Sep 17 00:00:00 2001 From: Intelli Date: Mon, 17 Jun 2024 17:34:18 -0600 Subject: [PATCH] Added logging for droppers adding items to other containers --- .../listener/player/HopperPullListener.java | 4 ++-- .../listener/player/HopperPushListener.java | 4 ++-- .../listener/player/InventoryChangeListener.java | 12 +++++++++--- src/main/java/net/coreprotect/utility/Validate.java | 5 +++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/coreprotect/listener/player/HopperPullListener.java b/src/main/java/net/coreprotect/listener/player/HopperPullListener.java index e85fe4ed..5b47f929 100644 --- a/src/main/java/net/coreprotect/listener/player/HopperPullListener.java +++ b/src/main/java/net/coreprotect/listener/player/HopperPullListener.java @@ -18,7 +18,7 @@ public final class HopperPullListener { - static void processHopperPull(Location location, InventoryHolder sourceHolder, InventoryHolder destinationHolder, ItemStack item) { + static void processHopperPull(Location location, String user, InventoryHolder sourceHolder, InventoryHolder destinationHolder, ItemStack item) { String loggingChestId = "#hopper-pull." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ(); Object[] lastAbort = ConfigHandler.hopperAbort.get(loggingChestId); if (lastAbort != null) { @@ -91,7 +91,7 @@ static void processHopperPull(Location location, InventoryHolder sourceHolder, I originalSource[inventoryContents.length] = movedItem; InventoryChangeListener.checkTasks(taskStarted); - InventoryChangeListener.onInventoryInteract("#hopper", sourceInventory, originalSource, null, sourceInventory.getLocation(), true); + InventoryChangeListener.onInventoryInteract(user, sourceInventory, originalSource, null, sourceInventory.getLocation(), true); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/coreprotect/listener/player/HopperPushListener.java b/src/main/java/net/coreprotect/listener/player/HopperPushListener.java index 8655435f..cb8d733e 100644 --- a/src/main/java/net/coreprotect/listener/player/HopperPushListener.java +++ b/src/main/java/net/coreprotect/listener/player/HopperPushListener.java @@ -18,7 +18,7 @@ public final class HopperPushListener { - static void processHopperPush(Location location, InventoryHolder sourceHolder, InventoryHolder destinationHolder, ItemStack item) { + static void processHopperPush(Location location, String user, InventoryHolder sourceHolder, InventoryHolder destinationHolder, ItemStack item) { Location destinationLocation = destinationHolder.getInventory().getLocation(); if (destinationLocation == null) { return; @@ -97,7 +97,7 @@ static void processHopperPush(Location location, InventoryHolder sourceHolder, I } InventoryChangeListener.checkTasks(taskStarted); - InventoryChangeListener.onInventoryInteract("#hopper", destinationInventory, originalDestination, null, destinationInventory.getLocation(), true); + InventoryChangeListener.onInventoryInteract(user, destinationInventory, originalDestination, null, destinationInventory.getLocation(), true); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/coreprotect/listener/player/InventoryChangeListener.java b/src/main/java/net/coreprotect/listener/player/InventoryChangeListener.java index 4aa4a0f1..9beeb565 100644 --- a/src/main/java/net/coreprotect/listener/player/InventoryChangeListener.java +++ b/src/main/java/net/coreprotect/listener/player/InventoryChangeListener.java @@ -344,10 +344,16 @@ protected void onInventoryMoveItemEvent(InventoryMoveItemEvent event) { if (hopperTransactions) { if (Validate.isHopper(destinationHolder) && (Validate.isContainer(sourceHolder) && !Validate.isHopper(sourceHolder))) { - HopperPullListener.processHopperPull(location, sourceHolder, destinationHolder, event.getItem()); + HopperPullListener.processHopperPull(location, "#hopper", sourceHolder, destinationHolder, event.getItem()); } else if (Validate.isHopper(sourceHolder) && (Validate.isContainer(destinationHolder) && !Validate.isHopper(destinationHolder))) { - HopperPushListener.processHopperPush(location, sourceHolder, destinationHolder, event.getItem()); + HopperPushListener.processHopperPush(location, "#hopper", sourceHolder, destinationHolder, event.getItem()); + } + else if (Validate.isDropper(sourceHolder) && (Validate.isContainer(destinationHolder))) { + HopperPullListener.processHopperPull(location, "#dropper", sourceHolder, destinationHolder, event.getItem()); + if (!Validate.isHopper(destinationHolder)) { + HopperPushListener.processHopperPush(location, "#dropper", sourceHolder, destinationHolder, event.getItem()); + } } return; @@ -362,6 +368,6 @@ else if (Validate.isHopper(sourceHolder) && (Validate.isContainer(destinationHol return; } - HopperPullListener.processHopperPull(location, sourceHolder, destinationHolder, event.getItem()); + HopperPullListener.processHopperPull(location, "#hopper", sourceHolder, destinationHolder, event.getItem()); } } diff --git a/src/main/java/net/coreprotect/utility/Validate.java b/src/main/java/net/coreprotect/utility/Validate.java index 414db388..5f154396 100644 --- a/src/main/java/net/coreprotect/utility/Validate.java +++ b/src/main/java/net/coreprotect/utility/Validate.java @@ -1,6 +1,7 @@ package net.coreprotect.utility; import org.bukkit.block.DoubleChest; +import org.bukkit.block.Dropper; import org.bukkit.block.Hopper; import org.bukkit.entity.minecart.HopperMinecart; import org.bukkit.inventory.BlockInventoryHolder; @@ -16,6 +17,10 @@ public static boolean isHopper(InventoryHolder inventoryHolder) { return (inventoryHolder instanceof Hopper || inventoryHolder instanceof HopperMinecart); } + public static boolean isDropper(InventoryHolder inventoryHolder) { + return (inventoryHolder instanceof Dropper); + } + /* check if valid hopper destination */ public static boolean isContainer(InventoryHolder inventoryHolder) { return (inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest);