From b7a964f3872c960093a7bdebfe0cf7a5eb0e5620 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Wed, 6 Dec 2023 09:54:52 -0800 Subject: [PATCH] Upstream blocked Player#remove so our patch needed to be refactored --- ...-remove-from-being-called-on-Players.patch | 33 ------------------- ...r-remove-if-the-handle-is-a-custom-p.patch | 26 +++++++++++++++ 2 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 patches/server/Block-Entity-remove-from-being-called-on-Players.patch create mode 100644 patches/server/Dont-block-Player-remove-if-the-handle-is-a-custom-p.patch diff --git a/patches/server/Block-Entity-remove-from-being-called-on-Players.patch b/patches/server/Block-Entity-remove-from-being-called-on-Players.patch deleted file mode 100644 index 7d6f94bb60..0000000000 --- a/patches/server/Block-Entity-remove-from-being-called-on-Players.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Zach Brown <1254957+zachbr@users.noreply.github.com> -Date: Mon, 4 Feb 2019 23:33:24 -0500 -Subject: [PATCH] Block Entity#remove from being called on Players - -This doesn't result in the same behavior as other entities and causes -several problems. Anyone ever complain about the "Cannot send chat -message" thing? That's one of the issues this causes, among others. - -If a plugin developer can come up with a valid reason to call this on a -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player { - public void resetCooldown() { - getHandle().resetAttackStrengthTicker(); - } -+ -+ @Override -+ public void remove() { -+ if (this.getHandle().getClass().equals(ServerPlayer.class)) { // special case for NMS plugins inheriting -+ throw new UnsupportedOperationException("Calling Entity#remove on players produces undefined (bad) behavior"); -+ } else { -+ super.remove(); -+ } -+ } - // Paper end - // Spigot start - private final Player.Spigot spigot = new Player.Spigot() diff --git a/patches/server/Dont-block-Player-remove-if-the-handle-is-a-custom-p.patch b/patches/server/Dont-block-Player-remove-if-the-handle-is-a-custom-p.patch new file mode 100644 index 0000000000..99f7ed04c6 --- /dev/null +++ b/patches/server/Dont-block-Player-remove-if-the-handle-is-a-custom-p.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Zach Brown <1254957+zachbr@users.noreply.github.com> +Date: Mon, 4 Feb 2019 23:33:24 -0500 +Subject: [PATCH] Dont block Player#remove if the handle is a custom player + +Upstream throws UOE if you try to call remove on a Player. +We just add a check to ensure that the CraftPlayer's handle +is a ServerPlayer + +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + + @Override + public void remove() { ++ if (this.getHandle().getClass().equals(ServerPlayer.class)) { // special case for NMS plugins inheriting + // Will lead to an inconsistent player state if we remove the player as any other entity. + throw new UnsupportedOperationException(String.format("Cannot remove player %s, use Player#kickPlayer(String) instead.", this.getName())); ++ } else { ++ super.remove(); ++ } + } + + @Override