mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-19 09:05:48 +01:00
Fix issue with entity tracking on PaperSpigot
This commit is contained in:
parent
f01b3999ff
commit
a189947617
@ -25,6 +25,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -101,6 +102,7 @@ class EntityUtilities {
|
|||||||
trackedPlayers.removeAll(nmsPlayers);
|
trackedPlayers.removeAll(nmsPlayers);
|
||||||
|
|
||||||
// We have to rely on a NAME once again. Damn it.
|
// We have to rely on a NAME once again. Damn it.
|
||||||
|
// TODO: Make sure this stays up to date with version changes
|
||||||
if (scanPlayersMethod == null) {
|
if (scanPlayersMethod == null) {
|
||||||
scanPlayersMethod = trackerEntry.getClass().getMethod("scanPlayers", List.class);
|
scanPlayersMethod = trackerEntry.getClass().getMethod("scanPlayers", List.class);
|
||||||
}
|
}
|
||||||
@ -133,14 +135,23 @@ class EntityUtilities {
|
|||||||
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
|
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
|
||||||
|
|
||||||
if (trackerEntry == null) {
|
if (trackerEntry == null) {
|
||||||
throw new IllegalArgumentException("Cannot find entity trackers for " + entity +
|
throw new IllegalArgumentException("Cannot find entity trackers for " + entity + (entity.isDead() ? " - entity is dead." : "."));
|
||||||
(entity.isDead() ? " - entity is dead." : "."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trackedPlayersField == null) {
|
if (trackedPlayersField == null) {
|
||||||
trackedPlayersField = FuzzyReflection.fromObject(trackerEntry).getFieldByType("java\\.util\\..*");
|
trackedPlayersField = FuzzyReflection.fromObject(trackerEntry).getFieldByType("java\\.util\\..*");
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<?> trackedPlayers = (Collection<?>) FieldUtils.readField(trackedPlayersField, trackerEntry, false);
|
Collection<?> trackedPlayers = null;
|
||||||
|
Object value = FieldUtils.readField(trackedPlayersField, trackerEntry, false);
|
||||||
|
|
||||||
|
if (value instanceof Collection) {
|
||||||
|
trackedPlayers = (Collection<?>) value;
|
||||||
|
} else if (value instanceof Map) { // PaperSpigot
|
||||||
|
trackedPlayers = ((Map<?, ?>) value).keySet();
|
||||||
|
} else { // Please, no more changes
|
||||||
|
throw new IllegalStateException("trackedPlayers field was an unknown type: expected Set or Map, but got " + value.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
// Wrap every player - we also ensure that the underlying tracker list is immutable
|
// Wrap every player - we also ensure that the underlying tracker list is immutable
|
||||||
for (Object tracker : trackedPlayers) {
|
for (Object tracker : trackedPlayers) {
|
||||||
|
Loading…
Reference in New Issue
Block a user