From 0309fcff5ecb7a5a226f0e1005b2d66bf3b33fcd Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Mon, 12 Aug 2019 21:28:23 -0500 Subject: [PATCH] fix cache material check --- .../hopper/levels/modules/ModuleAutoCrafting.java | 4 ++-- .../hopper/levels/modules/ModuleSuction.java | 4 ++-- .../epichoppers/listeners/HopperListeners.java | 10 +++++----- .../java/com/songoda/epichoppers/tasks/HopTask.java | 12 ++++++------ .../java/com/songoda/epichoppers/utils/Methods.java | 10 +++++----- .../epichoppers/utils/StorageContainerCache.java | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java index 0e06663..3cd2220 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java @@ -71,7 +71,7 @@ public class ModuleAutoCrafting extends Module { for(ItemStack item : recipe.recipe) { int amountHave = 0; for (ItemStack hopperItem : hopperCache.cachedInventory) { - if (hopperItem != null && Methods.isSimilar(hopperItem, item)) + if (hopperItem != null && Methods.isSimilarMaterial(hopperItem, item)) amountHave += hopperItem.getAmount(); } if (amountHave < item.getAmount()) { @@ -149,7 +149,7 @@ public class ModuleAutoCrafting extends Module { try { Recipe recipe = recipeIterator.next(); ItemStack stack = recipe.getResult(); - if (Methods.isSimilar(stack, toCraft)) + if (Methods.isSimilarMaterial(stack, toCraft)) recipes.addRecipe(recipe); } catch (Throwable ignored) {} } diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java index 8f1a3e8..dc78426 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java @@ -83,13 +83,13 @@ public class ModuleSuction extends Module { // whitelist has priority if (!hopper.getFilter().getWhiteList().isEmpty()) { // is this item on the whitelist? - if (!hopper.getFilter().getWhiteList().stream().anyMatch(filterItem -> Methods.isSimilar(itemStack, filterItem))) { + if (!hopper.getFilter().getWhiteList().stream().anyMatch(filterItem -> Methods.isSimilarMaterial(itemStack, filterItem))) { // nope! continue; } } else { // check the blacklist - if (hopper.getFilter().getBlackList().stream().anyMatch(filterItem -> Methods.isSimilar(itemStack, filterItem))) { + if (hopper.getFilter().getBlackList().stream().anyMatch(filterItem -> Methods.isSimilarMaterial(itemStack, filterItem))) { // don't grab this, then continue; } diff --git a/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java b/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java index 92df83c..e12ee6b 100644 --- a/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java +++ b/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java @@ -72,7 +72,7 @@ public class HopperListeners implements Listener { // if we're not moving the item that we're trying to craft, we need to verify that we're not trying to fill the last slot // (filling every slot leaves no room for the crafter to function) if (toCraft != null && toCraft.getType() != Material.AIR - && !Methods.isSimilar(toMove, toCraft) + && !Methods.isSimilarMaterial(toMove, toCraft) && !Methods.canMoveReserved(destination, toMove)) { event.setCancelled(true); return; @@ -88,14 +88,14 @@ public class HopperListeners implements Listener { // whitelist has priority if (!toHopper.getFilter().getWhiteList().isEmpty()) { // is this item on the whitelist? - allowItem = toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilar(toMove, item)); + allowItem = toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item)); if(!allowItem) { // can we change the item to something else? searchReplacement: for(ItemStack sourceItem : source.getContents()) { if(sourceItem != null && Methods.canMove(destination, sourceItem)) { for(ItemStack item : toHopper.getFilter().getWhiteList()) { - if(Methods.isSimilar(sourceItem, item)) { + if(Methods.isSimilarMaterial(sourceItem, item)) { moveInstead = new ItemStack(sourceItem); moveInstead.setAmount(1); break searchReplacement; @@ -106,13 +106,13 @@ public class HopperListeners implements Listener { } } else { // check the blacklist - allowItem = !toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilar(toMove, item)); + allowItem = !toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item)); if (!allowItem) { // can we change the item to something else? searchReplacement: for (ItemStack sourceItem : source.getContents()) { if (sourceItem != null && Methods.canMove(destination, sourceItem)) { - boolean blacklisted = toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilar(sourceItem, item)); + boolean blacklisted = toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(sourceItem, item)); if (!blacklisted) { moveInstead = new ItemStack(sourceItem); moveInstead.setAmount(1); diff --git a/src/main/java/com/songoda/epichoppers/tasks/HopTask.java b/src/main/java/com/songoda/epichoppers/tasks/HopTask.java index e35774f..7fda657 100644 --- a/src/main/java/com/songoda/epichoppers/tasks/HopTask.java +++ b/src/main/java/com/songoda/epichoppers/tasks/HopTask.java @@ -132,7 +132,7 @@ public class HopTask extends BukkitRunnable { || (hopperCache.cacheChanged[i] && item.getAmount() - hopperCache.cacheAdded[i] < maxToMove) // skip if blocked or voidlisted || blockedMaterials.contains(item.getType()) - || hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilar(itemStack, item))) + || hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilarMaterial(itemStack, item))) continue; doProcess = true; @@ -262,7 +262,7 @@ public class HopTask extends BukkitRunnable { // if we're not moving the item that we're trying to craft, we need to verify that we're not trying to fill the last slot // (filling every slot leaves no room for the crafter to function) - if (toCraft != null && !Methods.isSimilar(toMove, toCraft) && !Methods.canMoveReserved(hopperCache.cachedInventory, toMove)) + if (toCraft != null && !Methods.isSimilarMaterial(toMove, toCraft) && !Methods.canMoveReserved(hopperCache.cachedInventory, toMove)) continue; // respect whitelist/blacklist filters @@ -272,13 +272,13 @@ public class HopTask extends BukkitRunnable { // whitelist has priority if (!toHopper.getFilter().getWhiteList().isEmpty()) { // is this item on the whitelist? - if (!toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilar(toMove, item))) { + if (!toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item))) { // nope! continue; } } else { // check the blacklist - if (toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilar(toMove, item))) { + if (toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item))) { // don't grab this, then continue; } @@ -407,7 +407,7 @@ public class HopTask extends BukkitRunnable { || (hopperCache.cacheChanged[i] && item.getAmount() - hopperCache.cacheAdded[i] < maxToMove) // skip if blocked or voidlisted || blockedMaterials.contains(item.getType()) - || hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilar(itemStack, item))) + || hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilarMaterial(itemStack, item))) continue; // Create item that will be moved. @@ -443,7 +443,7 @@ public class HopTask extends BukkitRunnable { ItemStack[] hopperContents = hopperCache.cachedInventory; for (int i = 0; i < hopperContents.length; i++) { final ItemStack item = hopperContents[i]; - if (item != null && hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilar(itemStack, item))) { + if (item != null && hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilarMaterial(itemStack, item))) { int amt = Math.min(0, item.getAmount() - maxToMove); if (amt == 0) { hopperCache.removeItem(i); diff --git a/src/main/java/com/songoda/epichoppers/utils/Methods.java b/src/main/java/com/songoda/epichoppers/utils/Methods.java index 1999e7a..a1df111 100644 --- a/src/main/java/com/songoda/epichoppers/utils/Methods.java +++ b/src/main/java/com/songoda/epichoppers/utils/Methods.java @@ -145,7 +145,7 @@ public class Methods { return glass; } - public static boolean isSimilar(ItemStack is1, ItemStack is2) { + public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) { if (EpicHoppers.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)) { return is1.getType() == is2.getType(); } else { @@ -159,7 +159,7 @@ public class Methods { final ItemMeta itemMeta = item.getItemMeta(); for (ItemStack stack : inventory) { final ItemMeta stackMeta; - if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { return true; @@ -175,7 +175,7 @@ public class Methods { if (stack == null || stack.getAmount() == 0) return true; final ItemMeta stackMeta; - if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { return true; @@ -192,7 +192,7 @@ public class Methods { for (int i = 0; i < 4; i++) { final ItemStack stack = contents[i]; final ItemMeta stackMeta; - if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { return true; @@ -208,7 +208,7 @@ public class Methods { if (stack == null || stack.getAmount() == 0) return true; final ItemMeta stackMeta; - if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { return true; diff --git a/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java b/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java index a85103e..ed82629 100644 --- a/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java +++ b/src/main/java/com/songoda/epichoppers/utils/StorageContainerCache.java @@ -111,7 +111,7 @@ public class StorageContainerCache { int toRemove = item.getAmount(); for (int i = 0; toRemove > 0 && i < cachedInventory.length; i++) { final ItemStack cacheItem = cachedInventory[i]; - if (cacheItem != null && cacheItem.getAmount() != 0 && Methods.isSimilar(item, cacheItem)) { + if (cacheItem != null && cacheItem.getAmount() != 0 && item.isSimilar(cacheItem)) { int have = cacheItem.getAmount(); if (have > toRemove) { cachedInventory[i].setAmount(have - toRemove); @@ -155,7 +155,7 @@ public class StorageContainerCache { cacheAdded[i] = toAdd; totalAdded += toAdd; amountToAdd -= toAdd; - } else if (maxStack > cacheItem.getAmount() && Methods.isSimilar(item, cacheItem)) { + } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { // free space! int toAdd = Math.min(maxStack - cacheItem.getAmount(), amountToAdd); cachedInventory[i].setAmount(toAdd + cacheItem.getAmount());