Major performance improvements.

This commit is contained in:
Brianna 2019-12-14 18:46:38 -05:00
parent 80a81a1cb8
commit 7a1cede33b
2 changed files with 15 additions and 2 deletions

View File

@ -25,7 +25,7 @@ public class EntityStackManager {
public EntityStack addStack(UUID uuid, int amount) {
EntityStack stack = new EntityStack(uuid, amount);
stacks.put(uuid, new EntityStack(uuid, amount));
stacks.put(uuid, stack);
return stack;
}
@ -36,7 +36,7 @@ public class EntityStackManager {
if (!name.contains(":")) return null;
String split = name.split(":")[0];
int amount = Methods.isInt(split) ? Integer.parseInt(split) : 0;
addStack(entity, amount);
return addStack(entity, amount);
}
return null;
}

View File

@ -2,7 +2,9 @@ package com.songoda.ultimatestacker.utils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import java.util.Objects;
@ -16,6 +18,10 @@ public class CachedChunk {
this(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
}
public CachedChunk(Location location) {
this(location.getWorld().getName(), (int)location.getX() >> 4, (int)location.getZ() >> 4);
}
public CachedChunk(String world, int x, int z) {
this.world = world;
this.x = x;
@ -41,6 +47,13 @@ public class CachedChunk {
return world.getChunkAt(this.x, this.z);
}
public Entity[] getEntities() {
if (!Bukkit.getWorld(world).isChunkLoaded(x, z)) {
return new Entity[0];
}
return getChunk().getEntities();
}
@Override
public boolean equals(Object o) {
if (o instanceof Chunk) {