cache tracker field

This commit is contained in:
Esmorall 2019-09-05 18:37:27 -03:00
parent 4208443d26
commit b0440f6b40

View File

@ -21,6 +21,16 @@ import net.minemora.entitytrackerfixer.util.Util;
public class UntrackerTask extends BukkitRunnable { public class UntrackerTask extends BukkitRunnable {
private static boolean running = false; private static boolean running = false;
private static Field trackerField;
static {
try {
trackerField = ReflectionUtils.getClassPrivateField(EntityTracker.class, "tracker");
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
@ -48,9 +58,8 @@ public class UntrackerTask extends BukkitRunnable {
ChunkProviderServer cps = ws.getChunkProvider(); ChunkProviderServer cps = ws.getChunkProvider();
try { try {
Field field = ReflectionUtils.getClassPrivateField(EntityTracker.class, "tracker");
for(EntityTracker et : cps.playerChunkMap.trackedEntities.values()) { for(EntityTracker et : cps.playerChunkMap.trackedEntities.values()) {
net.minecraft.server.v1_14_R1.Entity nmsEnt = (net.minecraft.server.v1_14_R1.Entity) field.get(et); net.minecraft.server.v1_14_R1.Entity nmsEnt = (net.minecraft.server.v1_14_R1.Entity) trackerField.get(et);
if(nmsEnt instanceof EntityPlayer) { if(nmsEnt instanceof EntityPlayer) {
continue; continue;
} }
@ -82,7 +91,7 @@ public class UntrackerTask extends BukkitRunnable {
UntrackedEntitiesCache.getInstance().add(nmsEnt); UntrackedEntitiesCache.getInstance().add(nmsEnt);
} }
} }
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { } catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }