Archiviert
13
0

Fix issue with entity tracking on PaperSpigot

Dieser Commit ist enthalten in:
Dan Mulloy 2016-02-16 15:43:23 -05:00
Ursprung f01b3999ff
Commit a189947617

Datei anzeigen

@ -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) {