Plug WorldMap Memory Leak

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2014-08-08 19:57:03 +10:00
parent 0098808c9e
commit 83699d54bf

View file

@ -347,12 +347,12 @@
+ ((ServerPlayer) this.players.get(idx)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false); + ((ServerPlayer) this.players.get(idx)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false);
+ } + }
+ } + }
} + }
+ for (int idx = 0; idx < this.players.size(); ++idx) { + for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((ServerPlayer) this.players.get(idx)).level() == this) { + if (((ServerPlayer) this.players.get(idx)).level() == this) {
+ ((ServerPlayer) this.players.get(idx)).updateWeather(this.oRainLevel, this.rainLevel, this.oThunderLevel, this.thunderLevel); + ((ServerPlayer) this.players.get(idx)).updateWeather(this.oRainLevel, this.rainLevel, this.oThunderLevel, this.thunderLevel);
+ } + }
+ } }
+ // CraftBukkit end + // CraftBukkit end
} }
@ -457,18 +457,19 @@
+ return this.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.DEFAULT); + return this.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
} }
- public boolean addWithUUID(Entity entity) {
- return this.addEntity(entity);
+ @Override + @Override
+ public boolean addFreshEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) { + public boolean addFreshEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason); + return this.addEntity(entity, reason);
+ // CraftBukkit end + // CraftBukkit end
+ }
+
public boolean addWithUUID(Entity entity) {
- return this.addEntity(entity);
+ // CraftBukkit start
+ return this.addWithUUID(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
} }
+ public boolean addWithUUID(Entity entity) {
+ // CraftBukkit start
+ return this.addWithUUID(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public boolean addWithUUID(Entity entity, CreatureSpawnEvent.SpawnReason reason) { + public boolean addWithUUID(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason); + return this.addEntity(entity, reason);
+ // CraftBukkit end + // CraftBukkit end
@ -799,7 +800,7 @@
ServerLevel.this.getChunkSource().addEntity(entity); ServerLevel.this.getChunkSource().addEntity(entity);
if (entity instanceof ServerPlayer entityplayer) { if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.add(entityplayer); ServerLevel.this.players.add(entityplayer);
@@ -1864,9 +2109,19 @@ @@ -1864,9 +2109,42 @@
} }
entity.updateDynamicGameEventListener(DynamicGameEventListener::add); entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@ -809,6 +810,29 @@
public void onTrackingEnd(Entity entity) { public void onTrackingEnd(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot + 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 ( Iterator<MapItemSavedData.HoldingPlayer> iter = (Iterator<MapItemSavedData.HoldingPlayer>) map.carriedBy.iterator(); iter.hasNext(); )
+ {
+ if ( iter.next().player == entity )
+ {
+ iter.remove();
+ }
+ }
+ }
+ }
+ } );
+ }
+ // Spigot end
+ // Spigot Start + // Spigot Start
+ if (entity.getBukkitEntity() instanceof org.bukkit.inventory.InventoryHolder && (!(entity instanceof ServerPlayer) || entity.getRemovalReason() != Entity.RemovalReason.KILLED)) { // SPIGOT-6876: closeInventory clears death message + if (entity.getBukkitEntity() instanceof org.bukkit.inventory.InventoryHolder && (!(entity instanceof ServerPlayer) || entity.getRemovalReason() != Entity.RemovalReason.KILLED)) { // SPIGOT-6876: closeInventory clears death message
+ for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((org.bukkit.inventory.InventoryHolder) entity.getBukkitEntity()).getInventory().getViewers())) { + for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((org.bukkit.inventory.InventoryHolder) entity.getBukkitEntity()).getInventory().getViewers())) {
@ -819,7 +843,7 @@
ServerLevel.this.getChunkSource().removeEntity(entity); ServerLevel.this.getChunkSource().removeEntity(entity);
if (entity instanceof ServerPlayer entityplayer) { if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.remove(entityplayer); ServerLevel.this.players.remove(entityplayer);
@@ -1895,6 +2150,14 @@ @@ -1895,6 +2173,14 @@
} }
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove); entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);