mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Added InstanceManager#unregisterInstance
This commit is contained in:
parent
5ff56212a2
commit
670887f7b3
@ -1606,9 +1606,6 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
PlayerPositionAndLookPacket positionAndLookPacket = new PlayerPositionAndLookPacket();
|
||||
positionAndLookPacket.position = position.clone();
|
||||
positionAndLookPacket.flags = 0x00;
|
||||
if (teleportId == Integer.MAX_VALUE) {
|
||||
teleportId = 0;
|
||||
}
|
||||
positionAndLookPacket.teleportId = teleportId++;
|
||||
playerConnection.sendPacket(positionAndLookPacket);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
private ChunkGenerator chunkGenerator;
|
||||
private final ConcurrentHashMap<Long, Chunk> chunks = new ConcurrentHashMap<>();
|
||||
private final Set<Chunk> scheduledChunksToRemove = new HashSet<>();
|
||||
protected final Set<Chunk> scheduledChunksToRemove = new HashSet<>();
|
||||
|
||||
private ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
|
||||
private Map<BlockPosition, Block> currentlyChangingBlocks = new HashMap<>();
|
||||
@ -657,7 +657,7 @@ public class InstanceContainer extends Instance {
|
||||
* <p>
|
||||
* Unsafe because it has to be done on the same thread as the instance/chunks tick update
|
||||
*/
|
||||
private void UNSAFE_unloadChunks() {
|
||||
protected void UNSAFE_unloadChunks() {
|
||||
synchronized (this.scheduledChunksToRemove) {
|
||||
for (Chunk chunk : scheduledChunksToRemove) {
|
||||
final int chunkX = chunk.getChunkX();
|
||||
|
@ -101,6 +101,27 @@ public final class InstanceManager {
|
||||
return registerSharedInstance(sharedInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the {@link Instance} internally
|
||||
* <p>
|
||||
* If {@code instance} is an {@link InstanceContainer} all chunks are unloaded
|
||||
*
|
||||
* @param instance the {@link Instance} to unregister
|
||||
*/
|
||||
public void unregisterInstance(Instance instance) {
|
||||
Check.stateCondition(!instance.getPlayers().isEmpty(), "You cannot unregister an instance with players");
|
||||
|
||||
// Unload all chunks
|
||||
if (instance instanceof InstanceContainer) {
|
||||
InstanceContainer instanceContainer = (InstanceContainer) instance;
|
||||
instanceContainer.scheduledChunksToRemove.addAll(instanceContainer.getChunks());
|
||||
instanceContainer.UNSAFE_unloadChunks();
|
||||
}
|
||||
|
||||
instance.setRegistered(false);
|
||||
this.instances.remove(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the registered instances
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user