fix potential exceptions after world shutdown

This commit is contained in:
James Seibel
2026-04-21 22:19:46 -05:00
parent 246c679a97
commit d61b601c14
7 changed files with 26 additions and 10 deletions
@@ -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;
}
@@ -211,7 +211,7 @@ public class SharedApi
}
// ignore updates if the world is read-only
if (DhApiWorldProxy.INSTANCE.getReadOnly())
if (DhApiWorldProxy.INSTANCE.tryGetReadOnly())
{
return;
}
@@ -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)
@@ -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;
}
@@ -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;
}
@@ -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";
}
@@ -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;
}
//================//