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 8d7c5dd61..bbfa2536e 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 @@ -122,7 +122,7 @@ public class ServerApi public void serverPlayerJoinEvent(IServerPlayerWrapper player) { - if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { return; } @@ -136,7 +136,7 @@ public class ServerApi } public void serverPlayerDisconnectEvent(IServerPlayerWrapper player) { - if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { return; } @@ -150,7 +150,7 @@ public class ServerApi } public void serverPlayerLevelChangeEvent(IServerPlayerWrapper player, IServerLevelWrapper originLevel, IServerLevelWrapper destinationLevel) { - if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { return; } @@ -170,7 +170,7 @@ public class ServerApi */ public void pluginMessageReceived(IServerPlayerWrapper player, @NotNull AbstractNetworkMessage message) { - if (DhApiWorldProxy.INSTANCE.worldLoaded() && DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { return; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index de884c938..ee131b797 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -211,7 +211,7 @@ public class SharedApi } // ignore updates if the world is read-only - if (DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { return; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/LodRequestModule.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/LodRequestModule.java index 2c99a6497..c55a2cc4f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/LodRequestModule.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/LodRequestModule.java @@ -104,7 +104,7 @@ public class LodRequestModule implements Closeable boolean shouldDoWorldGen = this.onWorldGenCompleteListener.shouldDoWorldGen(); // if the world is read only don't generate anything - shouldDoWorldGen &= !DhApiWorldProxy.INSTANCE.getReadOnly(); + shouldDoWorldGen &= !DhApiWorldProxy.INSTANCE.tryGetReadOnly(); // don't generate chunks for client levels that aren't being rendered // (this can happen when moving between dimensions) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/WorldGenerationQueue.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/WorldGenerationQueue.java index b3985e328..4952e203e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/WorldGenerationQueue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/queues/WorldGenerationQueue.java @@ -202,7 +202,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb private synchronized void tryQueueNewWorldGenRequestsAsync() { if (!DhApiWorldProxy.INSTANCE.worldLoaded() - || DhApiWorldProxy.INSTANCE.getReadOnly()) + || DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { return; } 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 a85d28616..d2dca5550 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 @@ -151,8 +151,7 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende public synchronized boolean tick(DhBlockPos2D targetPos) { - if (DhApiWorldProxy.INSTANCE.worldLoaded() - && DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { return false; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/AbstractDhWorld.java b/core/src/main/java/com/seibel/distanthorizons/core/world/AbstractDhWorld.java index 49d17ce64..00256f0d4 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/AbstractDhWorld.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/AbstractDhWorld.java @@ -64,7 +64,7 @@ public abstract class AbstractDhWorld implements IDhWorld, Closeable String levelCountStr = F3Screen.NUMBER_FORMAT.format(this.getLoadedLevelCount()); String readOnlyStr = ""; - if (DhApiWorldProxy.INSTANCE.getReadOnly()) + if (DhApiWorldProxy.INSTANCE.tryGetReadOnly()) { readOnlyStr += " - ReadOnly"; } 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 53c46b14b..1d9595820 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 @@ -113,6 +113,23 @@ public class DhApiWorldProxy implements IDhApiWorldProxy return this.isReadOnly; } + /** + * Returns false if no world is loaded. + * Can be used in places where the world state might be a bit more questionable + * without having to worry about the {@link IllegalStateException} thrown by + * {@link DhApiWorldProxy#getReadOnly()} + */ + public boolean tryGetReadOnly() + { + if (SharedApi.getAbstractDhWorld() == null) + { + // no world is loaded, use the default value for the next world + return false; + } + + return this.isReadOnly; + } + //================//