diff --git a/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java b/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java index 61388cf3..aea71bad 100644 --- a/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java +++ b/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java @@ -17,6 +17,11 @@ package com.comphenix.protocol.injector; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.accessors.Accessors; @@ -34,11 +39,6 @@ import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - /** * Used to perform certain operations on entities. * @@ -71,17 +71,27 @@ class EntityUtilities { trackedPlayers.removeAll(nmsPlayers); - // TODO Find equivalent method for newer versions + Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId()); if (scanPlayersMethod == null) { - Class trackerEntry = MinecraftReflection.getMinecraftClass("EntityTrackerEntry"); - scanPlayersMethod = Accessors.getMethodAccessor(trackerEntry, "scanPlayers"); + scanPlayersMethod = findScanPlayers(trackerEntry.getClass()); } - Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId()); scanPlayersMethod.invoke(trackerEntry, nmsPlayers); } + private MethodAccessor findScanPlayers(Class trackerClass) { + MethodAccessor candidate = Accessors.getMethodAcccessorOrNull(trackerClass, "scanPlayers"); + if (candidate != null) { + return candidate; + } + + FuzzyReflection fuzzy = FuzzyReflection.fromClass(trackerClass, true); + return Accessors.getMethodAccessor( + fuzzy.getMethod( + FuzzyMethodContract.newBuilder().returnTypeVoid().parameterExactArray(List.class).build())); + } + /** * Retrieve every client that is receiving information about a given entity. * @param entity - the entity that is being tracked.