diff --git a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java index 4e609d41..6589c383 100644 --- a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java +++ b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java @@ -109,6 +109,14 @@ public BukkitPlugin() { @Override public void onEnable() { + //save world so the level.dat is present on new worlds + if (!FoliaSupport.IS_FOLIA) { + Logger.global.logInfo("Saving all worlds once, to make sure the level.dat is present..."); + for (World world : getServer().getWorlds()) { + world.save(); + } + } + //register events getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(eventForwarder, this); diff --git a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java index 57c9a290..78106c59 100644 --- a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java +++ b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java @@ -25,6 +25,7 @@ package de.bluecolored.bluemap.bukkit; import de.bluecolored.bluemap.common.serverinterface.ServerWorld; +import de.bluecolored.bluemap.core.resources.datapack.DataPack; import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.world.mca.MCAWorld; import org.bukkit.World; @@ -43,8 +44,15 @@ public BukkitWorld(World delegate) { this.delegate = new WeakReference<>(delegate); Path worldFolder = delegate.getWorldFolder().toPath(); - var id = delegate.key(); - this.dimension = new Key(id.namespace(), id.value()); + this.dimension = switch (delegate.getEnvironment()) { + case NORMAL -> DataPack.DIMENSION_OVERWORLD; + case NETHER -> DataPack.DIMENSION_THE_NETHER; + case THE_END -> DataPack.DIMENSION_THE_END; + case CUSTOM -> { + var id = delegate.key(); + yield new Key(id.namespace(), id.value()); + } + }; // fix for hybrids Path dimensionFolder = MCAWorld.resolveDimensionFolder(worldFolder, dimension); @@ -58,17 +66,18 @@ public BukkitWorld(World delegate) { this.worldFolder = worldFolder; } - /* Not supported by folia @Override public boolean persistWorldChanges() { - World world = delegate.get(); - if (world != null) { - world.save(); - return true; + if (!FoliaSupport.IS_FOLIA) { + World world = delegate.get(); + if (world != null) { + world.save(); + return true; + } } + return false; } - */ @Override public Path getWorldFolder() { diff --git a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/FoliaSupport.java b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/FoliaSupport.java new file mode 100644 index 00000000..65741e40 --- /dev/null +++ b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/FoliaSupport.java @@ -0,0 +1,19 @@ +package de.bluecolored.bluemap.bukkit; + +import de.bluecolored.bluemap.core.logger.Logger; + +public class FoliaSupport { + + public static final boolean IS_FOLIA = isFolia(); + + private static boolean isFolia() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + Logger.global.logInfo("Folia detected, enabling folia-support mode."); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + +}