Fixes #4747: Server unload event was destroying grids before the associated nodes were saved, leading to player ids not being saved correctly when quitting the server.
This commit is contained in:
@@ -35,8 +35,8 @@ import com.google.common.base.Stopwatch;
|
|||||||
import com.google.common.collect.LinkedListMultimap;
|
import com.google.common.collect.LinkedListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@@ -73,7 +73,7 @@ public class TickHandler {
|
|||||||
ServerTickEvents.END_SERVER_TICK.register(this::onAfterServerTick);
|
ServerTickEvents.END_SERVER_TICK.register(this::onAfterServerTick);
|
||||||
ServerTickEvents.START_WORLD_TICK.register(this::onBeforeWorldTick);
|
ServerTickEvents.START_WORLD_TICK.register(this::onBeforeWorldTick);
|
||||||
ServerTickEvents.END_WORLD_TICK.register(this::onAfterWorldTick);
|
ServerTickEvents.END_WORLD_TICK.register(this::onAfterWorldTick);
|
||||||
ServerLifecycleEvents.SERVER_STOPPING.register(this::onServerStopping);
|
ServerWorldEvents.UNLOAD.register(this::onUnloadWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TickHandler instance() {
|
public static TickHandler instance() {
|
||||||
@@ -135,38 +135,13 @@ public class TickHandler {
|
|||||||
this.getRepo().clear();
|
this.getRepo().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME FABRIC It does not look like worlds can ever unload in Fabric.
|
public void onUnloadWorld(MinecraftServer server, ServerWorld world) {
|
||||||
// FIXME FABRIC public void unloadWorld(final WorldEvent.Unload ev) {
|
|
||||||
// FIXME FABRIC if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
|
||||||
// FIXME FABRIC {
|
|
||||||
// FIXME FABRIC final List<IGridNode> toDestroy = new ArrayList<>();
|
|
||||||
// FIXME FABRIC
|
|
||||||
// FIXME FABRIC this.getRepo().updateNetworks();
|
|
||||||
// FIXME FABRIC for (final Grid g : this.getRepo().networks) {
|
|
||||||
// FIXME FABRIC for (final IGridNode n : g.getNodes()) {
|
|
||||||
// FIXME FABRIC if (n.getWorld() == ev.getWorld()) {
|
|
||||||
// FIXME FABRIC toDestroy.add(n);
|
|
||||||
// FIXME FABRIC }
|
|
||||||
// FIXME FABRIC }
|
|
||||||
// FIXME FABRIC }
|
|
||||||
// FIXME FABRIC
|
|
||||||
// FIXME FABRIC for (final IGridNode n : toDestroy) {
|
|
||||||
// FIXME FABRIC n.destroy();
|
|
||||||
// FIXME FABRIC }
|
|
||||||
// FIXME FABRIC }
|
|
||||||
// FIXME FABRIC }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is primarily useful for an integrated server being stopped, and can be
|
|
||||||
* fully replaced by the event above once world unload events hit.
|
|
||||||
*/
|
|
||||||
private void onServerStopping(MinecraftServer server) {
|
|
||||||
final List<IGridNode> toDestroy = new ArrayList<>();
|
final List<IGridNode> toDestroy = new ArrayList<>();
|
||||||
this.server.updateNetworks();
|
|
||||||
for (final Grid g : this.server.networks) {
|
this.getRepo().updateNetworks();
|
||||||
|
for (final Grid g : this.getRepo().networks) {
|
||||||
for (final IGridNode n : g.getNodes()) {
|
for (final IGridNode n : g.getNodes()) {
|
||||||
WorldAccess nodeWorld = n.getWorld();
|
if (n.getWorld() == world) {
|
||||||
if (nodeWorld instanceof ServerWorld && ((ServerWorld) nodeWorld).getServer() == server) {
|
|
||||||
toDestroy.add(n);
|
toDestroy.add(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user