Fix errors when on vanilla server

This commit is contained in:
s809
2024-04-01 00:55:15 +05:00
parent ff7720a8d6
commit bdc4fa4477
2 changed files with 13 additions and 1 deletions
@@ -80,6 +80,11 @@ public class ClientNetworkState implements Closeable
private String[] f3Log()
{
if (!this.client.isActive())
{
return new String[]{"Waiting for connection info..."};
}
if (!this.client.isClosed())
{
return new String[]{
@@ -59,6 +59,8 @@ public class NettyClient extends NettyEventSource implements INettyConnection, A
EConnectionState.CLOSED
);
private final AtomicReference<EConnectionState> connectionState = new AtomicReference<>(EConnectionState.INITIAL);
/** Indicates whether the client is working. */
public boolean isActive() { return this.connectionState.get() != EConnectionState.INITIAL && !this.isClosed(); }
/** Indicates whether the client is closed(-ing) and should not be used. */
public boolean isClosed() { return closedStates.contains(this.connectionState.get()); }
@@ -188,6 +190,10 @@ public class NettyClient extends NettyEventSource implements INettyConnection, A
@Override
public ChannelHandlerContext getChannelContext()
{
if (this.channel == null)
{
return null;
}
return this.channel.pipeline().context(NettyMessageHandler.class);
}
@@ -200,7 +206,8 @@ public class NettyClient extends NettyEventSource implements INettyConnection, A
@Override
public void close()
{
if (this.connectionState.getAndSet(EConnectionState.CLOSED) == EConnectionState.CLOSED)
EConnectionState stateChangeResult = this.connectionState.getAndSet(EConnectionState.CLOSED);
if (stateChangeResult == EConnectionState.CLOSED || stateChangeResult == EConnectionState.INITIAL)
{
return;
}