diff --git a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java index c516979..de311c6 100644 --- a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java +++ b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java @@ -212,14 +212,19 @@ public class StackingTask extends BukkitRunnable { || minEntityStackSize > maxEntityStackSize) return; // If a stack was never found create a new one. - EntityStack newStack = stackManager.addStack(new EntityStack(livingEntity, (stackableFriends.size() + 1) > - maxEntityStackSize ? maxEntityStackSize : stackableFriends.size() + 1)); + EntityStack newStack = stackManager.addStack(new EntityStack(livingEntity, + Math.min((stackableFriends.size() + 1), maxEntityStackSize))); // Loop through the unstacked and unprocessed stackable friends while not creating // a stack larger than the maximum. stackableFriends.stream().filter(entity -> !stackManager.isStacked(entity) && !this.processed.contains(entity.getUniqueId())).limit(maxEntityStackSize).forEach(entity -> { + // Make sure we're not naming some poor kids pet. + if (entity.getCustomName() != null) { + processed.add(livingEntity.getUniqueId()); + return; + } // Fix the entities health. fixHealth(livingEntity, entity); newStack.addHealth(entity.getHealth()); @@ -262,7 +267,6 @@ public class StackingTask extends BukkitRunnable { } - private void fixHealth(LivingEntity entity, LivingEntity initialEntity) { if (!Setting.STACK_ENTITY_HEALTH.getBoolean() && Setting.CARRY_OVER_LOWEST_HEALTH.getBoolean() && initialEntity.getHealth() < entity.getHealth()) entity.setHealth(initialEntity.getHealth());