diff --git a/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java b/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java index 8ac9f6b..19ae76c 100644 --- a/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java @@ -49,6 +49,30 @@ public class EntityListeners implements Listener { } } + @EventHandler + public void onEgg(ItemSpawnEvent event) { + if (event.getEntity().getItemStack().getType() != Material.EGG) return; + + Location location = event.getLocation(); + + List entities = new ArrayList<>(location.getWorld().getNearbyEntities(location, .1, .5, .1)); + + if (entities.isEmpty()) return; + + Entity entity = entities.get(0); + + EntityStackManager stackManager = instance.getEntityStackManager(); + + if (!stackManager.isStacked(entity)) return; + + EntityStack stack = stackManager.getStack(entity); + + ItemStack item = event.getEntity().getItemStack(); + item.setAmount((stack.getAmount() - 1) + item.getAmount() > item.getMaxStackSize() ? item.getMaxStackSize() + : item.getAmount() + (stack.getAmount() - 1)); + event.getEntity().setItemStack(item); + } + @EventHandler public void onPickup(EntityPickupItemEvent event) { if (!(event.getEntity() instanceof Player)) return;