From f7cb9068628dcb672f4afaade91d2ecb322b52cf Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Wed, 21 Aug 2024 07:14:29 +0200 Subject: [PATCH] Cleanup more fields on player & world Signed-off-by: Pablo Herrera --- core/src/main/java/tc/oc/pgm/match/MatchImpl.java | 2 ++ .../main/java/tc/oc/pgm/match/MatchManagerImpl.java | 1 + .../main/java/tc/oc/pgm/match/MatchPlayerImpl.java | 1 + .../tc/oc/pgm/platform/modern/ModernNMSHacks.java | 10 ++++++++++ .../pgm/platform/sportpaper/NMSHacksSportPaper.java | 12 ++++++++++++ .../tc/oc/pgm/platform/sportpaper/SpPlayerUtils.java | 2 +- util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java | 4 ++++ 7 files changed, 31 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/tc/oc/pgm/match/MatchImpl.java b/core/src/main/java/tc/oc/pgm/match/MatchImpl.java index 193674d8da..4e059fdd89 100644 --- a/core/src/main/java/tc/oc/pgm/match/MatchImpl.java +++ b/core/src/main/java/tc/oc/pgm/match/MatchImpl.java @@ -2,6 +2,7 @@ import static tc.oc.pgm.util.Assert.assertNotNull; import static tc.oc.pgm.util.Assert.assertTrue; +import static tc.oc.pgm.util.nms.NMSHacks.NMS_HACKS; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -909,6 +910,7 @@ public void destroy() { if (world == null) return; final String worldName = world.getName(); + NMS_HACKS.cleanupWorld(world); if (PGM.get().getServer().unloadWorld(worldName, false)) { logger.fine("Successfully unloaded " + worldName); } else { diff --git a/core/src/main/java/tc/oc/pgm/match/MatchManagerImpl.java b/core/src/main/java/tc/oc/pgm/match/MatchManagerImpl.java index 2678af86d6..7621fed78a 100644 --- a/core/src/main/java/tc/oc/pgm/match/MatchManagerImpl.java +++ b/core/src/main/java/tc/oc/pgm/match/MatchManagerImpl.java @@ -104,6 +104,7 @@ private void onNonMatchUnload(World world) { if (name.startsWith("match")) return; NMS_HACKS.resetDimension(world); + NMS_HACKS.cleanupWorld(world); if (PGM.get().getServer().unloadWorld(name, false)) { logger.info("Unloaded non-match " + name); diff --git a/core/src/main/java/tc/oc/pgm/match/MatchPlayerImpl.java b/core/src/main/java/tc/oc/pgm/match/MatchPlayerImpl.java index 1be67591bb..2152df27dc 100644 --- a/core/src/main/java/tc/oc/pgm/match/MatchPlayerImpl.java +++ b/core/src/main/java/tc/oc/pgm/match/MatchPlayerImpl.java @@ -283,6 +283,7 @@ public void reset() { bukkit.setFlySpeed(0.1f); bukkit.setWalkSpeed(WalkSpeedKit.BUKKIT_DEFAULT); bukkit.setLastDamageCause(null); + NMS_HACKS.cleanupPlayer(bukkit); PLAYER_UTILS.clearArrowsInPlayer(bukkit); PLAYER_UTILS.setKnockbackReduction(bukkit, 0); bukkit.setVelocity(new Vector()); diff --git a/platform/platform-modern/src/main/java/tc/oc/pgm/platform/modern/ModernNMSHacks.java b/platform/platform-modern/src/main/java/tc/oc/pgm/platform/modern/ModernNMSHacks.java index 41c8901d3f..25ce36fa86 100644 --- a/platform/platform-modern/src/main/java/tc/oc/pgm/platform/modern/ModernNMSHacks.java +++ b/platform/platform-modern/src/main/java/tc/oc/pgm/platform/modern/ModernNMSHacks.java @@ -156,6 +156,16 @@ public void resetDimension(World world) { // no-op } + @Override + public void cleanupWorld(World world) { + // no-op + } + + @Override + public void cleanupPlayer(Player player) { + // no-op + } + @Override public double getTPS() { return Bukkit.getServer().getTPS()[0]; diff --git a/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/NMSHacksSportPaper.java b/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/NMSHacksSportPaper.java index e735673340..ad3d82540e 100644 --- a/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/NMSHacksSportPaper.java +++ b/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/NMSHacksSportPaper.java @@ -30,6 +30,7 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFireball; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFirework; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; import org.bukkit.entity.Entity; import org.bukkit.entity.Fireball; @@ -183,10 +184,21 @@ public void resetDimension(World world) { // No-op, newer version of Java have disabled modifying final fields } } + } + @Override + public void cleanupWorld(World world) { + var nmsWorld = ((CraftWorld) world).getHandle(); nmsWorld.craftingManager.lastCraftView = null; } + @Override + public void cleanupPlayer(Player player) { + var nmsPlayer = ((CraftPlayer) player).getHandle(); + nmsPlayer.killer = null; + nmsPlayer.p(null); // Resets who last hit the entityLiving + } + @Override public double getTPS() { return Bukkit.getServer().spigot().getTPS()[0]; diff --git a/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/SpPlayerUtils.java b/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/SpPlayerUtils.java index 03ca14e0e2..297fec67ed 100644 --- a/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/SpPlayerUtils.java +++ b/platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/SpPlayerUtils.java @@ -93,7 +93,7 @@ public float getKnockbackReduction(Player player) { @Override public void clearArrowsInPlayer(Player player) { - ((CraftPlayer) player).getHandle().o(0); + player.setArrowsStuck(0); } @Override diff --git a/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java b/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java index 17fce5d146..25b523c100 100644 --- a/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java +++ b/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java @@ -47,6 +47,10 @@ public interface NMSHacks { void resetDimension(World world); + void cleanupWorld(World world); + + void cleanupPlayer(Player player); + double getTPS(); void postToMainThread(Plugin plugin, boolean priority, Runnable task);