diff --git a/src/main/java/com/songoda/ultimatestacker/stackable/entity/EntityStack.java b/src/main/java/com/songoda/ultimatestacker/stackable/entity/EntityStack.java index f333ebf..beda971 100644 --- a/src/main/java/com/songoda/ultimatestacker/stackable/entity/EntityStack.java +++ b/src/main/java/com/songoda/ultimatestacker/stackable/entity/EntityStack.java @@ -16,6 +16,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -41,6 +42,20 @@ public class EntityStack extends ColdEntityStack { return stackedEntity; } + @Override + public List takeEntities(int amount) { + List entities = super.takeEntities(amount); + if (this.stackedEntities.isEmpty()) + destroy(true); + return entities; + } + + @Override + public List takeAllEntities() { + destroy(true); + return super.takeAllEntities(); + } + public void updateStack() { if (createDuplicates != 0) { List stackedEntities = new ArrayList<>(); diff --git a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java index df6adc1..e187cb4 100644 --- a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java +++ b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java @@ -189,16 +189,16 @@ public class StackingTask extends BukkitRunnable { // If we are a stack lets merge our stack with the just found friend stack. if (isStack) { + // Get the host entity. + StackedEntity host = stack.getHostAsStackedEntity(); // Get all the stacked entities in our stack and add them to a list. List entities = stack.takeAllEntities(); // Add the host to this list. - entities.add(stack.getHostAsStackedEntity()); + entities.add(host); // Add the collected entities to the new stack. friendStack.addEntitiesToStackSilently(entities); // Update friend stack to display changes. friendStack.updateStack(); - // Destroy our stack. - stack.destroy(); // Push changes to the database. plugin.getDataManager().createStackedEntities(friendStack, entities); } else {