From 17e150393aea860483b515ae6975a73e75574d7c Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 14 Oct 2016 19:20:47 -0400 Subject: [PATCH] Avoid throwing errors with invalid entities --- .../protocol/injector/EntityUtilities.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java index 36a71f5a..e326a20e 100644 --- a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java +++ b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java @@ -63,10 +63,14 @@ class EntityUtilities { */ public static void updateEntity(Entity entity, List observers) throws FieldAccessException { + if (entity == null || !entity.isValid()) { + return; + } + try { Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId()); 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) { @@ -106,12 +110,16 @@ class EntityUtilities { * @throws FieldAccessException If reflection failed. */ public static List getEntityTrackers(Entity entity) { + if (entity == null || !entity.isValid()) { + return new ArrayList<>(); + } + try { List result = new ArrayList(); Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId()); 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) { @@ -230,7 +238,6 @@ class EntityUtilities { } private static List unwrapBukkit(List players) { - List output = Lists.newArrayList(); BukkitUnwrapper unwrapper = new BukkitUnwrapper();