Archiviert
13
0

Avoid throwing errors with invalid entities

Dieser Commit ist enthalten in:
Dan Mulloy 2016-10-14 19:20:47 -04:00
Ursprung b5ecfb9c5f
Commit 17e150393a

Datei anzeigen

@ -63,10 +63,14 @@ class EntityUtilities {
*/ */
public static void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException { public static void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException {
if (entity == null || !entity.isValid()) {
return;
}
try { try {
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 + (entity.isDead() ? " - entity is dead." : ".")); throw new IllegalArgumentException("Cannot find entity trackers for " + entity + ".");
} }
if (trackedPlayersField == null) { if (trackedPlayersField == null) {
@ -106,12 +110,16 @@ class EntityUtilities {
* @throws FieldAccessException If reflection failed. * @throws FieldAccessException If reflection failed.
*/ */
public static List<Player> getEntityTrackers(Entity entity) { public static List<Player> getEntityTrackers(Entity entity) {
if (entity == null || !entity.isValid()) {
return new ArrayList<>();
}
try { try {
List<Player> result = new ArrayList<Player>(); List<Player> result = new ArrayList<Player>();
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 + (entity.isDead() ? " - entity is dead." : ".")); throw new IllegalArgumentException("Cannot find entity trackers for " + entity + ".");
} }
if (trackedPlayersField == null) { if (trackedPlayersField == null) {
@ -230,7 +238,6 @@ class EntityUtilities {
} }
private static List<Object> unwrapBukkit(List<Player> players) { private static List<Object> unwrapBukkit(List<Player> players) {
List<Object> output = Lists.newArrayList(); List<Object> output = Lists.newArrayList();
BukkitUnwrapper unwrapper = new BukkitUnwrapper(); BukkitUnwrapper unwrapper = new BukkitUnwrapper();