diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index f0554b1..f2330e1 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -28,18 +28,20 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import java.util.Map; + public class BlockIdWrapper14 implements BlockIdWrapper { private static final Class chunkProviderServer = Reflection.getClass("{nms.server.level}.ChunkProviderServer"); private static final Reflection.MethodInvoker getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); private static final Class playerChunkMap = Reflection.getClass("{nms.server.level}.PlayerChunkMap"); private static final Reflection.FieldAccessor getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); - private static final Reflection.FieldAccessor entityTrackers = Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0); + private static final Reflection.FieldAccessor entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private final Int2ObjectMap trackers; + private final Map trackers; public BlockIdWrapper14() { trackers = entityTrackers.get(getPlayerChunkMap.get(getChunkProvider.invoke(getWorldHandle.invoke(Config.world)))); } @@ -71,13 +73,17 @@ public class BlockIdWrapper14 implements BlockIdWrapper { private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, int entity) { - updatePlayer.invoke(trackers.get(entity), getPlayer.invoke(player)); + Object tracker = trackers.get(entity); + if(tracker != null) + updatePlayer.invoke(tracker, getPlayer.invoke(player)); } private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "a" : "clear", entityPlayer); @Override public void untrackEntity(Player player, int entity) { - clearPlayer.invoke(trackers.get(entity), getPlayer.invoke(player)); + Object tracker = trackers.get(entity); + if(tracker != null) + clearPlayer.invoke(tracker, getPlayer.invoke(player)); } private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index f77fe95..d330cfb 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -58,13 +58,17 @@ public class BlockIdWrapper8 implements BlockIdWrapper { private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, int entity) { - updatePlayer.invoke(get.invoke(trackers, entity), getPlayer.invoke(player)); + Object tracker = get.invoke(trackers, entity); + if(tracker != null) + updatePlayer.invoke(tracker, getPlayer.invoke(player)); } private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTrackerEntry, "a", entityPlayer); @Override public void untrackEntity(Player player, int entity) { - clearPlayer.invoke(get.invoke(trackers, entity), getPlayer.invoke(player)); + Object tracker = get.invoke(trackers, entity); + if(tracker != null) + clearPlayer.invoke(tracker, getPlayer.invoke(player)); } @Override