Properly Close Inventories

Properly close inventories when unloading and switching worlds.

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2013-06-27 17:26:09 +10:00
parent 55148a3f2c
commit 1904e973f2

View file

@ -79,7 +79,7 @@
+ // CraftBukkit start
+ public final LevelStorageSource.LevelStorageAccess convertable;
+ public final UUID uuid;
+
+ public LevelChunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false);
+ }
@ -112,7 +112,7 @@
+ chunkgenerator = new FlatLevelSource(cpf.settings(), worldChunkManager);
+ }
+ }
+
+ if (gen != null) {
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
+ }
@ -338,8 +338,8 @@
+ if (((ServerPlayer) this.players.get(idx)).level() == this) {
+ ((ServerPlayer) this.players.get(idx)).tickWeather();
+ }
}
+ }
+
+ if (flag != this.isRaining()) {
+ // Only send weather packets to those affected
+ for (int idx = 0; idx < this.players.size(); ++idx) {
@ -347,14 +347,14 @@
+ ((ServerPlayer) this.players.get(idx)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false);
+ }
+ }
+ }
}
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((ServerPlayer) this.players.get(idx)).level() == this) {
+ ((ServerPlayer) this.players.get(idx)).updateWeather(this.oRainLevel, this.rainLevel, this.oThunderLevel, this.thunderLevel);
+ }
+ }
+ // CraftBukkit end
+
}
@VisibleForTesting
@ -492,7 +492,7 @@
}
}
@@ -939,24 +1080,38 @@
@@ -939,41 +1080,86 @@
this.entityManager.addNewEntity(player);
}
@ -535,7 +535,19 @@
return true;
}
}
@@ -967,13 +1122,35 @@
public void unload(LevelChunk chunk) {
+ // Spigot Start
+ for (net.minecraft.world.level.block.entity.BlockEntity tileentity : chunk.getBlockEntities().values()) {
+ if (tileentity instanceof net.minecraft.world.Container) {
+ for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((net.minecraft.world.Container) tileentity).getViewers())) {
+ h.closeInventory();
+ }
+ }
+ }
+ // Spigot End
chunk.clearAllBlockEntities();
chunk.unregisterTickContainerFromLevel(this);
}
public void removePlayerImmediately(ServerPlayer player, Entity.RemovalReason reason) {
@ -572,7 +584,7 @@
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
@@ -982,6 +1159,12 @@
@@ -982,6 +1168,12 @@
double d1 = (double) pos.getY() - entityplayer.getY();
double d2 = (double) pos.getZ() - entityplayer.getZ();
@ -585,7 +597,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
}
@@ -1060,7 +1243,18 @@
@@ -1060,7 +1252,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@ -605,7 +617,7 @@
PathNavigation navigationabstract = entityinsentient.getNavigation();
if (navigationabstract.shouldRecomputePath(pos)) {
@@ -1126,9 +1320,15 @@
@@ -1126,9 +1329,15 @@
@Override
public void explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, ParticleOptions smallParticle, ParticleOptions largeParticle, Holder<SoundEvent> soundEvent) {
@ -622,7 +634,7 @@
case NONE:
explosion_effect = Explosion.BlockInteraction.KEEP;
break;
@@ -1144,16 +1344,26 @@
@@ -1144,16 +1353,26 @@
case TRIGGER:
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
break;
@ -652,7 +664,7 @@
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
@@ -1162,10 +1372,11 @@
@@ -1162,10 +1381,11 @@
if (entityplayer.distanceToSqr(vec3d) < 4096.0D) {
Optional<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
@ -665,7 +677,7 @@
}
private Explosion.BlockInteraction getDestroyType(GameRules.Key<GameRules.BooleanValue> decayRule) {
@@ -1226,17 +1437,24 @@
@@ -1226,17 +1446,24 @@
}
public <T extends ParticleOptions> int sendParticles(T parameters, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) {
@ -693,7 +705,7 @@
++j;
}
}
@@ -1292,7 +1510,7 @@
@@ -1292,7 +1519,7 @@
@Nullable
public BlockPos findNearestMapStructure(TagKey<Structure> structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) {
@ -702,7 +714,7 @@
return null;
} else {
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(structureTag);
@@ -1334,11 +1552,22 @@
@@ -1334,11 +1561,22 @@
@Nullable
@Override
public MapItemSavedData getMapData(MapId id) {
@ -726,7 +738,7 @@
this.getServer().overworld().getDataStorage().set(id.key(), state);
}
@@ -1649,6 +1878,11 @@
@@ -1649,6 +1887,11 @@
@Override
public void blockUpdated(BlockPos pos, Block block) {
if (!this.isDebug()) {
@ -738,7 +750,7 @@
this.updateNeighborsAt(pos, block);
}
@@ -1668,12 +1902,12 @@
@@ -1668,12 +1911,12 @@
}
public boolean isFlat() {
@ -753,7 +765,7 @@
}
@Nullable
@@ -1696,7 +1930,7 @@
@@ -1696,7 +1939,7 @@
private static <T> String getTypeCount(Iterable<T> items, Function<T, String> classifier) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
@ -762,7 +774,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1705,7 +1939,7 @@
@@ -1705,7 +1948,7 @@
object2intopenhashmap.addTo(s, 1);
}
@ -771,7 +783,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1717,6 +1951,7 @@
@@ -1717,6 +1960,7 @@
@Override
public LevelEntityGetter<Entity> getEntities() {
@ -779,7 +791,7 @@
return this.entityManager.getEntityGetter();
}
@@ -1836,6 +2071,7 @@
@@ -1836,6 +2080,7 @@
}
public void onTrackingStart(Entity entity) {
@ -787,7 +799,7 @@
ServerLevel.this.getChunkSource().addEntity(entity);
if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.add(entityplayer);
@@ -1864,9 +2100,12 @@
@@ -1864,9 +2109,19 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@ -797,10 +809,17 @@
public void onTrackingEnd(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
+ // Spigot Start
+ 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())) {
+ h.closeInventory();
+ }
+ }
+ // Spigot End
ServerLevel.this.getChunkSource().removeEntity(entity);
if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.remove(entityplayer);
@@ -1895,6 +2134,14 @@
@@ -1895,6 +2150,14 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);