Skip to content

Commit

Permalink
Fix dynamic world management on servers with multiple instances (#276)
Browse files Browse the repository at this point in the history
This fixes the feature on servers like Hypixel, where you change sub-servers when switching lobbies.

Fixes #250
  • Loading branch information
KrisAphalon authored and Johni0702 committed Jun 17, 2024
1 parent dea7707 commit 6336732
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### 5.2.1-SNAPSHOT
- Fix "Dynamic World Management" not working when switching server without full reconnect (#250) (thanks to KrisAphalon!)

### 5.2.0
- Update to Minecraft 1.20.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public FakeChunkManager(ClientWorld world, ClientChunkManager clientChunkManager

if (config.isDynamicMultiWorld()) {
worlds = Worlds.getFor(storagePath);
worlds.startNewWorld();
storages.add(worlds::loadTag);

storage = null;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/de/johni0702/minecraft/bobby/Worlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ private Worlds(Path directory) {
}
}

public void startNewWorld() {
// When switching from one server to another, this function can be executed multiple times
// Without this early return, that would create multiple empty words,
// after which only the last one would be merged and the empty ones would stay in memory
if (worlds.get(currentWorldId).knownRegions.isEmpty()) {
return;
}

lock.writeLock().lock();
try {
currentWorldId = nextWorldId++;
worlds.put(currentWorldId, new World(currentWorldId, CURRENT_SAVE_VERSION));
} finally {
lock.writeLock().unlock();
}
}

public CompletableFuture<Optional<NbtCompound>> loadTag(ChunkPos chunkPos) {
RegionPos regionPos = RegionPos.from(chunkPos);
long regionCoord = regionPos.toLong();
Expand Down

0 comments on commit 6336732

Please sign in to comment.