mirror of
https://github.com/Minestom/Minestom.git
synced 2024-10-06 10:27:33 +02:00
Cleanup
This commit is contained in:
parent
e730f60c0a
commit
6f9a92ac76
@ -72,16 +72,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
public void update() {
|
||||
// Flush
|
||||
if (channel.isActive()) {
|
||||
|
||||
// Write all waiting packets
|
||||
synchronized (tickBuffer) {
|
||||
final ByteBuf copy = tickBuffer.copy();
|
||||
this.channel.write(new FramedPacket(copy)).addListener(future -> {
|
||||
copy.release();
|
||||
});
|
||||
tickBuffer.clear();
|
||||
}
|
||||
|
||||
writeWaitingPackets();
|
||||
this.channel.flush();
|
||||
}
|
||||
// Network stats
|
||||
@ -183,20 +174,17 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
tickBuffer.writeBytes(buffer);
|
||||
}
|
||||
return;
|
||||
} else if (message instanceof ByteBuf) {
|
||||
synchronized (tickBuffer) {
|
||||
tickBuffer.writeBytes((ByteBuf) message);
|
||||
}
|
||||
|
||||
ChannelFuture channelFuture = channel.write(message);
|
||||
|
||||
if (MinecraftServer.shouldProcessNettyErrors()) {
|
||||
channelFuture.addListener(future -> {
|
||||
if (!future.isSuccess() && channel.isActive()) {
|
||||
MinecraftServer.getExceptionManager().handleException(future.cause());
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
throw new UnsupportedOperationException("type " + message.getClass() + " is not supported");
|
||||
}
|
||||
|
||||
public void writeAndFlush(@NotNull Object message) {
|
||||
writeWaitingPackets();
|
||||
ChannelFuture channelFuture = channel.writeAndFlush(message);
|
||||
|
||||
if (MinecraftServer.shouldProcessNettyErrors()) {
|
||||
@ -208,6 +196,27 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeWaitingPackets() {
|
||||
synchronized (tickBuffer) {
|
||||
final ByteBuf copy = tickBuffer.copy();
|
||||
|
||||
ChannelFuture channelFuture = channel.write(new FramedPacket(copy)).addListener(future -> {
|
||||
copy.release();
|
||||
});
|
||||
|
||||
// Netty debug
|
||||
if (MinecraftServer.shouldProcessNettyErrors()) {
|
||||
channelFuture.addListener(future -> {
|
||||
if (!future.isSuccess() && channel.isActive()) {
|
||||
MinecraftServer.getExceptionManager().handleException(future.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
tickBuffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SocketAddress getRemoteAddress() {
|
||||
|
Loading…
Reference in New Issue
Block a user