diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index 6f57fd2ba..0b8eadafd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -11,10 +11,7 @@ import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.netty.*; import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.*; import io.netty.util.ReferenceCountUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -104,6 +101,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { } } + public EventLoop eventLoop() { + return channel.eventLoop(); + } + public void write(Object msg) { if (channel.isActive()) { channel.writeAndFlush(msg, channel.voidPromise()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index ba16d0a6a..556605935 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -96,7 +96,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { if (pme.getResult().isAllowed()) { serverConn.getPlayer().getConnection().write(pm); } - }, serverConn.getConnection().getChannel().eventLoop()); + }, serverConn.getConnection().eventLoop()); } } else if (packet instanceof TabCompleteResponse) { playerHandler.handleTabCompleteResponse((TabCompleteResponse) packet); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 35b2b7efe..0fbdf3328 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -93,11 +93,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { server.getEventManager().fire(event) .thenAcceptAsync(pme -> { if (pme.getResult().equals(PlayerChatEvent.ChatResult.allowed())){ - player.getConnectedServer().getConnection().write(chat); + serverConnection.getConnection().write(chat); } else if (pme.getResult().isAllowed() && pme.getResult().getMessage().isPresent()){ - player.getConnectedServer().getConnection().write(Chat.createServerbound(pme.getResult().getMessage().get())); + serverConnection.getConnection().write(Chat.createServerbound(pme.getResult().getMessage().get())); } - }, player.getConnectedServer().getConnection().getChannel().eventLoop()); + }, serverConnection.getConnection().eventLoop()); } return; } @@ -290,7 +290,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { if (pme.getResult().isAllowed()) { player.getConnectedServer().getConnection().write(packet); } - }, player.getConnectedServer().getConnection().getChannel().eventLoop()); + }, player.getConnectedServer().getConnection().eventLoop()); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index b7a5f8654..40ad1b896 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -309,7 +309,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { // In case someone gets creative, assume we want to disconnect the player. connection.closeWith(Disconnect.create(friendlyReason)); } - }, connection.getChannel().eventLoop()); + }, connection.eventLoop()); } else { connection.closeWith(Disconnect.create(friendlyReason)); } @@ -463,7 +463,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { handleConnectionException(server, Disconnect.create(status.getReason().orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR))); break; } - }, connection.getChannel().eventLoop()); + }, connection.eventLoop()); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index 6ed3c805c..e50b006e6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -116,7 +116,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { .thenRunAsync(() -> { // The disconnect packet is the same as the server response one. connection.closeWith(LegacyDisconnect.fromPingResponse(LegacyPingResponse.from(event.getPing()))); - }, connection.getChannel().eventLoop()); + }, connection.eventLoop()); } else if (packet instanceof LegacyHandshake) { connection.closeWith(LegacyDisconnect.from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED))); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 116351ebb..b6455c8c8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -129,7 +129,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { profileResponse.getCode(), login.getUsername(), playerIp); inbound.close(); } - }, inbound.getChannel().eventLoop()) + }, inbound.eventLoop()) .exceptionally(exception -> { logger.error("Unable to enable encryption", exception); inbound.close(); @@ -167,7 +167,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } else { initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false); } - }, inbound.getChannel().eventLoop()); + }, inbound.eventLoop()); } private EncryptionRequest generateRequest() { @@ -214,7 +214,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } handleProxyLogin(player); - }, inbound.getChannel().eventLoop()); + }, inbound.eventLoop()); }); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index a8b0f3bd0..b34ee3bfb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -58,7 +58,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { StatusResponse response = new StatusResponse(); response.setStatus(VelocityServer.GSON.toJson(event.getPing())); connection.write(response); - }, connection.getChannel().eventLoop()); + }, connection.eventLoop()); } @Override