From 6cd0a6b148edd59a01f8911c3b6f9e0550cb9661 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 29 Sep 2018 01:38:30 -0400 Subject: [PATCH] Introduce Channel#eventLoop() shorthand This is such a common call that it makes a lot of sense to go ahead and expose this. --- .../proxy/connection/MinecraftConnection.java | 9 +++++---- .../connection/backend/BackendPlaySessionHandler.java | 2 +- .../connection/client/ClientPlaySessionHandler.java | 8 ++++---- .../proxy/connection/client/ConnectedPlayer.java | 4 ++-- .../proxy/connection/client/HandshakeSessionHandler.java | 2 +- .../proxy/connection/client/LoginSessionHandler.java | 6 +++--- .../proxy/connection/client/StatusSessionHandler.java | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) 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