Skip to content

Commit 75b562e

Browse files
committed
Generalize world-ids
1 parent 474c5e2 commit 75b562e

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private synchronized void loadMap(String id, MapConfig mapConfig) throws Configu
219219
"Check if the 'world' setting in the config-file for that map is correct, or remove the entire config-file if you don't want that map.");
220220
}
221221

222-
String worldId = MCAWorld.id(worldFolder, dimension);
222+
String worldId = World.id(worldFolder, dimension);
223223
World world = worlds.get(worldId);
224224
if (world == null) {
225225
try {

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import de.bluecolored.bluemap.common.addons.Addons;
3232
import de.bluecolored.bluemap.common.api.BlueMapAPIImpl;
3333
import de.bluecolored.bluemap.common.config.*;
34+
import de.bluecolored.bluemap.common.debug.StateDumper;
3435
import de.bluecolored.bluemap.common.live.LivePlayersDataSupplier;
3536
import de.bluecolored.bluemap.common.plugin.skins.PlayerSkinUpdater;
3637
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
@@ -40,7 +41,6 @@
4041
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
4142
import de.bluecolored.bluemap.common.web.*;
4243
import de.bluecolored.bluemap.common.web.http.HttpServer;
43-
import de.bluecolored.bluemap.common.debug.StateDumper;
4444
import de.bluecolored.bluemap.core.logger.Logger;
4545
import de.bluecolored.bluemap.core.map.BmMap;
4646
import de.bluecolored.bluemap.core.metrics.Metrics;
@@ -50,7 +50,6 @@
5050
import de.bluecolored.bluemap.core.util.FileHelper;
5151
import de.bluecolored.bluemap.core.util.Tristate;
5252
import de.bluecolored.bluemap.core.world.World;
53-
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
5453
import lombok.AccessLevel;
5554
import lombok.Getter;
5655
import org.jetbrains.annotations.Nullable;
@@ -639,7 +638,7 @@ public boolean checkPausedByPlayerCount() {
639638
}
640639

641640
public @Nullable World getWorld(ServerWorld serverWorld) {
642-
String id = MCAWorld.id(serverWorld.getWorldFolder(), serverWorld.getDimension());
641+
String id = World.id(serverWorld.getWorldFolder(), serverWorld.getDimension());
643642
return getBlueMap().getWorlds().get(id);
644643
}
645644

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/World.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
import com.flowpowered.math.vector.Vector2i;
2828
import com.flowpowered.math.vector.Vector3i;
2929
import de.bluecolored.bluemap.core.util.Grid;
30+
import de.bluecolored.bluemap.core.util.Key;
3031
import de.bluecolored.bluemap.core.util.WatchService;
3132

3233
import java.io.IOException;
34+
import java.nio.file.Path;
3335
import java.util.Collection;
3436
import java.util.function.Predicate;
3537

@@ -105,4 +107,17 @@ default void preloadRegionChunks(int x, int z) {
105107
*/
106108
void invalidateChunkCache(int x, int z);
107109

110+
/**
111+
* Generates a unique world-id based on a world-folder and a dimension
112+
*/
113+
static String id(Path worldFolder, Key dimension) {
114+
worldFolder = worldFolder.toAbsolutePath().normalize();
115+
116+
Path workingDir = Path.of("").toAbsolutePath().normalize();
117+
if (worldFolder.startsWith(workingDir))
118+
worldFolder = workingDir.relativize(worldFolder);
119+
120+
return worldFolder + "#" + dimension.getFormatted();
121+
}
122+
108123
}

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAWorld.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class MCAWorld implements World {
9494
.build(this::loadChunk);
9595

9696
private MCAWorld(Path worldFolder, Key dimension, DataPack dataPack, LevelData levelData) {
97-
this.id = id(worldFolder, dimension);
97+
this.id = World.id(worldFolder, dimension);
9898
this.worldFolder = worldFolder;
9999
this.dimension = dimension;
100100
this.dataPack = dataPack;
@@ -275,16 +275,6 @@ public static MCAWorld load(Path worldFolder, Key dimension, DataPack dataPack)
275275
return new MCAWorld(worldFolder, dimension, dataPack, levelData);
276276
}
277277

278-
public static String id(Path worldFolder, Key dimension) {
279-
worldFolder = worldFolder.toAbsolutePath().normalize();
280-
281-
Path workingDir = Path.of("").toAbsolutePath().normalize();
282-
if (worldFolder.startsWith(workingDir))
283-
worldFolder = workingDir.relativize(worldFolder);
284-
285-
return "MCA#" + worldFolder + "#" + dimension.getFormatted();
286-
}
287-
288278
public static Path resolveDimensionFolder(Path worldFolder, Key dimension) {
289279
if (DataPack.DIMENSION_OVERWORLD.equals(dimension)) return worldFolder;
290280
if (DataPack.DIMENSION_THE_NETHER.equals(dimension)) return worldFolder.resolve("DIM-1");

0 commit comments

Comments
 (0)