Skip to content

Commit

Permalink
Added logging for droppers adding items to other containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Jun 17, 2024
1 parent 37fc9af commit aa2ee72
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/coreprotect/utility/Validate.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit aa2ee72

Please sign in to comment.