aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0294-Block-Entity-remove-from-being-called-on-Players.patch
blob: f8eface290fff12b0b12afef80e210f1be6249f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
From 0000000000000000000000000000000000000000 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

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 a87007a67ee1188150abab643329fa7314f9e583..fefe3dc1597d7449e0138be2f60918b06864108a 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2848,6 +2848,15 @@ 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()