private void initialize() throws IllegalAccessException { if (intHashMap == null) { // We're looking for the first static field with a Minecraft-object. This should be a IntHashMap. Field intHashMapField = FuzzyReflection.fromClass(MinecraftReflection.getPacketClass(), true). getFieldByType("packetIdMap", MinecraftReflection.getIntHashMapClass()); try { intHashMap = WrappedIntHashMap.fromHandle( FieldUtils.readField(intHashMapField, (Object) null, true)); } catch (IllegalArgumentException e) { throw new RuntimeException("Minecraft is incompatible.", e); } } } }
private static Object getEntityTrackerEntry(World world, int entityID) throws FieldAccessException, IllegalArgumentException { BukkitUnwrapper unwrapper = new BukkitUnwrapper(); Object worldServer = unwrapper.unwrapItem(world); if (entityTrackerField == null) entityTrackerField = FuzzyReflection.fromObject(worldServer). getFieldByType("tracker", MinecraftReflection.getEntityTrackerClass()); // Get the tracker Object tracker = null; try { tracker = FieldUtils.readField(entityTrackerField, worldServer, false); } catch (IllegalAccessException e) { throw new FieldAccessException("Cannot access 'tracker' field due to security limitations.", e); } // Looking for an IntHashMap in the tracker entry if (trackedEntitiesField == null) { trackedEntitiesField = FuzzyReflection.fromObject(tracker, false) .getFieldByType("trackedEntities", MinecraftReflection.getIntHashMapClass()); } // Read the map Object trackedEntities = null; try { trackedEntities = FieldUtils.readField(trackedEntitiesField, tracker, false); } catch (IllegalAccessException e) { throw new FieldAccessException("Cannot access 'trackedEntities' field due to security limitations.", e); } return WrappedIntHashMap.fromHandle(trackedEntities).get(entityID); }