Johni0702 / bobby

GNU General Public License v3.0
216 stars 57 forks source link

Fix dynamic world management on servers with multiple instances #276

Closed KrisAphalon closed 5 months ago

KrisAphalon commented 5 months ago

This fixes the feature on servers like Hypixel, where you change sub-servers when switching lobbies.

This (I'm pretty sure) fixes https://github.com/Johni0702/bobby/issues/250. I tested it only on Hypixel, but it works there.

First of all, I'm not writing Java on day-to-day, so the code might not be the best. However, I was able to trace what changed between the wip version that worked on Hypixel and the current version and then apply fixes. There might be a better way to implement this fix, but it does fix the issue (at least in my testing).

The issue with Hypixel, or other big minigame servers, is that when you connect to the main IP, you're placed in a smaller server. Then, when you change the lobby, for example, when choosing a minigame, you're transported to a different server. This doesn't trigger any creation of a new map, so you still see chunks from the main lobby while you were in a minigame.

To fix this, I re-added the startNewWorld function, which creates a world each time a world is loaded. The world should then be quickly merged with an existing one, if there is one in cache.

The last problem I saw was that, for some reason, when changing servers on Hypixel the newly added startNewWorld was triggering 3 times. I think that's because to get a fancy nether portal animation on changing servers, the server sends you first to overworld, then to nether and then to the final map. That created a lot of empty maps with 0 chunks when I was playing, and those will never get merged. To fix that, I added an early return, so if the world for the current id is empty, we can just use it instead of creating a new one.

Julienraptor01 commented 5 months ago

i compiled it, tested it and it seems to entirely fix the issue where on hypixel it would mess up and mix worlds

Johni0702 commented 5 months ago

Oh, yeah, that makes sense. Thank you very much for looking into it!

I'm honestly not sure why I removed startNewWorld, I must have thought that it's redundant given load already creates a new world on each load (but didn't realize that Worlds doesn't get re-loaded unless you reconnect), and thereafter I've only ever tested it by reconnecting and never by actually switching servers while connected.

Merged in 6336732f with one minor change (knownRegions instead of regions because the former is guaranteed to be loaded for all worlds, the latter might not yet be; practically right now it will be too, but in the future that might change) and changelog.