mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-28 12:55:34 +01:00
Improved hopper logging to prevent infinite attempts on failed pushes
E.g. when a hopper is repeatedly trying to push into a smoker, but no items are actually being transferred
This commit is contained in:
parent
6023c21ba9
commit
5426e69fb8
@ -101,6 +101,7 @@ public class ConfigHandler extends Queue {
|
||||
public static ConcurrentHashMap<String, List<ItemStack>> itemsSell = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, List<ItemStack>> itemsBuy = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, Object[]> hopperAbort = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, Object[]> hopperSuccess = new ConcurrentHashMap<>();
|
||||
public static Map<String, List<ItemStack[]>> forceContainer = syncMap();
|
||||
public static Map<String, Integer> lookupType = syncMap();
|
||||
public static Map<String, Object[]> lookupThrottle = syncMap();
|
||||
|
@ -1,12 +1,16 @@
|
||||
package net.coreprotect.consumer.process;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
@ -41,6 +45,41 @@ class ContainerTransactionProcess {
|
||||
ConfigHandler.transactingChest.remove(transactingChestId);
|
||||
}
|
||||
}
|
||||
else if (loggingChestId.startsWith("#hopper")) {
|
||||
if (force_size == 0 && ConfigHandler.oldContainer.get(loggingChestId).size() == 1 && ConfigHandler.transactingChest.get(transactingChestId).isEmpty()) {
|
||||
int loopCount = ConfigHandler.loggingChest.get(loggingChestId);
|
||||
int maxInventorySize = (99 * 54);
|
||||
try {
|
||||
Inventory checkInventory = (Inventory) inventory;
|
||||
maxInventorySize = checkInventory.getSize() * checkInventory.getMaxStackSize();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// use default of 5,346
|
||||
}
|
||||
|
||||
if (loopCount > maxInventorySize) {
|
||||
ItemStack[] destinationContents = null;
|
||||
ItemStack movedItem = null;
|
||||
|
||||
String hopperPush = "#hopper-push." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
Object[] hopperPushData = ConfigHandler.hopperSuccess.remove(hopperPush);
|
||||
if (hopperPushData != null) {
|
||||
destinationContents = (ItemStack[]) hopperPushData[0];
|
||||
movedItem = (ItemStack) hopperPushData[1];
|
||||
}
|
||||
|
||||
if (destinationContents != null) {
|
||||
Set<ItemStack> movedItems = new HashSet<>();
|
||||
Object[] lastAbort = ConfigHandler.hopperAbort.get(hopperPush);
|
||||
if (lastAbort != null && Arrays.equals(destinationContents, (ItemStack[]) lastAbort[1])) {
|
||||
((Set<?>) lastAbort[0]).forEach(itemStack -> movedItems.add((ItemStack) itemStack));
|
||||
}
|
||||
movedItems.add(movedItem);
|
||||
ConfigHandler.hopperAbort.put(hopperPush, new Object[] { movedItems, destinationContents });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
inventories.remove(id);
|
||||
}
|
||||
|
@ -161,6 +161,7 @@ public class ContainerLogger extends Queue {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
boolean success = false;
|
||||
int slot = 0;
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
@ -190,10 +191,17 @@ public class ContainerLogger extends Queue {
|
||||
int data = 0;
|
||||
int amount = item.getAmount();
|
||||
ContainerStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, typeId, data, amount, metadata, action, 0);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
slot++;
|
||||
}
|
||||
|
||||
if (success && user.equals("#hopper")) {
|
||||
String hopperPush = "#hopper-push." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
ConfigHandler.hopperSuccess.remove(hopperPush);
|
||||
ConfigHandler.hopperAbort.remove(hopperPush);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -19,7 +19,8 @@ import net.coreprotect.utility.Util;
|
||||
public final class HopperPushListener {
|
||||
|
||||
static void processHopperPush(Location location, InventoryHolder sourceHolder, InventoryHolder destinationHolder, ItemStack item) {
|
||||
String loggingChestId = "#hopper-push." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
Location destinationLocation = destinationHolder.getInventory().getLocation();
|
||||
String loggingChestId = "#hopper-push." + destinationLocation.getBlockX() + "." + destinationLocation.getBlockY() + "." + destinationLocation.getBlockZ();
|
||||
Object[] lastAbort = ConfigHandler.hopperAbort.get(loggingChestId);
|
||||
if (lastAbort != null) {
|
||||
ItemStack[] destinationContents = destinationHolder.getInventory().getContents();
|
||||
@ -55,6 +56,9 @@ public final class HopperPushListener {
|
||||
ConfigHandler.hopperAbort.put(loggingChestId, new Object[] { movedItems, Util.getContainerState(destinationContents) });
|
||||
return;
|
||||
}
|
||||
else {
|
||||
ConfigHandler.hopperSuccess.put(loggingChestId, new Object[] { destinationContainer, movedItem });
|
||||
}
|
||||
|
||||
List<Object> list = ConfigHandler.transactingChest.get(location.getWorld().getUID().toString() + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ());
|
||||
if (list != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user