API improvements.

This commit is contained in:
Brianna 2020-08-31 17:34:39 -05:00
parent ea5e56f431
commit b82c128910
2 changed files with 18 additions and 3 deletions

View File

@ -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<StackedEntity> takeEntities(int amount) {
List<StackedEntity> entities = super.takeEntities(amount);
if (this.stackedEntities.isEmpty())
destroy(true);
return entities;
}
@Override
public List<StackedEntity> takeAllEntities() {
destroy(true);
return super.takeAllEntities();
}
public void updateStack() {
if (createDuplicates != 0) {
List<StackedEntity> stackedEntities = new ArrayList<>();

View File

@ -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<StackedEntity> 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 {