From 32b9e723d1b146e29fc214bd9063399b3323ae3e Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 6 Nov 2024 07:08:17 -0600 Subject: [PATCH] Fix crashing after server shutdown in serverPlayerDisconnectEvent --- .../core/api/internal/ServerApi.java | 14 +++++++------- .../core/generation/WorldGenerationQueue.java | 2 +- .../AbstractFullDataNetworkRequestQueue.java | 2 +- .../core/world/DhApiWorldProxy.java | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ServerApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ServerApi.java index 4435b3ae6..d852c1504 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ServerApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ServerApi.java @@ -145,13 +145,13 @@ public class ServerApi public void serverPlayerJoinEvent(IServerPlayerWrapper player) { - if (DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) { return; } IDhServerWorld serverWorld = SharedApi.getIDhServerWorld(); - LOGGER.info("Player [${player.getName()}] joined."); + LOGGER.info("Player ["+player.getName()+"] joined."); if (serverWorld != null) { serverWorld.addPlayer(player); @@ -159,13 +159,13 @@ public class ServerApi } public void serverPlayerDisconnectEvent(IServerPlayerWrapper player) { - if (DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) { return; } IDhServerWorld serverWorld = SharedApi.getIDhServerWorld(); - LOGGER.info("Player [${player.getName()}] disconnected."); + LOGGER.info("Player ["+player.getName()+"] disconnected."); if (serverWorld != null) { serverWorld.removePlayer(player); @@ -173,13 +173,13 @@ public class ServerApi } public void serverPlayerLevelChangeEvent(IServerPlayerWrapper player, IServerLevelWrapper originLevel, IServerLevelWrapper destinationLevel) { - if (DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) { return; } IDhServerWorld serverWorld = SharedApi.getIDhServerWorld(); - LOGGER.info("Player [${player.getName()}] changed level: [${originLevel.getKeyedLevelDimensionName()}] -> [${destinationLevel.getKeyedLevelDimensionName()}]."); + LOGGER.info("Player ["+player.getName()+"] changed level: ["+originLevel.getKeyedLevelDimensionName()+"] -> ["+destinationLevel.getKeyedLevelDimensionName()+"]."); if (serverWorld != null) { serverWorld.changePlayerLevel(player, originLevel, destinationLevel); @@ -188,7 +188,7 @@ public class ServerApi public void pluginMessageReceived(IServerPlayerWrapper player, @NotNull AbstractNetworkMessage message) { - if (DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) { return; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java index d700ea058..c2510e5a0 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java @@ -190,7 +190,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb try { // loop until the generator is shutdown - while (!Thread.interrupted() && !DhApiWorldProxy.INSTANCE.getReadOnly()) + while (!Thread.interrupted() && DhApiWorldProxy.INSTANCE.worldLoaded() && !DhApiWorldProxy.INSTANCE.getReadOnly()) { this.generator.preGeneratorTaskStart(); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java b/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java index dfb9e9e62..2731a0b94 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java @@ -129,7 +129,7 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende public synchronized boolean tick(DhBlockPos2D targetPos) { - if (DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) { return false; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java index ce17bf93c..4f70b967f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java @@ -72,13 +72,13 @@ public class DhApiWorldProxy implements IDhApiWorldProxy public boolean worldLoaded() { return SharedApi.getAbstractDhWorld() != null; } @Override - public void setReadOnly(boolean readOnly) { this.setReadOnly(readOnly, true); } + public void setReadOnly(boolean readOnly) throws IllegalStateException { this.setReadOnly(readOnly, true); } /** * Not part of the public API. * Normal API users shouldn't be able to change the upcoming world state * this is only here so DH can revert the readonly value after the world is unloaded */ - public void setReadOnly(boolean readOnly, boolean throwIfWorldUnloaded) + public void setReadOnly(boolean readOnly, boolean throwIfWorldUnloaded) throws IllegalStateException { if (throwIfWorldUnloaded && SharedApi.getAbstractDhWorld() == null) { @@ -102,7 +102,7 @@ public class DhApiWorldProxy implements IDhApiWorldProxy } @Override - public boolean getReadOnly() + public boolean getReadOnly() throws IllegalStateException { if (SharedApi.getAbstractDhWorld() == null) { @@ -120,7 +120,7 @@ public class DhApiWorldProxy implements IDhApiWorldProxy //================// @Override - public IDhApiLevelWrapper getSinglePlayerLevel() + public IDhApiLevelWrapper getSinglePlayerLevel() throws IllegalStateException { if (SharedApi.getAbstractDhWorld() == null) { @@ -138,7 +138,7 @@ public class DhApiWorldProxy implements IDhApiWorldProxy @Override - public Iterable getAllLoadedLevelWrappers() + public Iterable getAllLoadedLevelWrappers() throws IllegalStateException { AbstractDhWorld world = SharedApi.getAbstractDhWorld(); if (world == null) @@ -155,7 +155,7 @@ public class DhApiWorldProxy implements IDhApiWorldProxy } @Override - public Iterable getAllLoadedLevelsForDimensionType(IDhApiDimensionTypeWrapper dimensionTypeWrapper) + public Iterable getAllLoadedLevelsForDimensionType(IDhApiDimensionTypeWrapper dimensionTypeWrapper) throws IllegalStateException { AbstractDhWorld world = SharedApi.getAbstractDhWorld(); if (world == null) @@ -176,7 +176,7 @@ public class DhApiWorldProxy implements IDhApiWorldProxy } @Override - public Iterable getAllLoadedLevelsWithDimensionNameLike(String dimensionName) + public Iterable getAllLoadedLevelsWithDimensionNameLike(String dimensionName) throws IllegalStateException { AbstractDhWorld world = SharedApi.getAbstractDhWorld(); if (world == null)