fix: reuse already loaded world and handle Folia unsupported world creation

This commit is contained in:
loki5512344 2026-10-06 11:35:16 +02:00
parent 4e3ccfd736
commit cc521dc284
Signed by: boba
GPG key ID: 253067914055423B

View file

@ -54,6 +54,11 @@ public class World {
if (Config.CONFIG.getBoolean("world.delete-on-reload")) {
deleteWorld();
} else if (world != null) {
// Already loaded (e.g. pre-created by a worlds plugin, required on Folia) — do not recreate.
LoParkour.log("Using already loaded world " + name);
setup();
return;
}
createWorld();
@ -71,6 +76,10 @@ public class World {
.environment(org.bukkit.World.Environment.NORMAL);
world = Bukkit.createWorld(creator);
} catch (UnsupportedOperationException ex) {
LoParkour.getPlugin().getLogger().severe(
"World creation is not supported on this server (Folia). Pre-create the world '" + name
+ "' with a worlds plugin and restart.");
} catch (IllegalArgumentException | IllegalStateException ex) {
LoParkour.getPlugin().getLogger().severe(
"Error while trying to create the parkour world — check world.name — " + ex.getMessage());
@ -130,7 +139,13 @@ public class World {
return;
}
Bukkit.unloadWorld(name, false);
try {
Bukkit.unloadWorld(name, false);
} catch (UnsupportedOperationException ex) {
LoParkour.getPlugin().getLogger().severe(
"Cannot unload/delete world on this server (Folia) — set world.delete-on-reload to false.");
return;
}
try (Stream<Path> files = Files.walk(folder.toPath())) {
files.sorted(Comparator.reverseOrder())