From 544cf08309144b0be00c428a7d5910c0052cabfd Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 13 Jul 2019 15:49:40 -0400 Subject: [PATCH] quick fix. --- .../listeners/ItemListeners.java | 24 ++----------------- .../ultimatestacker/utils/Methods.java | 22 +++++++++++++++++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java index 26b0e95..7dd9ed1 100644 --- a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java @@ -58,7 +58,7 @@ public class ItemListeners implements Listener { if (amount <= 32) return; event.setCancelled(true); - updateInventory(event.getItem(), event.getInventory()); + Methods.updateInventory(event.getItem(), event.getInventory()); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -77,27 +77,7 @@ public class ItemListeners implements Listener { instance.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_ITEM_PICKUP : Sound.valueOf("ITEM_PICKUP"), .2f, (float) (1 + Math.random())); - updateInventory(event.getItem(), event.getPlayer().getInventory()); + Methods.updateInventory(event.getItem(), event.getPlayer().getInventory()); } - private void updateInventory(Item item, Inventory inventory) { - int amount = Methods.getActualItemAmount(item); - - while (amount > 0) { - int subtract = Math.min(amount, 64); - amount -= subtract; - ItemStack newItem = item.getItemStack().clone(); - newItem.setAmount(subtract); - Map result = inventory.addItem(newItem); - if (result.get(0) != null) { - amount += result.get(0).getAmount(); - break; - } - } - - if (amount <= 0) - item.remove(); - else - Methods.updateItemAmount(item, amount); - } } diff --git a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java index 7cac7c9..de89df6 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java @@ -9,6 +9,7 @@ import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.CreatureSpawner; import org.bukkit.entity.*; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.ItemMeta; @@ -24,6 +25,27 @@ import java.util.stream.Collectors; public class Methods { + public static void updateInventory(Item item, Inventory inventory) { + int amount = Methods.getActualItemAmount(item); + + while (amount > 0) { + int subtract = Math.min(amount, 64); + amount -= subtract; + ItemStack newItem = item.getItemStack().clone(); + newItem.setAmount(subtract); + Map result = inventory.addItem(newItem); + if (result.get(0) != null) { + amount += result.get(0).getAmount(); + break; + } + } + + if (amount <= 0) + item.remove(); + else + Methods.updateItemAmount(item, amount); + } + public static void updateItemAmount(Item item, int newAmount) { UltimateStacker plugin = UltimateStacker.getInstance(); Material material = item.getItemStack().getType();