diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 5a03e56b..4015eb26 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -31,7 +31,7 @@ public class ServerConnection implements Server @Override public synchronized void disconnect(String reason) { - if ( ch.getHandle().isActive() ) + if ( !ch.isClosed() ) { ch.write( new PacketFFKick( reason ) ); ch.getHandle().eventLoop().schedule( new Runnable() diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index a3cf9c96..fc0d44e1 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -114,7 +114,7 @@ public final class UserConnection implements ProxiedPlayer @Deprecated public boolean isActive() { - return ch.getHandle().isActive(); + return !ch.isClosed(); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 385a6851..e004c7cf 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -262,10 +262,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public synchronized void disconnect(String reason) { - if ( ch.getHandle().isActive() ) + if ( !ch.isClosed() ) { ch.write( new PacketFFKick( reason ) ); - ch.getHandle().close(); + ch.close(); disconnected = true; } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java index 32a5d50e..055584ee 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java @@ -1,11 +1,14 @@ package net.md_5.bungee.netty; import io.netty.channel.Channel; +import lombok.Getter; public class ChannelWrapper { private final Channel ch; + @Getter + private volatile boolean closed; public ChannelWrapper(Channel ch) { @@ -14,7 +17,19 @@ public class ChannelWrapper public void write(Object packet) { - ch.write( packet, ch.voidPromise() ); + if ( !closed ) + { + ch.write( packet, ch.voidPromise() ); + } + } + + public void close() + { + if ( !closed ) + { + closed = true; + ch.close(); + } } public Channel getHandle()