Only enforce CraftPlayer#remove exception on instances of EntityPlayer

Should be more friendly to plugins that dabble in inheriting NMS
entities.
This commit is contained in:
Zach Brown 2019-02-05 07:44:36 -05:00
parent 28cf2696d4
commit 8211569c9a
No known key found for this signature in database
GPG key ID: CC9DA35FC5450B76

View file

@ -1,4 +1,4 @@
From 77bf3954e56da679c67b1fab72772d8824ffb401 Mon Sep 17 00:00:00 2001
From 0ccfc3c7b8ddd8ba3b7e3ac5e6d9d107ce7d15ff Mon Sep 17 00:00:00 2001
From: Zach Brown <zach@zachbr.io>
Date: Mon, 4 Feb 2019 23:33:24 -0500
Subject: [PATCH] Block Entity#remove from being called on Players
@ -12,17 +12,21 @@ Player we will look at limiting the scope of this change. It appears to
be unintentional in the few cases we've seen so far.
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 36a38713..7b7dc7f2 100644
index 36a38713..fbe34290 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1937,6 +1937,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -1937,6 +1937,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void resetCooldown() {
getHandle().resetCooldown();
}
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Calling Entity#remove on players produces undefined (bad) behavior");
+ if (this.getHandle().getClass().equals(EntityPlayer.class)) { // special case for NMS plugins inheriting
+ throw new UnsupportedOperationException("Calling Entity#remove on players produces undefined (bad) behavior");
+ } else {
+ super.remove();
+ }
+ }
//Paper end