Skip to content

Commit 0613037

Browse files
committed
Fix paper-implementation not detecting additional worlds correctly
1 parent aecbd23 commit 0613037

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public BukkitPlugin() {
109109
@Override
110110
public void onEnable() {
111111

112+
//save world so the level.dat is present on new worlds
113+
if (!FoliaSupport.IS_FOLIA) {
114+
Logger.global.logInfo("Saving all worlds once, to make sure the level.dat is present...");
115+
for (World world : getServer().getWorlds()) {
116+
world.save();
117+
}
118+
}
119+
112120
//register events
113121
getServer().getPluginManager().registerEvents(this, this);
114122
getServer().getPluginManager().registerEvents(eventForwarder, this);

implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package de.bluecolored.bluemap.bukkit;
2626

2727
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
28+
import de.bluecolored.bluemap.core.resources.datapack.DataPack;
2829
import de.bluecolored.bluemap.core.util.Key;
2930
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
3031
import org.bukkit.World;
@@ -43,8 +44,15 @@ public BukkitWorld(World delegate) {
4344
this.delegate = new WeakReference<>(delegate);
4445
Path worldFolder = delegate.getWorldFolder().toPath();
4546

46-
var id = delegate.key();
47-
this.dimension = new Key(id.namespace(), id.value());
47+
this.dimension = switch (delegate.getEnvironment()) {
48+
case NORMAL -> DataPack.DIMENSION_OVERWORLD;
49+
case NETHER -> DataPack.DIMENSION_THE_NETHER;
50+
case THE_END -> DataPack.DIMENSION_THE_END;
51+
case CUSTOM -> {
52+
var id = delegate.key();
53+
yield new Key(id.namespace(), id.value());
54+
}
55+
};
4856

4957
// fix for hybrids
5058
Path dimensionFolder = MCAWorld.resolveDimensionFolder(worldFolder, dimension);
@@ -58,17 +66,18 @@ public BukkitWorld(World delegate) {
5866
this.worldFolder = worldFolder;
5967
}
6068

61-
/* Not supported by folia
6269
@Override
6370
public boolean persistWorldChanges() {
64-
World world = delegate.get();
65-
if (world != null) {
66-
world.save();
67-
return true;
71+
if (!FoliaSupport.IS_FOLIA) {
72+
World world = delegate.get();
73+
if (world != null) {
74+
world.save();
75+
return true;
76+
}
6877
}
78+
6979
return false;
7080
}
71-
*/
7281

7382
@Override
7483
public Path getWorldFolder() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package de.bluecolored.bluemap.bukkit;
2+
3+
import de.bluecolored.bluemap.core.logger.Logger;
4+
5+
public class FoliaSupport {
6+
7+
public static final boolean IS_FOLIA = isFolia();
8+
9+
private static boolean isFolia() {
10+
try {
11+
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
12+
Logger.global.logInfo("Folia detected, enabling folia-support mode.");
13+
return true;
14+
} catch (ClassNotFoundException e) {
15+
return false;
16+
}
17+
}
18+
19+
}

0 commit comments

Comments
 (0)