diff --git a/src/main/java/xyz/nucleoid/fantasy/Fantasy.java b/src/main/java/xyz/nucleoid/fantasy/Fantasy.java index c718c7d..83b5882 100644 --- a/src/main/java/xyz/nucleoid/fantasy/Fantasy.java +++ b/src/main/java/xyz/nucleoid/fantasy/Fantasy.java @@ -108,7 +108,23 @@ private void tick() { * @return a future providing the created world */ public RuntimeWorldHandle openTemporaryWorld(RuntimeWorldConfig config) { - RuntimeWorld world = this.addTemporaryWorld(config); + return this.openTemporaryWorld(generateTemporaryWorldKey(), config); + } + + /** + * Creates a new temporary world with the given identifier and {@link RuntimeWorldConfig} that will not be saved and will be + * deleted when the server exits. + *

+ * The created world is returned asynchronously through a {@link RuntimeWorldHandle}. + * This handle can be used to acquire the {@link ServerWorld} object through {@link RuntimeWorldHandle#asWorld()}, + * as well as to delete the world through {@link RuntimeWorldHandle#delete()}. + * + * @param key the unique identifier for this dimension + * @param config the config with which to construct this temporary world + * @return a future providing the created world + */ + public RuntimeWorldHandle openTemporaryWorld(Identifier key, RuntimeWorldConfig config) { + RuntimeWorld world = this.addTemporaryWorld(key, config); return new RuntimeWorldHandle(this, world); } @@ -147,8 +163,8 @@ private RuntimeWorld addPersistentWorld(Identifier key, RuntimeWorldConfig confi return this.worldManager.add(worldKey, config, RuntimeWorld.Style.PERSISTENT); } - private RuntimeWorld addTemporaryWorld(RuntimeWorldConfig config) { - RegistryKey worldKey = RegistryKey.of(RegistryKeys.WORLD, generateTemporaryWorldKey()); + private RuntimeWorld addTemporaryWorld(Identifier key, RuntimeWorldConfig config) { + RegistryKey worldKey = RegistryKey.of(RegistryKeys.WORLD, key); try { LevelStorage.Session session = this.serverAccess.getSession(); @@ -171,7 +187,7 @@ void enqueueWorldUnloading(ServerWorld world) { }); } - private boolean tickDeleteWorld(ServerWorld world) { + public boolean tickDeleteWorld(ServerWorld world) { if (this.isWorldUnloaded(world)) { this.worldManager.delete(world); return true; @@ -181,7 +197,7 @@ private boolean tickDeleteWorld(ServerWorld world) { } } - private boolean tickUnloadWorld(ServerWorld world) { + public boolean tickUnloadWorld(ServerWorld world) { if (this.isWorldUnloaded(world)) { this.worldManager.unload(world); return true;