mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-29 03:48:43 +01:00
Fixed memory leak.
List will now update correctly.
This commit is contained in:
parent
a39347b5a7
commit
ee92b59184
@ -44,7 +44,8 @@ public class EntityStack {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
updateStack();
|
if (amount != 0)
|
||||||
|
updateStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class StackingTask extends BukkitRunnable {
|
public class StackingTask extends BukkitRunnable {
|
||||||
|
|
||||||
@ -56,6 +57,8 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
List<Entity> entities = world.getEntities();
|
List<Entity> entities = world.getEntities();
|
||||||
Collections.reverse(entities);
|
Collections.reverse(entities);
|
||||||
|
|
||||||
|
List<UUID> removed = new ArrayList<>();
|
||||||
|
|
||||||
nextEntity:
|
nextEntity:
|
||||||
for (Entity entityO : entities) {
|
for (Entity entityO : entities) {
|
||||||
if (entityO == null || entityO instanceof Player) continue;
|
if (entityO == null || entityO instanceof Player) continue;
|
||||||
@ -114,6 +117,7 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
List<Entity> entityList = Methods.getSimilarEntitesAroundEntity(initalEntity);
|
List<Entity> entityList = Methods.getSimilarEntitesAroundEntity(initalEntity);
|
||||||
|
|
||||||
for (Entity entity : new ArrayList<>(entityList)) {
|
for (Entity entity : new ArrayList<>(entityList)) {
|
||||||
|
if (removed.contains(entity.getUniqueId())) continue;
|
||||||
EntityStack stack = stackManager.getStack(entity);
|
EntityStack stack = stackManager.getStack(entity);
|
||||||
if (stack == null && entity.getCustomName() != null) {
|
if (stack == null && entity.getCustomName() != null) {
|
||||||
entityList.remove(entity);
|
entityList.remove(entity);
|
||||||
@ -124,7 +128,9 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
if (stack != null && (stack.getAmount() + amtToStack) <= maxEntityStackSize) {
|
if (stack != null && (stack.getAmount() + amtToStack) <= maxEntityStackSize) {
|
||||||
stack.addAmount(amtToStack);
|
stack.addAmount(amtToStack);
|
||||||
stack.updateStack();
|
stack.updateStack();
|
||||||
|
removed.add(initalEntity.getUniqueId());
|
||||||
initalEntity.remove();
|
initalEntity.remove();
|
||||||
|
|
||||||
continue nextEntity;
|
continue nextEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,13 +145,15 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
EntityStack stack = stackManager.addStack(new EntityStack(initalEntity, entityList.size() + 1));
|
EntityStack stack = stackManager.addStack(new EntityStack(initalEntity, entityList.size() + 1));
|
||||||
|
|
||||||
for (Entity entity : entityList) {
|
for (Entity entity : entityList) {
|
||||||
if (stackManager.isStacked(entity)) continue;
|
if (stackManager.isStacked(entity) || removed.contains(entity.getUniqueId())) continue;
|
||||||
|
removed.add(entity.getUniqueId());
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.updateStack();
|
stack.updateStack();
|
||||||
}
|
}
|
||||||
entities.clear();
|
entities.clear();
|
||||||
|
removed.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user