From a15bb2bbd0bdca210ef58a371bc12feaf6a0e4cb Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 16 Dec 2024 09:56:45 +0100 Subject: [PATCH] Fix and clean up MapItemSavedData Spigot patch It's been dysfunctional for a good while, though I don't think it's even needed. That can be investigated later --- .../server/level/ServerLevel.java.patch | 32 +++++++------------ .../craftbukkit/entity/CraftEntity.java | 2 +- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch index 30adc7ef05..daa7e73901 100644 --- a/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch @@ -1097,7 +1097,7 @@ String string = "onTrackingStart called during navigation iteration"; Util.logAndPauseIfInIde( "onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration") -@@ -1757,10 +_,61 @@ +@@ -1757,10 +_,51 @@ } entity.updateDynamicGameEventListener(DynamicGameEventListener::add); @@ -1120,28 +1120,18 @@ public void onTrackingEnd(Entity entity) { + org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot + // Spigot start -+ if ( entity instanceof Player ) -+ { -+ com.google.common.collect.Streams.stream( ServerLevel.this.getServer().getAllLevels() ).map( ServerLevel::getDataStorage ).forEach( (worldData) -> -+ { -+ for (Object o : worldData.cache.values() ) -+ { -+ if ( o instanceof MapItemSavedData ) -+ { -+ MapItemSavedData map = (MapItemSavedData) o; -+ map.carriedByPlayers.remove( (Player) entity ); -+ for ( -+ java.util.Iterator iter = map.carriedBy.iterator(); -+ iter.hasNext(); -+ ) { -+ if ( iter.next().player == entity ) -+ { -+ iter.remove(); -+ } -+ } ++ // TODO I don't think this is needed anymore ++ if (entity instanceof Player player) { ++ for (final ServerLevel level : ServerLevel.this.getServer().getAllLevels()) { ++ for (final Optional savedData : level.getDataStorage().cache.values()) { ++ if (savedData.isEmpty() || !(savedData.get() instanceof MapItemSavedData map)) { ++ continue; + } ++ ++ map.carriedByPlayers.remove(player); ++ map.carriedBy.removeIf(holdingPlayer -> holdingPlayer.player == player); + } -+ } ); ++ } + } + // Spigot end + // Spigot Start diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 98c1a4cff9..8c3a6a15dd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -857,7 +857,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { @Override public void setPortalCooldown(int cooldown) { - this.getHandle().setPortalCooldown(cooldown);; + this.getHandle().setPortalCooldown(cooldown); } @Override