Skip to content

Commit 17e1503

Browse files
committed
Avoid throwing errors with invalid entities
1 parent b5ecfb9 commit 17e1503

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ public static void updateEntity2(Entity entity, List<Player> observers) {
6363
*/
6464

6565
public static void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException {
66+
if (entity == null || !entity.isValid()) {
67+
return;
68+
}
69+
6670
try {
6771
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
6872
if (trackerEntry == null) {
69-
throw new IllegalArgumentException("Cannot find entity trackers for " + entity + (entity.isDead() ? " - entity is dead." : "."));
73+
throw new IllegalArgumentException("Cannot find entity trackers for " + entity + ".");
7074
}
7175

7276
if (trackedPlayersField == null) {
@@ -106,12 +110,16 @@ public static void updateEntity(Entity entity, List<Player> observers) throws Fi
106110
* @throws FieldAccessException If reflection failed.
107111
*/
108112
public static List<Player> getEntityTrackers(Entity entity) {
113+
if (entity == null || !entity.isValid()) {
114+
return new ArrayList<>();
115+
}
116+
109117
try {
110118
List<Player> result = new ArrayList<Player>();
111119

112120
Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId());
113121
if (trackerEntry == null) {
114-
throw new IllegalArgumentException("Cannot find entity trackers for " + entity + (entity.isDead() ? " - entity is dead." : "."));
122+
throw new IllegalArgumentException("Cannot find entity trackers for " + entity + ".");
115123
}
116124

117125
if (trackedPlayersField == null) {
@@ -230,7 +238,6 @@ public static Entity getEntityFromID(World world, int entityID) throws FieldAcce
230238
}
231239

232240
private static List<Object> unwrapBukkit(List<Player> players) {
233-
234241
List<Object> output = Lists.newArrayList();
235242
BukkitUnwrapper unwrapper = new BukkitUnwrapper();
236243

0 commit comments

Comments
 (0)