Fix EntityUtilities updateEntity on 1.14

Fixes #651
This commit is contained in:
Dan Mulloy 2019-08-03 13:03:16 -04:00
parent dd9eac3d6d
commit 19dd81ce94

View File

@ -17,6 +17,11 @@
package com.comphenix.protocol.injector; 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.FieldAccessException;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.Accessors;
@ -34,11 +39,6 @@ import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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. * Used to perform certain operations on entities.
* *
@ -71,17 +71,27 @@ class EntityUtilities {
trackedPlayers.removeAll(nmsPlayers); trackedPlayers.removeAll(nmsPlayers);
// TODO Find equivalent method for newer versions Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
if (scanPlayersMethod == null) { if (scanPlayersMethod == null) {
Class<?> trackerEntry = MinecraftReflection.getMinecraftClass("EntityTrackerEntry"); scanPlayersMethod = findScanPlayers(trackerEntry.getClass());
scanPlayersMethod = Accessors.getMethodAccessor(trackerEntry, "scanPlayers");
} }
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
scanPlayersMethod.invoke(trackerEntry, nmsPlayers); 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. * Retrieve every client that is receiving information about a given entity.
* @param entity - the entity that is being tracked. * @param entity - the entity that is being tracked.