Fix paper-implementation not detecting additional worlds correctly

This commit is contained in:
Lukas Rieger (Blue) 2024-03-04 12:50:03 +01:00
parent aecbd23ba7
commit 0613037093
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
3 changed files with 44 additions and 8 deletions

View File

@ -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);

View File

@ -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() {

View File

@ -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;
}
}
}