Added logging for droppers adding items to other containers

This commit is contained in:
Intelli 2024-06-17 17:34:18 -06:00
parent 37fc9af300
commit aa2ee7225c
4 changed files with 18 additions and 7 deletions

View File

@ -18,7 +18,7 @@ import net.coreprotect.utility.Util;
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 @@ public final class HopperPullListener {
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();

View File

@ -18,7 +18,7 @@ import net.coreprotect.utility.Util;
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 @@ public final class HopperPushListener {
}
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();

View File

@ -344,10 +344,16 @@ public final class InventoryChangeListener extends Queue implements Listener {
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 @@ public final class InventoryChangeListener extends Queue implements Listener {
return;
}
HopperPullListener.processHopperPull(location, sourceHolder, destinationHolder, event.getItem());
HopperPullListener.processHopperPull(location, "#hopper", sourceHolder, destinationHolder, event.getItem());
}
}

View File

@ -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 class Validate {
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);