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
1 changed files with 19 additions and 9 deletions

View File

@ -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.