mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-18 21:32:56 +01:00
Fix shared instance unregistering
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
0f352a8f92
commit
b26abc11b0
@ -114,12 +114,12 @@ public final class InstanceManager {
|
|||||||
// Unload all chunks
|
// Unload all chunks
|
||||||
if (instance instanceof InstanceContainer) {
|
if (instance instanceof InstanceContainer) {
|
||||||
instance.getChunks().forEach(instance::unloadChunk);
|
instance.getChunks().forEach(instance::unloadChunk);
|
||||||
|
var dispatcher = MinecraftServer.process().dispatcher();
|
||||||
|
instance.getChunks().forEach(dispatcher::deletePartition);
|
||||||
}
|
}
|
||||||
// Unregister
|
// Unregister
|
||||||
instance.setRegistered(false);
|
instance.setRegistered(false);
|
||||||
this.instances.remove(instance);
|
this.instances.remove(instance);
|
||||||
var dispatcher = MinecraftServer.process().dispatcher();
|
|
||||||
instance.getChunks().forEach(dispatcher::deletePartition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,12 @@ public interface FlexibleListener<E extends Event> {
|
|||||||
*/
|
*/
|
||||||
void followup(@NotNull Consumer<E> handler);
|
void followup(@NotNull Consumer<E> handler);
|
||||||
|
|
||||||
|
default void followup() {
|
||||||
|
followup(event -> {
|
||||||
|
// Empty
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fails if an event is received. Valid until the next followup call.
|
* Fails if an event is received. Valid until the next followup call.
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package net.minestom.server.instance;
|
||||||
|
|
||||||
|
import net.minestom.server.api.Env;
|
||||||
|
import net.minestom.server.api.EnvTest;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.event.player.PlayerTickEvent;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@EnvTest
|
||||||
|
public class InstanceUnregisterIntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sharedInstance(Env env) {
|
||||||
|
// Ensure that unregistering a shared instance does not unload the container chunks
|
||||||
|
var instanceManager = env.process().instance();
|
||||||
|
var instance = instanceManager.createInstanceContainer();
|
||||||
|
var shared1 = instanceManager.createSharedInstance(instance);
|
||||||
|
var connection = env.createConnection();
|
||||||
|
var player = connection.connect(shared1, new Pos(0, 40, 0)).join();
|
||||||
|
|
||||||
|
var listener = env.listen(PlayerTickEvent.class);
|
||||||
|
listener.followup();
|
||||||
|
env.tick();
|
||||||
|
|
||||||
|
player.setInstance(instanceManager.createSharedInstance(instance)).join();
|
||||||
|
listener.followup();
|
||||||
|
env.tick();
|
||||||
|
|
||||||
|
instanceManager.unregisterInstance(shared1);
|
||||||
|
listener.followup();
|
||||||
|
env.tick();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user