mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Fixed instance switch while unloading chunk
This commit is contained in:
parent
b7b334645f
commit
895a4fd4bd
@ -295,9 +295,13 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
|
||||
/**
|
||||
* @param chunk the chunk to get the entities from
|
||||
* @return an unmodifiable set containing all the entities in a chunk
|
||||
* @return an unmodifiable set containing all the entities in a chunk,
|
||||
* if {@code chunk} is null, return an empty {@link HashSet}
|
||||
*/
|
||||
public Set<Entity> getChunkEntities(Chunk chunk) {
|
||||
if (chunk == null)
|
||||
return new HashSet<>();
|
||||
|
||||
long index = ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ());
|
||||
return Collections.unmodifiableSet(getEntitiesInChunk(index));
|
||||
}
|
||||
@ -545,14 +549,16 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
* @param chunk the chunk where the entity will be removed
|
||||
*/
|
||||
public void removeEntityFromChunk(Entity entity, Chunk chunk) {
|
||||
long chunkIndex = ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ());
|
||||
synchronized (chunkEntities) {
|
||||
Set<Entity> entities = getEntitiesInChunk(chunkIndex);
|
||||
entities.remove(entity);
|
||||
if (entities.isEmpty()) {
|
||||
this.chunkEntities.remove(chunkIndex);
|
||||
} else {
|
||||
this.chunkEntities.put(chunkIndex, entities);
|
||||
if (chunk != null) {
|
||||
long chunkIndex = ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ());
|
||||
Set<Entity> entities = getEntitiesInChunk(chunkIndex);
|
||||
entities.remove(entity);
|
||||
if (entities.isEmpty()) {
|
||||
this.chunkEntities.remove(chunkIndex);
|
||||
} else {
|
||||
this.chunkEntities.put(chunkIndex, entities);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof Player) {
|
||||
|
@ -314,6 +314,8 @@ public class InstanceContainer extends Instance {
|
||||
}
|
||||
|
||||
this.chunks.remove(index);
|
||||
this.chunkEntities.remove(index);
|
||||
|
||||
chunk.unload();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user