From 37477d4263103e5825ec5775fe72592e7c3fbda1 Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Wed, 21 Nov 2018 17:08:34 -0500 Subject: [PATCH] fix for picking up --- .../events/InteractListeners.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/songoda/ultimatestacker/events/InteractListeners.java b/src/main/java/com/songoda/ultimatestacker/events/InteractListeners.java index 9e62c4e..338af82 100644 --- a/src/main/java/com/songoda/ultimatestacker/events/InteractListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/events/InteractListeners.java @@ -25,7 +25,6 @@ public class InteractListeners implements Listener { @EventHandler public void onAccept(InventoryPickupItemEvent event) { - Bukkit.broadcastMessage("pickup"); ItemStack item = event.getItem().getItemStack(); instance.getStackingTask().setMax(item, 0, true); int amt = item.getAmount(); @@ -54,8 +53,34 @@ public class InteractListeners implements Listener { @EventHandler public void onPickup(EntityPickupItemEvent event) { if (!(event.getEntity() instanceof Player)) return; + event.getItem().setItemStack(instance.getStackingTask().setMax(event.getItem().getItemStack(), 0, true)); + ItemStack item = event.getItem().getItemStack(); + + int amt = item.getAmount(); + int max = item.getMaxStackSize(); + + if (amt <= max) return; + + event.setCancelled(true); + + item.setAmount(max); + amt = amt - max; + + while (amt > max) { + ItemStack newItem = new ItemStack(item); + newItem.setAmount(max); + + event.getItem().getWorld().dropItemNaturally(event.getItem().getLocation(), newItem); + amt = amt - max; + } + + ItemStack newItem = new ItemStack(item); + newItem.setAmount(amt); + + event.getItem().getWorld().dropItemNaturally(event.getItem().getLocation(), newItem); + } @EventHandler