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 acf7fe5cc..3456f0a82 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -19,7 +19,7 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.connection.client.LoginSessionHandler; import com.velocitypowered.proxy.connection.client.StatusSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder; @@ -27,6 +27,7 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; +import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; @@ -116,10 +117,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { return; } - if (msg instanceof MinecraftPacket) { - MinecraftPacket pkt = (MinecraftPacket) msg; + if (msg instanceof Packet) { + Packet pkt = (Packet) msg; if (!pkt.handle(sessionHandler)) { - sessionHandler.handleGeneric((MinecraftPacket) msg); + sessionHandler.handleGeneric((Packet) msg); } } else if (msg instanceof HAProxyMessage) { HAProxyMessage proxyMessage = (HAProxyMessage) msg; @@ -368,7 +369,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { /** * Sets the compression threshold on the connection. You are responsible for sending - * {@link com.velocitypowered.proxy.protocol.packet.SetCompression} beforehand. + * {@link SetCompressionPacket} beforehand. * @param threshold the compression threshold to use */ public void setCompressionThreshold(int threshold) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java index 297e5f884..71b16d997 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java @@ -1,35 +1,35 @@ package com.velocitypowered.proxy.connection; -import com.velocitypowered.proxy.protocol.MinecraftPacket; -import com.velocitypowered.proxy.protocol.packet.AvailableCommands; -import com.velocitypowered.proxy.protocol.packet.BossBar; -import com.velocitypowered.proxy.protocol.packet.Chat; -import com.velocitypowered.proxy.protocol.packet.ClientSettings; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; -import com.velocitypowered.proxy.protocol.packet.EncryptionResponse; -import com.velocitypowered.proxy.protocol.packet.Handshake; -import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; -import com.velocitypowered.proxy.protocol.packet.JoinGame; -import com.velocitypowered.proxy.protocol.packet.KeepAlive; -import com.velocitypowered.proxy.protocol.packet.LegacyHandshake; -import com.velocitypowered.proxy.protocol.packet.LegacyPing; -import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage; -import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse; -import com.velocitypowered.proxy.protocol.packet.PlayerListItem; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; -import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest; -import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse; -import com.velocitypowered.proxy.protocol.packet.Respawn; -import com.velocitypowered.proxy.protocol.packet.ServerLogin; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; -import com.velocitypowered.proxy.protocol.packet.SetCompression; -import com.velocitypowered.proxy.protocol.packet.StatusPing; -import com.velocitypowered.proxy.protocol.packet.StatusRequest; -import com.velocitypowered.proxy.protocol.packet.StatusResponse; -import com.velocitypowered.proxy.protocol.packet.TabCompleteRequest; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket; +import com.velocitypowered.proxy.protocol.packet.BossBarPacket; +import com.velocitypowered.proxy.protocol.packet.ChatPacket; +import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; +import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket; +import com.velocitypowered.proxy.protocol.packet.HandshakePacket; +import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket; +import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; +import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; +import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket; +import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket; +import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket; +import com.velocitypowered.proxy.protocol.packet.RespawnPacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; +import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; +import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; +import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; +import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; import com.velocitypowered.proxy.protocol.packet.TitlePacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; import io.netty.buffer.ByteBuf; public interface MinecraftSessionHandler { @@ -38,7 +38,7 @@ public interface MinecraftSessionHandler { return false; } - default void handleGeneric(MinecraftPacket packet) { + default void handleGeneric(Packet packet) { } @@ -74,103 +74,103 @@ public interface MinecraftSessionHandler { } - default boolean handle(AvailableCommands commands) { + default boolean handle(AvailableCommandsPacket commands) { return false; } - default boolean handle(BossBar packet) { + default boolean handle(BossBarPacket packet) { return false; } - default boolean handle(Chat packet) { + default boolean handle(ChatPacket packet) { return false; } - default boolean handle(ClientSettings packet) { + default boolean handle(ClientSettingsPacket packet) { return false; } - default boolean handle(Disconnect packet) { + default boolean handle(DisconnectPacket packet) { return false; } - default boolean handle(EncryptionRequest packet) { + default boolean handle(EncryptionRequestPacket packet) { return false; } - default boolean handle(EncryptionResponse packet) { + default boolean handle(EncryptionResponsePacket packet) { return false; } - default boolean handle(Handshake packet) { + default boolean handle(HandshakePacket packet) { return false; } - default boolean handle(HeaderAndFooter packet) { + default boolean handle(HeaderAndFooterPacket packet) { return false; } - default boolean handle(JoinGame packet) { + default boolean handle(JoinGamePacket packet) { return false; } - default boolean handle(KeepAlive packet) { + default boolean handle(KeepAlivePacket packet) { return false; } - default boolean handle(LegacyHandshake packet) { + default boolean handle(LegacyHandshakePacket packet) { return false; } - default boolean handle(LegacyPing packet) { + default boolean handle(LegacyPingPacket packet) { return false; } - default boolean handle(LoginPluginMessage packet) { + default boolean handle(LoginPluginMessagePacket packet) { return false; } - default boolean handle(LoginPluginResponse packet) { + default boolean handle(LoginPluginResponsePacket packet) { return false; } - default boolean handle(PluginMessage packet) { + default boolean handle(PluginMessagePacket packet) { return false; } - default boolean handle(Respawn packet) { + default boolean handle(RespawnPacket packet) { return false; } - default boolean handle(ServerLogin packet) { + default boolean handle(ServerLoginPacket packet) { return false; } - default boolean handle(ServerLoginSuccess packet) { + default boolean handle(ServerLoginSuccessPacket packet) { return false; } - default boolean handle(SetCompression packet) { + default boolean handle(SetCompressionPacket packet) { return false; } - default boolean handle(StatusPing packet) { + default boolean handle(StatusPingPacket packet) { return false; } - default boolean handle(StatusRequest packet) { + default boolean handle(StatusRequestPacket packet) { return false; } - default boolean handle(StatusResponse packet) { + default boolean handle(StatusResponsePacket packet) { return false; } - default boolean handle(TabCompleteRequest packet) { + default boolean handle(TabCompleteRequestPacket packet) { return false; } - default boolean handle(TabCompleteResponse packet) { + default boolean handle(TabCompleteResponsePacket packet) { return false; } @@ -178,15 +178,15 @@ public interface MinecraftSessionHandler { return false; } - default boolean handle(PlayerListItem packet) { + default boolean handle(PlayerListItemPacket packet) { return false; } - default boolean handle(ResourcePackRequest packet) { + default boolean handle(ResourcePackRequestPacket packet) { return false; } - default boolean handle(ResourcePackResponse packet) { + default boolean handle(ResourcePackResponsePacket packet) { return false; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java index f7fe7aca7..216190fec 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhase.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.backend; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; /** * Provides connection phase specific actions. @@ -21,7 +21,7 @@ public interface BackendConnectionPhase { */ default boolean handle(VelocityServerConnection server, ConnectedPlayer player, - PluginMessage message) { + PluginMessagePacket message) { return false; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java index 09d17053d..d185c0f48 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendConnectionPhases.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.backend; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; /** * Contains Vanilla {@link BackendConnectionPhase}s. @@ -29,7 +29,7 @@ public final class BackendConnectionPhases { @Override public boolean handle(VelocityServerConnection serverConn, ConnectedPlayer player, - PluginMessage message) { + PluginMessagePacket message) { // The connection may be legacy forge. If so, the Forge handler will deal with this // for us. Otherwise, we have nothing to do. return LegacyForgeHandshakeBackendPhase.NOT_STARTED.handle(serverConn, player, message); 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 abd1f7b91..81cec86e1 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 @@ -16,14 +16,14 @@ import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler; import com.velocitypowered.proxy.connection.util.ConnectionMessages; -import com.velocitypowered.proxy.protocol.MinecraftPacket; -import com.velocitypowered.proxy.protocol.packet.AvailableCommands; -import com.velocitypowered.proxy.protocol.packet.BossBar; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.KeepAlive; -import com.velocitypowered.proxy.protocol.packet.PlayerListItem; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket; +import com.velocitypowered.proxy.protocol.packet.BossBarPacket; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; +import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; @@ -79,30 +79,30 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(KeepAlive packet) { + public boolean handle(KeepAlivePacket packet) { serverConn.setLastPingId(packet.getRandomId()); return false; // forwards on } @Override - public boolean handle(Disconnect packet) { + public boolean handle(DisconnectPacket packet) { serverConn.disconnect(); serverConn.getPlayer().handleConnectionException(serverConn.getServer(), packet, true); return true; } @Override - public boolean handle(BossBar packet) { - if (packet.getAction() == BossBar.ADD) { + public boolean handle(BossBarPacket packet) { + if (packet.getAction() == BossBarPacket.ADD) { playerSessionHandler.getServerBossBars().add(packet.getUuid()); - } else if (packet.getAction() == BossBar.REMOVE) { + } else if (packet.getAction() == BossBarPacket.REMOVE) { playerSessionHandler.getServerBossBars().remove(packet.getUuid()); } return false; // forward } @Override - public boolean handle(PluginMessage packet) { + public boolean handle(PluginMessagePacket packet) { if (bungeecordMessageResponder.process(packet)) { return true; } @@ -123,8 +123,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } if (PluginMessageUtil.isMcBrand(packet)) { - PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion(), - playerConnection.getProtocolVersion()); + PluginMessagePacket rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, + server.getVersion(), playerConnection.getProtocolVersion()); playerConnection.write(rewritten); return true; } @@ -145,7 +145,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { server.getEventManager().fire(event) .thenAcceptAsync(pme -> { if (pme.getResult().isAllowed() && !playerConnection.isClosed()) { - PluginMessage copied = new PluginMessage(packet.getChannel(), + PluginMessagePacket copied = new PluginMessagePacket(packet.getChannel(), Unpooled.wrappedBuffer(copy)); playerConnection.write(copied); } @@ -158,19 +158,19 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(TabCompleteResponse packet) { + public boolean handle(TabCompleteResponsePacket packet) { playerSessionHandler.handleTabCompleteResponse(packet); return true; } @Override - public boolean handle(PlayerListItem packet) { + public boolean handle(PlayerListItemPacket packet) { serverConn.getPlayer().getTabList().processBackendPacket(packet); return false; //Forward packet to player } @Override - public boolean handle(AvailableCommands commands) { + public boolean handle(AvailableCommandsPacket commands) { RootCommandNode rootNode = commands.getRootNode(); if (server.getConfiguration().isAnnounceProxyCommands()) { // Inject commands from the proxy. @@ -243,9 +243,9 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } @Override - public void handleGeneric(MinecraftPacket packet) { - if (packet instanceof PluginMessage) { - ((PluginMessage) packet).retain(); + public void handleGeneric(Packet packet) { + if (packet instanceof PluginMessagePacket) { + ((PluginMessagePacket) packet).retain(); } playerConnection.delayedWrite(packet); } @@ -277,7 +277,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { if (!serverConn.isGracefulDisconnect() && !exceptionTriggered) { if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) { serverConn.getPlayer().handleConnectionException(serverConn.getServer(), - Disconnect.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, + DisconnectPacket.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, ProtocolVersion.MINECRAFT_1_16), true); } else { serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java index 6c5602954..09a48a984 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java @@ -9,7 +9,7 @@ import com.velocitypowered.api.util.UuidUtils; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; import com.velocitypowered.proxy.protocol.util.ByteBufDataInput; import com.velocitypowered.proxy.protocol.util.ByteBufDataOutput; import com.velocitypowered.proxy.server.VelocityRegisteredServer; @@ -45,7 +45,7 @@ public class BungeeCordMessageResponder { this.player = player; } - public static boolean isBungeeCordMessage(PluginMessage message) { + public static boolean isBungeeCordMessage(PluginMessagePacket message) { return MODERN_CHANNEL.getId().equals(message.getChannel()) || LEGACY_CHANNEL.getId() .equals(message.getChannel()); } @@ -312,7 +312,7 @@ public class BungeeCordMessageResponder { MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected(); String chan = getBungeeCordChannel(serverConnection.getProtocolVersion()); - PluginMessage msg = null; + PluginMessagePacket msg = null; boolean released = false; try { @@ -322,7 +322,7 @@ public class BungeeCordMessageResponder { } MinecraftConnection serverConn = vsc.ensureConnected(); - msg = new PluginMessage(chan, buf); + msg = new PluginMessagePacket(chan, buf); serverConn.write(msg); released = true; } finally { @@ -332,7 +332,7 @@ public class BungeeCordMessageResponder { } } - boolean process(PluginMessage message) { + boolean process(PluginMessagePacket message) { if (!proxy.getConfiguration().isBungeePluginChannelEnabled()) { return false; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index 4dfdf9291..7f0032922 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -11,12 +11,12 @@ import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; -import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage; -import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; -import com.velocitypowered.proxy.protocol.packet.SetCompression; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; +import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; +import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; import com.velocitypowered.proxy.util.except.QuietRuntimeException; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -49,12 +49,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(EncryptionRequest packet) { + public boolean handle(EncryptionRequestPacket packet) { throw new IllegalStateException("Backend server is online-mode!"); } @Override - public boolean handle(LoginPluginMessage packet) { + public boolean handle(LoginPluginMessagePacket packet) { MinecraftConnection mc = serverConn.ensureConnected(); VelocityConfiguration configuration = server.getConfiguration(); if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet @@ -62,31 +62,32 @@ public class LoginSessionHandler implements MinecraftSessionHandler { ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(), cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()), serverConn.getPlayer().getGameProfile()); - LoginPluginResponse response = new LoginPluginResponse(packet.getId(), true, forwardingData); + LoginPluginResponsePacket response = new LoginPluginResponsePacket(packet.getId(), true, + forwardingData); mc.write(response); informationForwarded = true; } else { // Don't understand - mc.write(new LoginPluginResponse(packet.getId(), false, Unpooled.EMPTY_BUFFER)); + mc.write(new LoginPluginResponsePacket(packet.getId(), false, Unpooled.EMPTY_BUFFER)); } return true; } @Override - public boolean handle(Disconnect packet) { + public boolean handle(DisconnectPacket packet) { resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); serverConn.disconnect(); return true; } @Override - public boolean handle(SetCompression packet) { + public boolean handle(SetCompressionPacket packet) { serverConn.ensureConnected().setCompressionThreshold(packet.getThreshold()); return true; } @Override - public boolean handle(ServerLoginSuccess packet) { + public boolean handle(ServerLoginSuccessPacket packet) { if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) { resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index ff3f56026..301fd19f2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -14,10 +14,10 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.JoinGame; -import com.velocitypowered.proxy.protocol.packet.KeepAlive; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; +import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import java.io.IOException; import java.util.concurrent.CompletableFuture; @@ -60,13 +60,13 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(KeepAlive packet) { + public boolean handle(KeepAlivePacket packet) { serverConn.ensureConnected().write(packet); return true; } @Override - public boolean handle(JoinGame packet) { + public boolean handle(JoinGamePacket packet) { MinecraftConnection smc = serverConn.ensureConnected(); VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); @@ -132,7 +132,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(Disconnect packet) { + public boolean handle(DisconnectPacket packet) { final MinecraftConnection connection = serverConn.ensureConnected(); serverConn.disconnect(); @@ -150,7 +150,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(PluginMessage packet) { + public boolean handle(PluginMessagePacket packet) { if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected() .getProtocolVersion(), packet)) { return true; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 092b68048..5ae3eb769 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -21,9 +21,10 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.Handshake; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; -import com.velocitypowered.proxy.protocol.packet.ServerLogin; +import com.velocitypowered.proxy.protocol.packet.HandshakePacket; +import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -142,7 +143,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, // Initiate the handshake. ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); - Handshake handshake = new Handshake(); + HandshakePacket handshake = new HandshakePacket(); handshake.setNextStatus(StateRegistry.LOGIN_ID); handshake.setProtocolVersion(protocolVersion); if (forwardingMode == PlayerInfoForwarding.LEGACY) { @@ -164,7 +165,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, mc.setProtocolVersion(protocolVersion); mc.setState(StateRegistry.LOGIN); - mc.delayedWrite(new ServerLogin(proxyPlayer.getUsername())); + mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername())); mc.flush(); } @@ -233,7 +234,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, MinecraftConnection mc = ensureConnected(); - PluginMessage message = new PluginMessage(identifier.getId(), data); + PluginMessagePacket message = new PluginMessagePacket(identifier.getId(), data); mc.write(message); return true; } @@ -307,7 +308,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } /** - * Gets whether the {@link com.velocitypowered.proxy.protocol.packet.JoinGame} + * Gets whether the {@link JoinGamePacket} * packet has been sent by this server. * * @return Whether the join has been completed. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java index ba45251a7..75ccabf8f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConnectionPhase.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.client; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeClientPhase; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; /** * Provides connection phase specific actions. @@ -22,7 +22,7 @@ public interface ClientConnectionPhase { * @return true if handled, false otherwise. */ default boolean handle(ConnectedPlayer player, - PluginMessage message, + PluginMessagePacket message, VelocityServerConnection server) { return false; } 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 0423d6fe6..761a78457 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 @@ -19,19 +19,19 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.BossBar; -import com.velocitypowered.proxy.protocol.packet.Chat; -import com.velocitypowered.proxy.protocol.packet.ClientSettings; -import com.velocitypowered.proxy.protocol.packet.JoinGame; -import com.velocitypowered.proxy.protocol.packet.KeepAlive; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; -import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse; -import com.velocitypowered.proxy.protocol.packet.Respawn; -import com.velocitypowered.proxy.protocol.packet.TabCompleteRequest; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse.Offer; +import com.velocitypowered.proxy.protocol.packet.BossBarPacket; +import com.velocitypowered.proxy.protocol.packet.ChatPacket; +import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; +import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; +import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket; +import com.velocitypowered.proxy.protocol.packet.RespawnPacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket.Offer; import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import io.netty.buffer.ByteBuf; @@ -64,9 +64,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { private final ConnectedPlayer player; private boolean spawned = false; private final List serverBossBars = new ArrayList<>(); - private final Queue loginPluginMessages = new ArrayDeque<>(); + private final Queue loginPluginMessages = new ArrayDeque<>(); private final VelocityServer server; - private @Nullable TabCompleteRequest outstandingTabComplete; + private @Nullable TabCompleteRequestPacket outstandingTabComplete; /** * Constructs a client play session handler. @@ -83,7 +83,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { Collection channels = server.getChannelRegistrar().getChannelsForProtocol(player .getProtocolVersion()); if (!channels.isEmpty()) { - PluginMessage register = constructChannelsPacket(player.getProtocolVersion(), channels); + PluginMessagePacket register = constructChannelsPacket(player.getProtocolVersion(), channels); player.getConnection().write(register); player.getKnownChannels().addAll(channels); } @@ -91,13 +91,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public void deactivated() { - for (PluginMessage message : loginPluginMessages) { + for (PluginMessagePacket message : loginPluginMessages) { ReferenceCountUtil.release(message); } } @Override - public boolean handle(KeepAlive packet) { + public boolean handle(KeepAlivePacket packet) { VelocityServerConnection serverConnection = player.getConnectedServer(); if (serverConnection != null && packet.getRandomId() == serverConnection.getLastPingId()) { MinecraftConnection smc = serverConnection.getConnection(); @@ -111,13 +111,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(ClientSettings packet) { + public boolean handle(ClientSettingsPacket packet) { player.setPlayerSettings(packet); return false; // will forward onto the server } @Override - public boolean handle(Chat packet) { + public boolean handle(ChatPacket packet) { VelocityServerConnection serverConnection = player.getConnectedServer(); if (serverConnection == null) { return true; @@ -154,7 +154,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { if (chatResult.isAllowed()) { Optional eventMsg = pme.getResult().getMessage(); if (eventMsg.isPresent()) { - smc.write(Chat.createServerbound(eventMsg.get())); + smc.write(ChatPacket.createServerbound(eventMsg.get())); } else { smc.write(packet); } @@ -169,7 +169,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(TabCompleteRequest packet) { + public boolean handle(TabCompleteRequestPacket packet) { boolean isCommand = !packet.isAssumeCommand() && packet.getCommand().startsWith("/"); if (isCommand) { @@ -180,7 +180,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(PluginMessage packet) { + public boolean handle(PluginMessagePacket packet) { VelocityServerConnection serverConn = player.getConnectedServer(); MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null; if (serverConn != null && backendConn != null) { @@ -229,7 +229,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { ByteBufUtil.getBytes(packet.content())); server.getEventManager().fire(event).thenAcceptAsync(pme -> { if (pme.getResult().isAllowed()) { - PluginMessage message = new PluginMessage(packet.getChannel(), + PluginMessagePacket message = new PluginMessagePacket(packet.getChannel(), Unpooled.wrappedBuffer(copy)); backendConn.write(message); } @@ -249,14 +249,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(ResourcePackResponse packet) { + public boolean handle(ResourcePackResponsePacket packet) { server.getEventManager().fireAndForget(new PlayerResourcePackStatusEvent(player, packet.getStatus())); return false; } @Override - public void handleGeneric(MinecraftPacket packet) { + public void handleGeneric(Packet packet) { VelocityServerConnection serverConnection = player.getConnectedServer(); if (serverConnection == null) { // No server connection yet, probably transitioning. @@ -265,8 +265,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { MinecraftConnection smc = serverConnection.getConnection(); if (smc != null && serverConnection.getPhase().consideredComplete()) { - if (packet instanceof PluginMessage) { - ((PluginMessage) packet).retain(); + if (packet instanceof PluginMessagePacket) { + ((PluginMessagePacket) packet).retain(); } smc.write(packet); } @@ -320,7 +320,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { * @param joinGame the join game packet * @param destination the new server we are connecting to */ - public void handleBackendJoinGame(JoinGame joinGame, VelocityServerConnection destination) { + public void handleBackendJoinGame(JoinGamePacket joinGame, VelocityServerConnection destination) { final MinecraftConnection serverMc = destination.ensureConnected(); if (!spawned) { @@ -345,9 +345,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to // track them. for (UUID serverBossBar : serverBossBars) { - BossBar deletePacket = new BossBar(); + BossBarPacket deletePacket = new BossBarPacket(); deletePacket.setUuid(serverBossBar); - deletePacket.setAction(BossBar.REMOVE); + deletePacket.setAction(BossBarPacket.REMOVE); player.getConnection().delayedWrite(deletePacket); } serverBossBars.clear(); @@ -359,7 +359,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } // If we had plugin messages queued during login/FML handshake, send them now. - PluginMessage pm; + PluginMessagePacket pm; while ((pm = loginPluginMessages.poll()) != null) { serverMc.delayedWrite(pm); } @@ -376,7 +376,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { destination.completeJoin(); } - private void doFastClientServerSwitch(JoinGame joinGame) { + private void doFastClientServerSwitch(JoinGamePacket joinGame) { // In order to handle switching to another server, you will need to send two packets: // // - The join game packet from the backend server, with a different dimension @@ -395,13 +395,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.getConnection().delayedWrite(joinGame); player.getConnection().delayedWrite( - new Respawn(sentOldDim, joinGame.getPartialHashedSeed(), + new RespawnPacket(sentOldDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), joinGame.getCurrentDimensionData())); } - private void doSafeClientServerSwitch(JoinGame joinGame) { + private void doSafeClientServerSwitch(JoinGamePacket joinGame) { // Some clients do not behave well with the "fast" respawn sequence. In this case we will use // a "safe" respawn sequence that involves sending three packets to the client. They have the // same effect but tend to work better with buggier clients (Forge 1.8 in particular). @@ -412,14 +412,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Send a respawn packet in a different dimension. int tempDim = joinGame.getDimension() == 0 ? -1 : 0; player.getConnection().delayedWrite( - new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), + new RespawnPacket(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), joinGame.getCurrentDimensionData())); // Now send a respawn packet in the correct dimension. player.getConnection().delayedWrite( - new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(), + new RespawnPacket(joinGame.getDimension(), joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), joinGame.getCurrentDimensionData())); @@ -429,7 +429,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return serverBossBars; } - private boolean handleCommandTabComplete(TabCompleteRequest packet) { + private boolean handleCommandTabComplete(TabCompleteRequestPacket packet) { // In 1.13+, we need to do additional work for the richer suggestions available. String command = packet.getCommand().substring(1); int commandEndPosition = command.indexOf(' '); @@ -459,7 +459,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } int startPos = packet.getCommand().lastIndexOf(' ') + 1; if (startPos > 0) { - TabCompleteResponse resp = new TabCompleteResponse(); + TabCompleteResponsePacket resp = new TabCompleteResponsePacket(); resp.setTransactionId(packet.getTransactionId()); resp.setStart(startPos); resp.setLength(packet.getCommand().length() - startPos); @@ -475,7 +475,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return true; // Sorry, handler; we're just gonna have to lie to you here. } - private boolean handleRegularTabComplete(TabCompleteRequest packet) { + private boolean handleRegularTabComplete(TabCompleteRequestPacket packet) { if (player.getProtocolVersion().compareTo(MINECRAFT_1_13) < 0) { // Outstanding tab completes are recorded for use with 1.12 clients and below to provide // additional tab completion support. @@ -489,7 +489,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { * * @param response the tab complete response from the backend */ - public void handleTabCompleteResponse(TabCompleteResponse response) { + public void handleTabCompleteResponse(TabCompleteResponsePacket response) { if (outstandingTabComplete != null && !outstandingTabComplete.isAssumeCommand()) { if (outstandingTabComplete.getCommand().startsWith("/")) { this.finishCommandTabComplete(outstandingTabComplete, response); @@ -503,7 +503,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } } - private void finishCommandTabComplete(TabCompleteRequest request, TabCompleteResponse response) { + private void finishCommandTabComplete(TabCompleteRequestPacket request, + TabCompleteResponsePacket response) { String command = request.getCommand().substring(1); server.getCommandManager().offerSuggestions(player, command) .thenAcceptAsync(offers -> { @@ -532,7 +533,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { }); } - private void finishRegularTabComplete(TabCompleteRequest request, TabCompleteResponse response) { + private void finishRegularTabComplete(TabCompleteRequestPacket request, + TabCompleteResponsePacket response) { List offers = new ArrayList<>(); for (Offer offer : response.getOffers()) { offers.add(offer.getText()); @@ -562,13 +564,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { MinecraftConnection smc = player.ensureAndGetCurrentServer().ensureConnected(); String commandToRun = result.getCommand().orElse(originalCommand); if (result.isForwardToServer()) { - return CompletableFuture.runAsync(() -> smc.write(Chat.createServerbound("/" + return CompletableFuture.runAsync(() -> smc.write(ChatPacket.createServerbound("/" + commandToRun)), smc.eventLoop()); } else { return server.getCommandManager().executeImmediately(player, commandToRun) .thenAcceptAsync(hasRun -> { if (!hasRun) { - smc.write(Chat.createServerbound("/" + commandToRun)); + smc.write(ChatPacket.createServerbound("/" + commandToRun)); } }, smc.eventLoop()); } @@ -582,7 +584,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { if (serverConnection != null) { MinecraftConnection connection = serverConnection.getConnection(); if (connection != null) { - PluginMessage pm; + PluginMessagePacket pm; while ((pm = loginPluginMessages.poll()) != null) { connection.write(pm); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java index a0d349db8..dfee04f61 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java @@ -2,20 +2,20 @@ package com.velocitypowered.proxy.connection.client; import com.velocitypowered.api.proxy.player.PlayerSettings; import com.velocitypowered.api.proxy.player.SkinParts; -import com.velocitypowered.proxy.protocol.packet.ClientSettings; +import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public class ClientSettingsWrapper implements PlayerSettings { static final PlayerSettings DEFAULT = new ClientSettingsWrapper( - new ClientSettings("en_US", (byte) 10, 0, true, (short) 127, 1)); + new ClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1)); - private final ClientSettings settings; + private final ClientSettingsPacket settings; private final SkinParts parts; private @Nullable Locale locale; - ClientSettingsWrapper(ClientSettings settings) { + ClientSettingsWrapper(ClientSettingsPacket settings) { this.settings = settings; this.parts = new SkinParts((byte) settings.getSkinParts()); } 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 a2679ec1c..4f3682322 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 @@ -38,12 +38,12 @@ import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.Chat; -import com.velocitypowered.proxy.protocol.packet.ClientSettings; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.KeepAlive; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; -import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest; +import com.velocitypowered.proxy.protocol.packet.ChatPacket; +import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket; import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.server.VelocityRegisteredServer; @@ -186,7 +186,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings; } - void setPlayerSettings(ClientSettings settings) { + void setPlayerSettings(ClientSettingsPacket settings) { ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); this.settings = cs; server.getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, cs)); @@ -228,7 +228,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public void sendMessage(@NonNull Identity identity, @NonNull Component message) { - connection.write(Chat.createClientbound(identity, message, this.getProtocolVersion())); + connection.write(ChatPacket.createClientbound(identity, message, this.getProtocolVersion())); } @Override @@ -237,8 +237,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(type, "type"); - Chat packet = Chat.createClientbound(identity, message, this.getProtocolVersion()); - packet.setType(type == MessageType.CHAT ? Chat.CHAT_TYPE : Chat.SYSTEM_TYPE); + ChatPacket packet = ChatPacket.createClientbound(identity, message, this.getProtocolVersion()); + packet.setType(type == MessageType.CHAT ? ChatPacket.CHAT_TYPE : ChatPacket.SYSTEM_TYPE); connection.write(packet); } @@ -257,9 +257,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { // legacy message and then inject the legacy text into a component... yuck! JsonObject object = new JsonObject(); object.addProperty("text", LegacyComponentSerializer.legacySection().serialize(message)); - Chat chat = new Chat(); + ChatPacket chat = new ChatPacket(); chat.setMessage(object.toString()); - chat.setType(Chat.GAME_INFO_TYPE); + chat.setType(ChatPacket.GAME_INFO_TYPE); connection.write(chat); } } @@ -343,7 +343,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public void disconnect0(Component reason, boolean duringLogin) { logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(Disconnect.create(reason, this.getProtocolVersion())); + connection.closeWith(DisconnectPacket.create(reason, this.getProtocolVersion())); } public @Nullable VelocityServerConnection getConnectedServer() { @@ -402,7 +402,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { * @param disconnect the disconnect packet * @param safe whether or not we can safely reconnect to a new server */ - public void handleConnectionException(RegisteredServer server, Disconnect disconnect, + public void handleConnectionException(RegisteredServer server, DisconnectPacket disconnect, boolean safe) { if (!isActive()) { // If the connection is no longer active, it makes no sense to try and recover it. @@ -507,7 +507,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { case SERVER_DISCONNECTED: Component reason = status.getReason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); - handleConnectionException(res.getServer(), Disconnect.create(reason, + handleConnectionException(res.getServer(), DisconnectPacket.create(reason, getProtocolVersion()), ((Impl) status).isSafe()); break; case SUCCESS: @@ -664,24 +664,25 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { Preconditions.checkNotNull(identifier, "identifier"); Preconditions.checkNotNull(data, "data"); - PluginMessage message = new PluginMessage(identifier.getId(), Unpooled.wrappedBuffer(data)); + PluginMessagePacket message = new PluginMessagePacket(identifier.getId(), + Unpooled.wrappedBuffer(data)); connection.write(message); return true; } @Override public void spoofChatInput(String input) { - Preconditions.checkArgument(input.length() <= Chat.MAX_SERVERBOUND_MESSAGE_LENGTH, - "input cannot be greater than " + Chat.MAX_SERVERBOUND_MESSAGE_LENGTH + Preconditions.checkArgument(input.length() <= ChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH, + "input cannot be greater than " + ChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH + " characters in length"); - ensureBackendConnection().write(Chat.createServerbound(input)); + ensureBackendConnection().write(ChatPacket.createServerbound(input)); } @Override public void sendResourcePack(String url) { Preconditions.checkNotNull(url, "url"); - ResourcePackRequest request = new ResourcePackRequest(); + ResourcePackRequestPacket request = new ResourcePackRequestPacket(); request.setUrl(url); request.setHash(""); connection.write(request); @@ -693,20 +694,20 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { Preconditions.checkNotNull(hash, "hash"); Preconditions.checkArgument(hash.length == 20, "Hash length is not 20"); - ResourcePackRequest request = new ResourcePackRequest(); + ResourcePackRequestPacket request = new ResourcePackRequestPacket(); request.setUrl(url); request.setHash(ByteBufUtil.hexDump(hash)); connection.write(request); } /** - * Sends a {@link KeepAlive} packet to the player with a random ID. + * Sends a {@link KeepAlivePacket} packet to the player with a random ID. * The response will be ignored by Velocity as it will not match the * ID last sent by the server. */ public void sendKeepAlive() { if (connection.getState() == StateRegistry.PLAY) { - KeepAlive keepAlive = new KeepAlive(); + KeepAlivePacket keepAlive = new KeepAlivePacket(); keepAlive.setRandomId(ThreadLocalRandom.current().nextLong()); connection.write(keepAlive); } @@ -746,7 +747,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { * @param message the plugin message to forward to the client * @return {@code true} if the message can be forwarded, {@code false} otherwise */ - public boolean canForwardPluginMessage(ProtocolVersion version, PluginMessage message) { + public boolean canForwardPluginMessage(ProtocolVersion version, PluginMessagePacket message) { boolean minecraftOrFmlMessage; // By default, all internal Minecraft and Forge channels are forwarded from the server. @@ -879,7 +880,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { case SERVER_DISCONNECTED: Component reason = status.getReason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); - handleConnectionException(toConnect, Disconnect.create(reason, + handleConnectionException(toConnect, DisconnectPacket.create(reason, getProtocolVersion()), status.isSafe()); break; default: 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 0716d4fdc..cdcc581a4 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 @@ -12,12 +12,12 @@ import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.Handshake; -import com.velocitypowered.proxy.protocol.packet.LegacyDisconnect; -import com.velocitypowered.proxy.protocol.packet.LegacyHandshake; -import com.velocitypowered.proxy.protocol.packet.LegacyPing; +import com.velocitypowered.proxy.protocol.packet.HandshakePacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; import io.netty.buffer.ByteBuf; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -41,7 +41,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(LegacyPing packet) { + public boolean handle(LegacyPingPacket packet) { connection.setProtocolVersion(ProtocolVersion.LEGACY); StatusSessionHandler handler = new StatusSessionHandler(server, connection, new LegacyInboundConnection(connection, packet)); @@ -51,14 +51,14 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(LegacyHandshake packet) { - connection.closeWith(LegacyDisconnect + public boolean handle(LegacyHandshakePacket packet) { + connection.closeWith(LegacyDisconnectPacket .from(Component.text("Your client is old, please upgrade!", NamedTextColor.RED))); return true; } @Override - public boolean handle(Handshake handshake) { + public boolean handle(HandshakePacket handshake) { InitialInboundConnection ic = new InitialInboundConnection(connection, cleanVhost(handshake.getServerAddress()), handshake); StateRegistry nextState = getStateForProtocol(handshake.getNextStatus()); @@ -97,7 +97,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } } - private void handleLogin(Handshake handshake, InitialInboundConnection ic) { + private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic) { if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) { ic.disconnectQuietly(Component.translatable("multiplayer.disconnect.outdated_client")); return; @@ -123,7 +123,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); } - private ConnectionType getHandshakeConnectionType(Handshake handshake) { + private ConnectionType getHandshakeConnectionType(HandshakePacket handshake) { // Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13). if (handshake.getServerAddress().endsWith(LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN) && handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { @@ -164,7 +164,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public void handleGeneric(MinecraftPacket packet) { + public void handleGeneric(Packet packet) { // Unknown packet received. Better to close the connection. connection.close(true); } @@ -178,10 +178,10 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { private static class LegacyInboundConnection implements InboundConnection { private final MinecraftConnection connection; - private final LegacyPing ping; + private final LegacyPingPacket ping; private LegacyInboundConnection(MinecraftConnection connection, - LegacyPing ping) { + LegacyPingPacket ping) { this.connection = connection; this.ping = ping; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java index 188ae3537..e634a3aaa 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java @@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.client; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; public class InitialConnectSessionHandler implements MinecraftSessionHandler { @@ -15,7 +15,7 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(PluginMessage packet) { + public boolean handle(PluginMessagePacket packet) { VelocityServerConnection serverConn = player.getConnectionInFlight(); if (serverConn != null) { if (player.getPhase().handle(player, packet, serverConn)) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index e984ac5e9..38bcf4cfe 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -4,8 +4,8 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.Handshake; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.HandshakePacket; import java.net.InetSocketAddress; import java.util.Optional; import net.kyori.adventure.text.Component; @@ -20,10 +20,10 @@ public final class InitialInboundConnection implements InboundConnection, private final MinecraftConnection connection; private final String cleanedAddress; - private final Handshake handshake; + private final HandshakePacket handshake; InitialInboundConnection(MinecraftConnection connection, String cleanedAddress, - Handshake handshake) { + HandshakePacket handshake) { this.connection = connection; this.cleanedAddress = cleanedAddress; this.handshake = handshake; @@ -61,7 +61,7 @@ public final class InitialInboundConnection implements InboundConnection, public void disconnect(Component reason) { logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(Disconnect.create(reason, getProtocolVersion())); + connection.closeWith(DisconnectPacket.create(reason, getProtocolVersion())); } /** @@ -69,6 +69,6 @@ public final class InitialInboundConnection implements InboundConnection, * @param reason the reason for disconnecting */ public void disconnectQuietly(Component reason) { - connection.closeWith(Disconnect.create(reason, getProtocolVersion())); + connection.closeWith(DisconnectPacket.create(reason, getProtocolVersion())); } } 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 3072f2767..4fc9f6ea5 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 @@ -26,12 +26,12 @@ import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; -import com.velocitypowered.proxy.protocol.packet.EncryptionResponse; -import com.velocitypowered.proxy.protocol.packet.ServerLogin; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; -import com.velocitypowered.proxy.protocol.packet.SetCompression; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; +import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; +import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; import io.netty.buffer.ByteBuf; import java.net.InetSocketAddress; import java.security.GeneralSecurityException; @@ -58,7 +58,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private final VelocityServer server; private final MinecraftConnection mcConnection; private final InitialInboundConnection inbound; - private @MonotonicNonNull ServerLogin login; + private @MonotonicNonNull ServerLoginPacket login; private byte[] verify = EMPTY_BYTE_ARRAY; private @MonotonicNonNull ConnectedPlayer connectedPlayer; @@ -70,15 +70,15 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(ServerLogin packet) { + public boolean handle(ServerLoginPacket packet) { this.login = packet; beginPreLogin(); return true; } @Override - public boolean handle(EncryptionResponse packet) { - ServerLogin login = this.login; + public boolean handle(EncryptionResponsePacket packet) { + ServerLoginPacket login = this.login; if (login == null) { throw new IllegalStateException("No ServerLogin packet received yet."); } @@ -153,7 +153,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } private void beginPreLogin() { - ServerLogin login = this.login; + ServerLoginPacket login = this.login; if (login == null) { throw new IllegalStateException("No ServerLogin packet received yet."); } @@ -169,7 +169,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { Optional disconnectReason = result.getReason(); if (disconnectReason.isPresent()) { // The component is guaranteed to be provided if the connection was denied. - mcConnection.closeWith(Disconnect.create(disconnectReason.get(), + mcConnection.closeWith(DisconnectPacket.create(disconnectReason.get(), inbound.getProtocolVersion())); return; } @@ -177,7 +177,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result .isOnlineModeAllowed())) { // Request encryption. - EncryptionRequest request = generateEncryptionRequest(); + EncryptionRequestPacket request = generateEncryptionRequest(); this.verify = Arrays.copyOf(request.getVerifyToken(), 4); mcConnection.write(request); } else { @@ -190,11 +190,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { }); } - private EncryptionRequest generateEncryptionRequest() { + private EncryptionRequestPacket generateEncryptionRequest() { byte[] verify = new byte[4]; ThreadLocalRandom.current().nextBytes(verify); - EncryptionRequest request = new EncryptionRequest(); + EncryptionRequestPacket request = new EncryptionRequestPacket(); request.setPublicKey(server.getServerKeyPair().getPublic().getEncoded()); request.setVerifyToken(verify); return request; @@ -243,7 +243,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private void completeLoginProtocolPhaseAndInitialize(ConnectedPlayer player) { int threshold = server.getConfiguration().getCompressionThreshold(); if (threshold >= 0 && mcConnection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) { - mcConnection.write(new SetCompression(threshold)); + mcConnection.write(new SetCompressionPacket(threshold)); mcConnection.setCompressionThreshold(threshold); } VelocityConfiguration configuration = server.getConfiguration(); @@ -251,7 +251,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) { playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername()); } - ServerLoginSuccess success = new ServerLoginSuccess(); + ServerLoginSuccessPacket success = new ServerLoginSuccessPacket(); success.setUsername(player.getUsername()); success.setUuid(playerUniqueId); mcConnection.write(success); 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 f88e27e94..a526c5dd4 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 @@ -13,11 +13,11 @@ import com.velocitypowered.proxy.config.PingPassthroughMode; import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.packet.LegacyDisconnect; -import com.velocitypowered.proxy.protocol.packet.LegacyPing; -import com.velocitypowered.proxy.protocol.packet.StatusPing; -import com.velocitypowered.proxy.protocol.packet.StatusRequest; -import com.velocitypowered.proxy.protocol.packet.StatusResponse; +import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; +import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; +import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.util.except.QuietRuntimeException; import io.netty.buffer.ByteBuf; @@ -158,7 +158,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(LegacyPing packet) { + public boolean handle(LegacyPingPacket packet) { if (this.pingReceived) { throw EXPECTED_AWAITING_REQUEST; } @@ -166,7 +166,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { getInitialPing() .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenAcceptAsync(event -> connection.closeWith( - LegacyDisconnect.fromServerPing(event.getPing(), packet.getVersion())), + LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())), connection.eventLoop()) .exceptionally((ex) -> { logger.error("Exception while handling legacy ping {}", packet, ex); @@ -176,13 +176,13 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } @Override - public boolean handle(StatusPing packet) { + public boolean handle(StatusPingPacket packet) { connection.closeWith(packet); return true; } @Override - public boolean handle(StatusRequest packet) { + public boolean handle(StatusRequestPacket packet) { if (this.pingReceived) { throw EXPECTED_AWAITING_REQUEST; } @@ -195,7 +195,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { StringBuilder json = new StringBuilder(); VelocityServer.getPingGsonInstance(connection.getProtocolVersion()) .toJson(event.getPing(), json); - connection.write(new StatusResponse(json)); + connection.write(new StatusResponsePacket(json)); }, connection.eventLoop()) .exceptionally((ex) -> { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java index 5dc381f2f..452aac6f0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java @@ -6,7 +6,7 @@ import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; import javax.annotation.Nullable; /** @@ -107,7 +107,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase { @Override public final boolean handle(VelocityServerConnection serverConnection, ConnectedPlayer player, - PluginMessage message) { + PluginMessagePacket message) { if (message.getChannel().equals(LegacyForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) { // Get the phase and check if we need to start the next phase. LegacyForgeHandshakeBackendPhase newPhase = getNewPhase(serverConnection, message); @@ -162,7 +162,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase { * @return The phase to transition to, which may be the same as before. */ private LegacyForgeHandshakeBackendPhase getNewPhase(VelocityServerConnection serverConnection, - PluginMessage packet) { + PluginMessagePacket packet) { if (packetToAdvanceOn != null && LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) { LegacyForgeHandshakeBackendPhase phaseToTransitionTo = nextPhase(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java index da4096cad..3d756b853 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java @@ -7,7 +7,7 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.client.ClientConnectionPhase; import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; import java.util.List; import javax.annotation.Nullable; @@ -39,7 +39,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { @Override boolean onHandle(ConnectedPlayer player, - PluginMessage message, + PluginMessagePacket message, MinecraftConnection backendConn) { // If we stay in this phase, we do nothing because it means the packet wasn't handled. // Returning false indicates this @@ -73,7 +73,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { @Override boolean onHandle(ConnectedPlayer player, - PluginMessage message, + PluginMessagePacket message, MinecraftConnection backendConn) { // Read the mod list if we haven't already. if (!player.getModInfo().isPresent()) { @@ -147,7 +147,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { @Override boolean onHandle(ConnectedPlayer player, - PluginMessage message, + PluginMessagePacket message, MinecraftConnection backendConn) { super.onHandle(player, message, backendConn); @@ -180,7 +180,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { @Override public final boolean handle(ConnectedPlayer player, - PluginMessage message, + PluginMessagePacket message, VelocityServerConnection server) { if (server != null) { MinecraftConnection backendConn = server.getConnection(); @@ -211,7 +211,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { * @return true if handled, false otherwise. */ boolean onHandle(ConnectedPlayer player, - PluginMessage message, + PluginMessagePacket message, MinecraftConnection backendConn) { // Send the packet on to the server. backendConn.write(message.retain()); @@ -241,7 +241,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { * @param packet The packet * @return The phase to transition to, which may be the same as before. */ - private LegacyForgeHandshakeClientPhase getNewPhase(PluginMessage packet) { + private LegacyForgeHandshakeClientPhase getNewPhase(PluginMessagePacket packet) { if (packetToAdvanceOn != null && LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) { return nextPhase(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java index 8d2c9d410..f73ea4783 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java @@ -8,7 +8,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.List; @@ -25,7 +25,7 @@ class LegacyForgeUtil { * @param message The message to analyse * @return The discriminator */ - static byte getHandshakePacketDiscriminator(PluginMessage message) { + static byte getHandshakePacketDiscriminator(PluginMessagePacket message) { Preconditions.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL)); Preconditions.checkArgument(message.content().isReadable()); return message.content().getByte(0); @@ -37,7 +37,7 @@ class LegacyForgeUtil { * @param message The message * @return The list of mods. May be empty. */ - static List readModList(PluginMessage message) { + static List readModList(PluginMessagePacket message) { Preconditions.checkNotNull(message, "message"); Preconditions .checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL), @@ -71,8 +71,8 @@ class LegacyForgeUtil { * * @return A copy of the reset packet */ - static PluginMessage resetPacket() { - PluginMessage msg = new PluginMessage(); + static PluginMessagePacket resetPacket() { + PluginMessagePacket msg = new PluginMessagePacket(); msg.setChannel(FORGE_LEGACY_HANDSHAKE_CHANNEL); msg.replace(Unpooled.wrappedBuffer(FORGE_LEGACY_HANDSHAKE_RESET_DATA.clone())); return msg; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java index 5852bc66e..35bf09488 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java @@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.util; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder.Status; import com.velocitypowered.api.proxy.server.RegisteredServer; -import com.velocitypowered.proxy.protocol.packet.Disconnect; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; import java.util.Optional; import javax.annotation.Nullable; import net.kyori.adventure.text.Component; @@ -41,12 +41,12 @@ public class ConnectionRequestResults { return new Impl(Status.SERVER_DISCONNECTED, component, server, true); } - public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) { + public static Impl forDisconnect(DisconnectPacket disconnect, RegisteredServer server) { Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); return forDisconnect(deserialized, server); } - public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) { + public static Impl forUnsafeDisconnect(DisconnectPacket disconnect, RegisteredServer server) { Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java index b6cff8606..9db1dd4c7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java @@ -8,7 +8,7 @@ import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER; import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; import com.velocitypowered.proxy.VelocityServer; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.netty.AutoReadHolderHandler; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; @@ -37,9 +37,9 @@ public class BackendChannelInitializer extends ChannelInitializer { .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, - new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) + new MinecraftDecoder(ProtocolDirection.CLIENTBOUND)) .addLast(FLOW_HANDLER, new AutoReadHolderHandler()) .addLast(MINECRAFT_ENCODER, - new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)); + new MinecraftEncoder(ProtocolDirection.SERVERBOUND)); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java index 64d2ec835..ce7d3e3fc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -11,7 +11,7 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder; import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; @@ -43,8 +43,8 @@ public class ServerChannelInitializer extends ChannelInitializer { .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) - .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND)) - .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND)); + .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolDirection.SERVERBOUND)) + .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolDirection.CLIENTBOUND)); final MinecraftConnection connection = new MinecraftConnection(ch, this.server); connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/MinecraftPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/Packet.java similarity index 53% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/MinecraftPacket.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/Packet.java index 11bed9297..b4dfcee26 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/MinecraftPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/Packet.java @@ -4,11 +4,11 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import io.netty.buffer.ByteBuf; -public interface MinecraftPacket { +public interface Packet { - void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion); + void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion); - void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion); + void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion); boolean handle(MinecraftSessionHandler handler); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolDirection.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolDirection.java new file mode 100644 index 000000000..d1a218b12 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolDirection.java @@ -0,0 +1,6 @@ +package com.velocitypowered.proxy.protocol; + +public enum ProtocolDirection { + SERVERBOUND, + CLIENTBOUND; +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index a7e0bd437..85b479cee 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -465,14 +465,4 @@ public enum ProtocolUtils { return PRE_1_16_SERIALIZER; } - public enum Direction { - SERVERBOUND, - CLIENTBOUND; - - public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(StateRegistry state, - ProtocolVersion version) { - return (this == SERVERBOUND ? state.serverbound : state.clientbound) - .getProtocolRegistry(version); - } - } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java index ada663f92..d2e694f52 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -14,35 +14,34 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4; import static com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION; import static com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS; -import static com.velocitypowered.proxy.protocol.ProtocolUtils.Direction; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.packet.AvailableCommands; -import com.velocitypowered.proxy.protocol.packet.BossBar; -import com.velocitypowered.proxy.protocol.packet.Chat; -import com.velocitypowered.proxy.protocol.packet.ClientSettings; -import com.velocitypowered.proxy.protocol.packet.Disconnect; -import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; -import com.velocitypowered.proxy.protocol.packet.EncryptionResponse; -import com.velocitypowered.proxy.protocol.packet.Handshake; -import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; -import com.velocitypowered.proxy.protocol.packet.JoinGame; -import com.velocitypowered.proxy.protocol.packet.KeepAlive; -import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage; -import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse; -import com.velocitypowered.proxy.protocol.packet.PlayerListItem; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; -import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest; -import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse; -import com.velocitypowered.proxy.protocol.packet.Respawn; -import com.velocitypowered.proxy.protocol.packet.ServerLogin; -import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; -import com.velocitypowered.proxy.protocol.packet.SetCompression; -import com.velocitypowered.proxy.protocol.packet.StatusPing; -import com.velocitypowered.proxy.protocol.packet.StatusRequest; -import com.velocitypowered.proxy.protocol.packet.StatusResponse; -import com.velocitypowered.proxy.protocol.packet.TabCompleteRequest; -import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; +import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket; +import com.velocitypowered.proxy.protocol.packet.BossBarPacket; +import com.velocitypowered.proxy.protocol.packet.ChatPacket; +import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; +import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; +import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket; +import com.velocitypowered.proxy.protocol.packet.HandshakePacket; +import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket; +import com.velocitypowered.proxy.protocol.packet.JoinGamePacket; +import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket; +import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket; +import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket; +import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket; +import com.velocitypowered.proxy.protocol.packet.RespawnPacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; +import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; +import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; +import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; +import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; +import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket; +import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; import com.velocitypowered.proxy.protocol.packet.TitlePacket; import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectMap; @@ -60,20 +59,20 @@ public enum StateRegistry { HANDSHAKE { { - serverbound.register(Handshake.class, Handshake::new, + serverbound.register(HandshakePacket.class, HandshakePacket::new, map(0x00, MINECRAFT_1_7_2, false)); } }, STATUS { { - serverbound.register(StatusRequest.class, () -> StatusRequest.INSTANCE, + serverbound.register(StatusRequestPacket.class, () -> StatusRequestPacket.INSTANCE, map(0x00, MINECRAFT_1_7_2, false)); - serverbound.register(StatusPing.class, StatusPing::new, + serverbound.register(StatusPingPacket.class, StatusPingPacket::new, map(0x01, MINECRAFT_1_7_2, false)); - clientbound.register(StatusResponse.class, StatusResponse::new, + clientbound.register(StatusResponsePacket.class, StatusResponsePacket::new, map(0x00, MINECRAFT_1_7_2, false)); - clientbound.register(StatusPing.class, StatusPing::new, + clientbound.register(StatusPingPacket.class, StatusPingPacket::new, map(0x01, MINECRAFT_1_7_2, false)); } }, @@ -82,33 +81,33 @@ public enum StateRegistry { serverbound.fallback = false; clientbound.fallback = false; - serverbound.register(TabCompleteRequest.class, TabCompleteRequest::new, + serverbound.register(TabCompleteRequestPacket.class, TabCompleteRequestPacket::new, map(0x14, MINECRAFT_1_7_2, false), map(0x01, MINECRAFT_1_9, false), map(0x02, MINECRAFT_1_12, false), map(0x01, MINECRAFT_1_12_1, false), map(0x05, MINECRAFT_1_13, false), map(0x06, MINECRAFT_1_14, false)); - serverbound.register(Chat.class, Chat::new, + serverbound.register(ChatPacket.class, ChatPacket::new, map(0x01, MINECRAFT_1_7_2, false), map(0x02, MINECRAFT_1_9, false), map(0x03, MINECRAFT_1_12, false), map(0x02, MINECRAFT_1_12_1, false), map(0x03, MINECRAFT_1_14, false)); - serverbound.register(ClientSettings.class, ClientSettings::new, + serverbound.register(ClientSettingsPacket.class, ClientSettingsPacket::new, map(0x15, MINECRAFT_1_7_2, false), map(0x04, MINECRAFT_1_9, false), map(0x05, MINECRAFT_1_12, false), map(0x04, MINECRAFT_1_12_1, false), map(0x05, MINECRAFT_1_14, false)); - serverbound.register(PluginMessage.class, PluginMessage::new, + serverbound.register(PluginMessagePacket.class, PluginMessagePacket::new, map(0x17, MINECRAFT_1_7_2, false), map(0x09, MINECRAFT_1_9, false), map(0x0A, MINECRAFT_1_12, false), map(0x09, MINECRAFT_1_12_1, false), map(0x0A, MINECRAFT_1_13, false), map(0x0B, MINECRAFT_1_14, false)); - serverbound.register(KeepAlive.class, KeepAlive::new, + serverbound.register(KeepAlivePacket.class, KeepAlivePacket::new, map(0x00, MINECRAFT_1_7_2, false), map(0x0B, MINECRAFT_1_9, false), map(0x0C, MINECRAFT_1_12, false), @@ -116,7 +115,7 @@ public enum StateRegistry { map(0x0E, MINECRAFT_1_13, false), map(0x0F, MINECRAFT_1_14, false), map(0x10, MINECRAFT_1_16, false)); - serverbound.register(ResourcePackResponse.class, ResourcePackResponse::new, + serverbound.register(ResourcePackResponsePacket.class, ResourcePackResponsePacket::new, map(0x19, MINECRAFT_1_8, false), map(0x16, MINECRAFT_1_9, false), map(0x18, MINECRAFT_1_12, false), @@ -125,29 +124,29 @@ public enum StateRegistry { map(0x20, MINECRAFT_1_16, false), map(0x21, MINECRAFT_1_16_2, false)); - clientbound.register(BossBar.class, BossBar::new, + clientbound.register(BossBarPacket.class, BossBarPacket::new, map(0x0C, MINECRAFT_1_9, false), map(0x0D, MINECRAFT_1_15, false), map(0x0C, MINECRAFT_1_16, false)); - clientbound.register(Chat.class, Chat::new, + clientbound.register(ChatPacket.class, ChatPacket::new, map(0x02, MINECRAFT_1_7_2, true), map(0x0F, MINECRAFT_1_9, true), map(0x0E, MINECRAFT_1_13, true), map(0x0F, MINECRAFT_1_15, true), map(0x0E, MINECRAFT_1_16, true)); - clientbound.register(TabCompleteResponse.class, TabCompleteResponse::new, + clientbound.register(TabCompleteResponsePacket.class, TabCompleteResponsePacket::new, map(0x3A, MINECRAFT_1_7_2, false), map(0x0E, MINECRAFT_1_9, false), map(0x10, MINECRAFT_1_13, false), map(0x11, MINECRAFT_1_15, false), map(0x10, MINECRAFT_1_16, false), map(0x0F, MINECRAFT_1_16_2, false)); - clientbound.register(AvailableCommands.class, AvailableCommands::new, + clientbound.register(AvailableCommandsPacket.class, AvailableCommandsPacket::new, map(0x11, MINECRAFT_1_13, false), map(0x12, MINECRAFT_1_15, false), map(0x11, MINECRAFT_1_16, false), map(0x10, MINECRAFT_1_16_2, false)); - clientbound.register(PluginMessage.class, PluginMessage::new, + clientbound.register(PluginMessagePacket.class, PluginMessagePacket::new, map(0x3F, MINECRAFT_1_7_2, false), map(0x18, MINECRAFT_1_9, false), map(0x19, MINECRAFT_1_13, false), @@ -155,7 +154,7 @@ public enum StateRegistry { map(0x19, MINECRAFT_1_15, false), map(0x18, MINECRAFT_1_16, false), map(0x17, MINECRAFT_1_16_2, false)); - clientbound.register(Disconnect.class, Disconnect::new, + clientbound.register(DisconnectPacket.class, DisconnectPacket::new, map(0x40, MINECRAFT_1_7_2, false), map(0x1A, MINECRAFT_1_9, false), map(0x1B, MINECRAFT_1_13, false), @@ -163,7 +162,7 @@ public enum StateRegistry { map(0x1B, MINECRAFT_1_15, false), map(0x1A, MINECRAFT_1_16, false), map(0x19, MINECRAFT_1_16_2, false)); - clientbound.register(KeepAlive.class, KeepAlive::new, + clientbound.register(KeepAlivePacket.class, KeepAlivePacket::new, map(0x00, MINECRAFT_1_7_2, false), map(0x1F, MINECRAFT_1_9, false), map(0x21, MINECRAFT_1_13, false), @@ -171,7 +170,7 @@ public enum StateRegistry { map(0x21, MINECRAFT_1_15, false), map(0x20, MINECRAFT_1_16, false), map(0x1F, MINECRAFT_1_16_2, false)); - clientbound.register(JoinGame.class, JoinGame::new, + clientbound.register(JoinGamePacket.class, JoinGamePacket::new, map(0x01, MINECRAFT_1_7_2, false), map(0x23, MINECRAFT_1_9, false), map(0x25, MINECRAFT_1_13, false), @@ -179,7 +178,7 @@ public enum StateRegistry { map(0x26, MINECRAFT_1_15, false), map(0x25, MINECRAFT_1_16, false), map(0x24, MINECRAFT_1_16_2, false)); - clientbound.register(Respawn.class, Respawn::new, + clientbound.register(RespawnPacket.class, RespawnPacket::new, map(0x07, MINECRAFT_1_7_2, true), map(0x33, MINECRAFT_1_9, true), map(0x34, MINECRAFT_1_12, true), @@ -189,7 +188,7 @@ public enum StateRegistry { map(0x3B, MINECRAFT_1_15, true), map(0x3A, MINECRAFT_1_16, true), map(0x39, MINECRAFT_1_16_2, true)); - clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new, + clientbound.register(ResourcePackRequestPacket.class, ResourcePackRequestPacket::new, map(0x48, MINECRAFT_1_8, true), map(0x32, MINECRAFT_1_9, true), map(0x33, MINECRAFT_1_12, true), @@ -199,7 +198,7 @@ public enum StateRegistry { map(0x3A, MINECRAFT_1_15, true), map(0x39, MINECRAFT_1_16, true), map(0x38, MINECRAFT_1_16_2, true)); - clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new, + clientbound.register(HeaderAndFooterPacket.class, HeaderAndFooterPacket::new, map(0x47, MINECRAFT_1_8, true), map(0x48, MINECRAFT_1_9, true), map(0x47, MINECRAFT_1_9_4, true), @@ -218,7 +217,7 @@ public enum StateRegistry { map(0x4F, MINECRAFT_1_14, true), map(0x50, MINECRAFT_1_15, true), map(0x4F, MINECRAFT_1_16, true)); - clientbound.register(PlayerListItem.class, PlayerListItem::new, + clientbound.register(PlayerListItemPacket.class, PlayerListItemPacket::new, map(0x38, MINECRAFT_1_7_2, false), map(0x2D, MINECRAFT_1_9, false), map(0x2E, MINECRAFT_1_12_1, false), @@ -231,37 +230,43 @@ public enum StateRegistry { }, LOGIN { { - serverbound.register(ServerLogin.class, ServerLogin::new, + serverbound.register(ServerLoginPacket.class, ServerLoginPacket::new, map(0x00, MINECRAFT_1_7_2, false)); - serverbound.register(EncryptionResponse.class, EncryptionResponse::new, + serverbound.register(EncryptionResponsePacket.class, EncryptionResponsePacket::new, map(0x01, MINECRAFT_1_7_2, false)); - serverbound.register(LoginPluginResponse.class, LoginPluginResponse::new, + serverbound.register(LoginPluginResponsePacket.class, LoginPluginResponsePacket::new, map(0x02, MINECRAFT_1_13, false)); - clientbound.register(Disconnect.class, Disconnect::new, + clientbound.register(DisconnectPacket.class, DisconnectPacket::new, map(0x00, MINECRAFT_1_7_2, false)); - clientbound.register(EncryptionRequest.class, EncryptionRequest::new, + clientbound.register(EncryptionRequestPacket.class, EncryptionRequestPacket::new, map(0x01, MINECRAFT_1_7_2, false)); - clientbound.register(ServerLoginSuccess.class, ServerLoginSuccess::new, + clientbound.register(ServerLoginSuccessPacket.class, ServerLoginSuccessPacket::new, map(0x02, MINECRAFT_1_7_2, false)); - clientbound.register(SetCompression.class, SetCompression::new, + clientbound.register(SetCompressionPacket.class, SetCompressionPacket::new, map(0x03, MINECRAFT_1_8, false)); - clientbound.register(LoginPluginMessage.class, LoginPluginMessage::new, + clientbound.register(LoginPluginMessagePacket.class, LoginPluginMessagePacket::new, map(0x04, MINECRAFT_1_13, false)); } }; public static final int STATUS_ID = 1; public static final int LOGIN_ID = 2; - public final PacketRegistry clientbound = new PacketRegistry(Direction.CLIENTBOUND); - public final PacketRegistry serverbound = new PacketRegistry(Direction.SERVERBOUND); + public final PacketRegistry clientbound = new PacketRegistry(ProtocolDirection.CLIENTBOUND); + public final PacketRegistry serverbound = new PacketRegistry(ProtocolDirection.SERVERBOUND); + + public PacketRegistry.ProtocolRegistry getProtocolRegistry(ProtocolDirection direction, + ProtocolVersion version) { + return (direction == ProtocolDirection.SERVERBOUND ? this.serverbound : this.clientbound) + .getProtocolRegistry(version); + } public static class PacketRegistry { - private final Direction direction; + private final ProtocolDirection direction; private final Map versions; private boolean fallback = true; - PacketRegistry(Direction direction) { + PacketRegistry(ProtocolDirection direction) { this.direction = direction; Map mutableVersions = new EnumMap<>(ProtocolVersion.class); @@ -285,8 +290,8 @@ public enum StateRegistry { return registry; } -

void register(Class

clazz, Supplier

packetSupplier, - PacketMapping... mappings) { +

void register(Class

clazz, Supplier

packetSupplier, + PacketMapping... mappings) { if (mappings.length == 0) { throw new IllegalArgumentException("At least one mapping must be provided."); } @@ -334,9 +339,9 @@ public enum StateRegistry { public class ProtocolRegistry { public final ProtocolVersion version; - final IntObjectMap> packetIdToSupplier = + final IntObjectMap> packetIdToSupplier = new IntObjectHashMap<>(16, 0.5f); - final Object2IntMap> packetClassToId = + final Object2IntMap> packetClassToId = new Object2IntOpenHashMap<>(16, 0.5f); ProtocolRegistry(final ProtocolVersion version) { @@ -350,8 +355,8 @@ public enum StateRegistry { * @param id the packet ID * @return the packet instance, or {@code null} if the ID is not registered */ - public @Nullable MinecraftPacket createPacket(final int id) { - final Supplier supplier = this.packetIdToSupplier.get(id); + public @Nullable Packet createPacket(final int id) { + final Supplier supplier = this.packetIdToSupplier.get(id); if (supplier == null) { return null; } @@ -365,7 +370,7 @@ public enum StateRegistry { * @return the packet ID * @throws IllegalArgumentException if the packet ID is not found */ - public int getPacketId(final MinecraftPacket packet) { + public int getPacketId(final Packet packet) { final int id = this.packetClassToId.getInt(packet.getClass()); if (id == Integer.MIN_VALUE) { throw new IllegalArgumentException(String.format( diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java index 875bc3c78..1bb86ca2d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java @@ -2,8 +2,8 @@ package com.velocitypowered.proxy.protocol.netty; import static com.velocitypowered.proxy.protocol.util.NettyPreconditions.checkFrame; -import com.velocitypowered.proxy.protocol.packet.LegacyHandshake; -import com.velocitypowered.proxy.protocol.packet.LegacyPing; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket; import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -32,13 +32,13 @@ public class LegacyPingDecoder extends ByteToMessageDecoder { if (first == 0xfe) { // possibly a ping if (!in.isReadable()) { - out.add(new LegacyPing(LegacyMinecraftPingVersion.MINECRAFT_1_3)); + out.add(new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_3)); return; } short next = in.readUnsignedByte(); if (next == 1 && !in.isReadable()) { - out.add(new LegacyPing(LegacyMinecraftPingVersion.MINECRAFT_1_4)); + out.add(new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_4)); return; } @@ -46,14 +46,14 @@ public class LegacyPingDecoder extends ByteToMessageDecoder { out.add(readExtended16Data(in)); } else if (first == 0x02 && in.isReadable()) { in.skipBytes(in.readableBytes()); - out.add(new LegacyHandshake()); + out.add(new LegacyHandshakePacket()); } else { in.readerIndex(originalReaderIndex); ctx.pipeline().remove(this); } } - private static LegacyPing readExtended16Data(ByteBuf in) { + private static LegacyPingPacket readExtended16Data(ByteBuf in) { in.skipBytes(1); String channelName = readLegacyString(in); if (!channelName.equals(MC_1_6_CHANNEL)) { @@ -63,7 +63,7 @@ public class LegacyPingDecoder extends ByteToMessageDecoder { String hostname = readLegacyString(in); int port = in.readInt(); - return new LegacyPing(LegacyMinecraftPingVersion.MINECRAFT_1_6, InetSocketAddress + return new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_6, InetSocketAddress .createUnresolved(hostname, port)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingEncoder.java index f45981a78..0a96f01bb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingEncoder.java @@ -1,6 +1,6 @@ package com.velocitypowered.proxy.protocol.netty; -import com.velocitypowered.proxy.protocol.packet.LegacyDisconnect; +import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -8,7 +8,7 @@ import io.netty.handler.codec.MessageToByteEncoder; import java.nio.charset.StandardCharsets; @ChannelHandler.Sharable -public class LegacyPingEncoder extends MessageToByteEncoder { +public class LegacyPingEncoder extends MessageToByteEncoder { public static final LegacyPingEncoder INSTANCE = new LegacyPingEncoder(); @@ -16,7 +16,7 @@ public class LegacyPingEncoder extends MessageToByteEncoder { } @Override - protected void encode(ChannelHandlerContext ctx, LegacyDisconnect msg, ByteBuf out) + protected void encode(ChannelHandlerContext ctx, LegacyDisconnectPacket msg, ByteBuf out) throws Exception { out.writeByte(0xff); writeLegacyString(out, msg.getReason()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java index 5139bedfd..e61104923 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java @@ -2,7 +2,8 @@ package com.velocitypowered.proxy.protocol.netty; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.util.except.QuietDecoderException; @@ -18,7 +19,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { new QuietDecoderException("A packet did not decode successfully (invalid data). If you are a " + "developer, launch Velocity with -Dvelocity.packet-decode-logging=true to see more."); - private final ProtocolUtils.Direction direction; + private final ProtocolDirection direction; private StateRegistry state; private StateRegistry.PacketRegistry.ProtocolRegistry registry; @@ -27,9 +28,9 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { * * @param direction the direction from which we decode from */ - public MinecraftDecoder(ProtocolUtils.Direction direction) { + public MinecraftDecoder(ProtocolDirection direction) { this.direction = Preconditions.checkNotNull(direction, "direction"); - this.registry = direction.getProtocolRegistry(StateRegistry.HANDSHAKE, + this.registry = StateRegistry.HANDSHAKE.getProtocolRegistry(direction, ProtocolVersion.MINIMUM_VERSION); this.state = StateRegistry.HANDSHAKE; } @@ -52,7 +53,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { int originalReaderIndex = buf.readerIndex(); int packetId = ProtocolUtils.readVarInt(buf); - MinecraftPacket packet = this.registry.createPacket(packetId); + Packet packet = this.registry.createPacket(packetId); if (packet == null) { buf.readerIndex(originalReaderIndex); ctx.fireChannelRead(buf); @@ -74,7 +75,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { } } - private Exception handleNotReadEnough(MinecraftPacket packet, int packetId) { + private Exception handleNotReadEnough(Packet packet, int packetId) { if (DEBUG) { return new CorruptedFrameException("Did not read full packet for " + packet.getClass() + " " + getExtraConnectionDetail(packetId)); @@ -83,7 +84,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { } } - private Exception handleDecodeFailure(Exception cause, MinecraftPacket packet, int packetId) { + private Exception handleDecodeFailure(Exception cause, Packet packet, int packetId) { if (DEBUG) { return new CorruptedFrameException( "Error decoding " + packet.getClass() + " " + getExtraConnectionDetail(packetId), cause); @@ -98,7 +99,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { } public void setProtocolVersion(ProtocolVersion protocolVersion) { - this.registry = direction.getProtocolRegistry(state, protocolVersion); + this.registry = state.getProtocolRegistry(direction, protocolVersion); } public void setState(StateRegistry state) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java index 889232de5..e6c0800b6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java @@ -2,16 +2,17 @@ package com.velocitypowered.proxy.protocol.netty; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.StateRegistry; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; -public class MinecraftEncoder extends MessageToByteEncoder { +public class MinecraftEncoder extends MessageToByteEncoder { - private final ProtocolUtils.Direction direction; + private final ProtocolDirection direction; private StateRegistry state; private StateRegistry.PacketRegistry.ProtocolRegistry registry; @@ -20,22 +21,22 @@ public class MinecraftEncoder extends MessageToByteEncoder { * * @param direction the direction to encode to */ - public MinecraftEncoder(ProtocolUtils.Direction direction) { + public MinecraftEncoder(ProtocolDirection direction) { this.direction = Preconditions.checkNotNull(direction, "direction"); - this.registry = direction - .getProtocolRegistry(StateRegistry.HANDSHAKE, ProtocolVersion.MINIMUM_VERSION); + this.registry = StateRegistry.HANDSHAKE + .getProtocolRegistry(direction, ProtocolVersion.MINIMUM_VERSION); this.state = StateRegistry.HANDSHAKE; } @Override - protected void encode(ChannelHandlerContext ctx, MinecraftPacket msg, ByteBuf out) { + protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) { int packetId = this.registry.getPacketId(msg); ProtocolUtils.writeVarInt(out, packetId); msg.encode(out, direction, registry.version); } public void setProtocolVersion(final ProtocolVersion protocolVersion) { - this.registry = direction.getProtocolRegistry(state, protocolVersion); + this.registry = state.getProtocolRegistry(direction, protocolVersion); } public void setState(StateRegistry state) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommands.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommandsPacket.java similarity index 96% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommands.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommandsPacket.java index e6ffd5de8..b563391c6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommands.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/AvailableCommandsPacket.java @@ -19,9 +19,9 @@ import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertyRegistry; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; @@ -35,7 +35,7 @@ import java.util.concurrent.CompletableFuture; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; -public class AvailableCommands implements MinecraftPacket { +public class AvailableCommandsPacket implements Packet { private static final Command PLACEHOLDER_COMMAND = source -> 0; private static final byte NODE_TYPE_ROOT = 0x00; @@ -61,7 +61,7 @@ public class AvailableCommands implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { int commands = ProtocolUtils.readVarInt(buf); WireNode[] wireNodes = new WireNode[commands]; for (int i = 0; i < commands; i++) { @@ -93,7 +93,7 @@ public class AvailableCommands implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { // Assign all the children an index. Deque> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode)); Object2IntMap> idMappings = new Object2IntLinkedOpenHashMap<>(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBarPacket.java similarity index 90% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBarPacket.java index 63ef23ed8..64440cf8f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBarPacket.java @@ -2,13 +2,14 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; -public class BossBar implements MinecraftPacket { +public class BossBarPacket implements Packet { public static final int ADD = 0; public static final int REMOVE = 1; @@ -16,6 +17,7 @@ public class BossBar implements MinecraftPacket { public static final int UPDATE_NAME = 3; public static final int UPDATE_STYLE = 4; public static final int UPDATE_PROPERTIES = 5; + private @Nullable UUID uuid; private int action; private @Nullable String name; @@ -97,7 +99,7 @@ public class BossBar implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.uuid = ProtocolUtils.readUuid(buf); this.action = ProtocolUtils.readVarInt(buf); switch (action) { @@ -129,7 +131,7 @@ public class BossBar implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (uuid == null) { throw new IllegalStateException("No boss bar UUID specified"); } @@ -174,8 +176,8 @@ public class BossBar implements MinecraftPacket { return handler.handle(this); } - public static BossBar createRemovePacket(UUID id) { - BossBar packet = new BossBar(); + public static BossBarPacket createRemovePacket(UUID id) { + BossBarPacket packet = new BossBarPacket(); packet.setUuid(id); packet.setAction(REMOVE); return packet; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ChatPacket.java similarity index 67% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ChatPacket.java index 3b6a868a0..ac8766d2e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ChatPacket.java @@ -3,7 +3,8 @@ package com.velocitypowered.proxy.protocol.packet; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.adventure.identity.Identity; @@ -12,7 +13,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import java.util.UUID; -public class Chat implements MinecraftPacket { +public class ChatPacket implements Packet { public static final byte CHAT_TYPE = (byte) 0; public static final byte SYSTEM_TYPE = (byte) 1; @@ -25,10 +26,10 @@ public class Chat implements MinecraftPacket { private byte type; private @Nullable UUID sender; - public Chat() { + public ChatPacket() { } - public Chat(String message, byte type, UUID sender) { + public ChatPacket(String message, byte type, UUID sender) { this.message = message; this.type = type; this.sender = sender; @@ -71,9 +72,9 @@ public class Chat implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { message = ProtocolUtils.readString(buf); - if (direction == ProtocolUtils.Direction.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (direction == ProtocolDirection.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { type = buf.readByte(); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { sender = ProtocolUtils.readUuid(buf); @@ -82,12 +83,12 @@ public class Chat implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (message == null) { throw new IllegalStateException("Message is not specified"); } ProtocolUtils.writeString(buf, message); - if (direction == ProtocolUtils.Direction.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (direction == ProtocolDirection.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { buf.writeByte(type); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { ProtocolUtils.writeUuid(buf, sender == null ? EMPTY_SENDER : sender); @@ -100,19 +101,19 @@ public class Chat implements MinecraftPacket { return handler.handle(this); } - public static Chat createClientbound(Identity identity, - Component component, ProtocolVersion version) { + public static ChatPacket createClientbound(Identity identity, + Component component, ProtocolVersion version) { return createClientbound(component, CHAT_TYPE, identity.uuid(), version); } - public static Chat createClientbound(Component component, byte type, - UUID sender, ProtocolVersion version) { + public static ChatPacket createClientbound(Component component, byte type, + UUID sender, ProtocolVersion version) { Preconditions.checkNotNull(component, "component"); - return new Chat(ProtocolUtils.getJsonChatSerializer(version).serialize(component), type, + return new ChatPacket(ProtocolUtils.getJsonChatSerializer(version).serialize(component), type, sender); } - public static Chat createServerbound(String message) { - return new Chat(message, CHAT_TYPE, EMPTY_SENDER); + public static ChatPacket createServerbound(String message) { + return new ChatPacket(message, CHAT_TYPE, EMPTY_SENDER); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java similarity index 85% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java index 361b1178e..efc10203c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettings.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java @@ -2,12 +2,13 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class ClientSettings implements MinecraftPacket { +public class ClientSettingsPacket implements Packet { private @Nullable String locale; private byte viewDistance; @@ -17,11 +18,11 @@ public class ClientSettings implements MinecraftPacket { private short skinParts; private int mainHand; - public ClientSettings() { + public ClientSettingsPacket() { } - public ClientSettings(String locale, byte viewDistance, int chatVisibility, boolean chatColors, - short skinParts, int mainHand) { + public ClientSettingsPacket(String locale, byte viewDistance, int chatVisibility, boolean chatColors, + short skinParts, int mainHand) { this.locale = locale; this.viewDistance = viewDistance; this.chatVisibility = chatVisibility; @@ -94,7 +95,7 @@ public class ClientSettings implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.locale = ProtocolUtils.readString(buf, 16); this.viewDistance = buf.readByte(); this.chatVisibility = ProtocolUtils.readVarInt(buf); @@ -112,7 +113,7 @@ public class ClientSettings implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (locale == null) { throw new IllegalStateException("No locale specified"); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/DisconnectPacket.java similarity index 67% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/DisconnectPacket.java index 63a92ffdb..5ae0bc162 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/DisconnectPacket.java @@ -3,20 +3,21 @@ package com.velocitypowered.proxy.protocol.packet; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; -public class Disconnect implements MinecraftPacket { +public class DisconnectPacket implements Packet { private @Nullable String reason; - public Disconnect() { + public DisconnectPacket() { } - public Disconnect(String reason) { + public DisconnectPacket(String reason) { this.reason = Preconditions.checkNotNull(reason, "reason"); } @@ -39,12 +40,12 @@ public class Disconnect implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { reason = ProtocolUtils.readString(buf); } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (reason == null) { throw new IllegalStateException("No reason specified."); } @@ -56,8 +57,8 @@ public class Disconnect implements MinecraftPacket { return handler.handle(this); } - public static Disconnect create(Component component, ProtocolVersion version) { + public static DisconnectPacket create(Component component, ProtocolVersion version) { Preconditions.checkNotNull(component, "component"); - return new Disconnect(ProtocolUtils.getJsonChatSerializer(version).serialize(component)); + return new DisconnectPacket(ProtocolUtils.getJsonChatSerializer(version).serialize(component)); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequestPacket.java similarity index 84% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequestPacket.java index 6575ac73f..ffcc9a9c0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequestPacket.java @@ -4,12 +4,13 @@ import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import java.util.Arrays; -public class EncryptionRequest implements MinecraftPacket { +public class EncryptionRequestPacket implements Packet { private String serverId = ""; private byte[] publicKey = EMPTY_BYTE_ARRAY; @@ -40,7 +41,7 @@ public class EncryptionRequest implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.serverId = ProtocolUtils.readString(buf, 20); if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { @@ -53,7 +54,7 @@ public class EncryptionRequest implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { ProtocolUtils.writeString(buf, this.serverId); if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponsePacket.java similarity index 82% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponsePacket.java index 5022f5c18..ec7e89d8e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponsePacket.java @@ -4,12 +4,13 @@ import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import java.util.Arrays; -public class EncryptionResponse implements MinecraftPacket { +public class EncryptionResponsePacket implements Packet { private byte[] sharedSecret = EMPTY_BYTE_ARRAY; private byte[] verifyToken = EMPTY_BYTE_ARRAY; @@ -31,7 +32,7 @@ public class EncryptionResponse implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { this.sharedSecret = ProtocolUtils.readByteArray(buf, 256); this.verifyToken = ProtocolUtils.readByteArray(buf, 128); @@ -42,7 +43,7 @@ public class EncryptionResponse implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { ProtocolUtils.writeByteArray(buf, sharedSecret); ProtocolUtils.writeByteArray(buf, verifyToken); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java similarity index 84% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java index cf64b7b93..cab9f3328 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java @@ -2,11 +2,12 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; -public class Handshake implements MinecraftPacket { +public class HandshakePacket implements Packet { private ProtocolVersion protocolVersion; private String serverAddress = ""; @@ -56,7 +57,7 @@ public class Handshake implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion ignored) { int realProtocolVersion = ProtocolUtils.readVarInt(buf); this.protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); this.serverAddress = ProtocolUtils.readString(buf); @@ -65,7 +66,7 @@ public class Handshake implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion ignored) { ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol()); ProtocolUtils.writeString(buf, this.serverAddress); buf.writeShort(this.port); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooterPacket.java similarity index 59% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooterPacket.java index 36c3a3d85..fc7900453 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooterPacket.java @@ -5,24 +5,25 @@ import static com.velocitypowered.proxy.protocol.ProtocolUtils.writeString; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -public class HeaderAndFooter implements MinecraftPacket { +public class HeaderAndFooterPacket implements Packet { private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}"; - private static final HeaderAndFooter RESET = new HeaderAndFooter(); + private static final HeaderAndFooterPacket RESET = new HeaderAndFooterPacket(); private final String header; private final String footer; - public HeaderAndFooter() { + public HeaderAndFooterPacket() { this(EMPTY_COMPONENT, EMPTY_COMPONENT); } - public HeaderAndFooter(String header, String footer) { + public HeaderAndFooterPacket(String header, String footer) { this.header = Preconditions.checkNotNull(header, "header"); this.footer = Preconditions.checkNotNull(footer, "footer"); } @@ -36,12 +37,12 @@ public class HeaderAndFooter implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { throw new UnsupportedOperationException("Decode is not implemented"); } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { writeString(buf, header); writeString(buf, footer); } @@ -51,13 +52,13 @@ public class HeaderAndFooter implements MinecraftPacket { return handler.handle(this); } - public static HeaderAndFooter create(net.kyori.adventure.text.Component header, - net.kyori.adventure.text.Component footer, ProtocolVersion protocolVersion) { + public static HeaderAndFooterPacket create(net.kyori.adventure.text.Component header, + net.kyori.adventure.text.Component footer, ProtocolVersion protocolVersion) { GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(protocolVersion); - return new HeaderAndFooter(serializer.serialize(header), serializer.serialize(footer)); + return new HeaderAndFooterPacket(serializer.serialize(header), serializer.serialize(footer)); } - public static HeaderAndFooter reset() { + public static HeaderAndFooterPacket reset() { return RESET; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGamePacket.java similarity index 96% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGamePacket.java index 76c384584..2c480b334 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGamePacket.java @@ -6,14 +6,16 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionRegistry; -import com.velocitypowered.proxy.protocol.*; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; +import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.adventure.nbt.BinaryTagTypes; import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.ListBinaryTag; import org.checkerframework.checker.nullness.qual.Nullable; -public class JoinGame implements MinecraftPacket { +public class JoinGamePacket implements Packet { private int entityId; private short gamemode; @@ -163,7 +165,7 @@ public class JoinGame implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.entityId = buf.readInt(); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { this.isHardcore = buf.readBoolean(); @@ -236,7 +238,7 @@ public class JoinGame implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { buf.writeInt(entityId); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { buf.writeBoolean(isHardcore); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlivePacket.java similarity index 78% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlivePacket.java index 32febe2b6..8e7bb3f85 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlivePacket.java @@ -2,11 +2,12 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; -public class KeepAlive implements MinecraftPacket { +public class KeepAlivePacket implements Packet { private long randomId; @@ -26,7 +27,7 @@ public class KeepAlive implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) { randomId = buf.readLong(); } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { @@ -37,7 +38,7 @@ public class KeepAlive implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) { buf.writeLong(randomId); } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyHandshake.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyHandshake.java deleted file mode 100644 index a7141b9e4..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyHandshake.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.velocitypowered.proxy.protocol.packet; - -import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; -import com.velocitypowered.proxy.protocol.ProtocolUtils; -import io.netty.buffer.ByteBuf; - -public class LegacyHandshake implements MinecraftPacket { - - @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { - throw new UnsupportedOperationException(); - } - - @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean handle(MinecraftSessionHandler handler) { - return handler.handle(this); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessagePacket.java similarity index 75% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessagePacket.java index a3dae879d..c5287cc07 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessagePacket.java @@ -2,23 +2,24 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.checkerframework.checker.nullness.qual.Nullable; -public class LoginPluginMessage extends DeferredByteBufHolder implements MinecraftPacket { +public class LoginPluginMessagePacket extends DeferredByteBufHolder implements Packet { private int id; private @Nullable String channel; - public LoginPluginMessage() { + public LoginPluginMessagePacket() { super(null); } - public LoginPluginMessage(int id, @Nullable String channel, ByteBuf data) { + public LoginPluginMessagePacket(int id, @Nullable String channel, ByteBuf data) { super(data); this.id = id; this.channel = channel; @@ -45,7 +46,7 @@ public class LoginPluginMessage extends DeferredByteBufHolder implements Minecra } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.id = ProtocolUtils.readVarInt(buf); this.channel = ProtocolUtils.readString(buf); if (buf.isReadable()) { @@ -56,7 +57,7 @@ public class LoginPluginMessage extends DeferredByteBufHolder implements Minecra } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { ProtocolUtils.writeVarInt(buf, id); if (channel == null) { throw new IllegalStateException("Channel is not specified!"); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponsePacket.java similarity index 74% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponsePacket.java index 5321c0eea..bfd403f56 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponsePacket.java @@ -2,23 +2,24 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; -public class LoginPluginResponse extends DeferredByteBufHolder implements MinecraftPacket { +public class LoginPluginResponsePacket extends DeferredByteBufHolder implements Packet { private int id; private boolean success; - public LoginPluginResponse() { + public LoginPluginResponsePacket() { super(Unpooled.EMPTY_BUFFER); } - public LoginPluginResponse(int id, boolean success, @MonotonicNonNull ByteBuf buf) { + public LoginPluginResponsePacket(int id, boolean success, @MonotonicNonNull ByteBuf buf) { super(buf); this.id = id; this.success = success; @@ -50,7 +51,7 @@ public class LoginPluginResponse extends DeferredByteBufHolder implements Minecr } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.id = ProtocolUtils.readVarInt(buf); this.success = buf.readBoolean(); if (buf.isReadable()) { @@ -61,7 +62,7 @@ public class LoginPluginResponse extends DeferredByteBufHolder implements Minecr } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { ProtocolUtils.writeVarInt(buf, id); buf.writeBoolean(success); buf.writeBytes(content()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItemPacket.java similarity index 94% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItemPacket.java index 80058abdc..64421dd49 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItemPacket.java @@ -5,7 +5,8 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -15,7 +16,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; -public class PlayerListItem implements MinecraftPacket { +public class PlayerListItemPacket implements Packet { public static final int ADD_PLAYER = 0; public static final int UPDATE_GAMEMODE = 1; @@ -25,12 +26,12 @@ public class PlayerListItem implements MinecraftPacket { private int action; private final List items = new ArrayList<>(); - public PlayerListItem(int action, List items) { + public PlayerListItemPacket(int action, List items) { this.action = action; this.items.addAll(items); } - public PlayerListItem() { + public PlayerListItemPacket() { } public int getAction() { @@ -42,7 +43,7 @@ public class PlayerListItem implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { action = ProtocolUtils.readVarInt(buf); int length = ProtocolUtils.readVarInt(buf); @@ -92,7 +93,7 @@ public class PlayerListItem implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, items.size()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessagePacket.java similarity index 63% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessagePacket.java index 5b9b3f136..8ceaecfde 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessagePacket.java @@ -4,23 +4,24 @@ import static com.velocitypowered.proxy.protocol.util.PluginMessageUtil.transfor import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; -public class PluginMessage extends DeferredByteBufHolder implements MinecraftPacket { +public class PluginMessagePacket extends DeferredByteBufHolder implements Packet { private @Nullable String channel; - public PluginMessage() { + public PluginMessagePacket() { super(null); } - public PluginMessage(String channel, - @MonotonicNonNull ByteBuf backing) { + public PluginMessagePacket(String channel, + @MonotonicNonNull ByteBuf backing) { super(backing); this.channel = channel; } @@ -45,7 +46,7 @@ public class PluginMessage extends DeferredByteBufHolder implements MinecraftPac } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.channel = ProtocolUtils.readString(buf); if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { this.channel = transformLegacyToModernChannel(this.channel); @@ -59,7 +60,7 @@ public class PluginMessage extends DeferredByteBufHolder implements MinecraftPac } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (channel == null) { throw new IllegalStateException("Channel is not specified."); } @@ -82,42 +83,42 @@ public class PluginMessage extends DeferredByteBufHolder implements MinecraftPac } @Override - public PluginMessage copy() { - return (PluginMessage) super.copy(); + public PluginMessagePacket copy() { + return (PluginMessagePacket) super.copy(); } @Override - public PluginMessage duplicate() { - return (PluginMessage) super.duplicate(); + public PluginMessagePacket duplicate() { + return (PluginMessagePacket) super.duplicate(); } @Override - public PluginMessage retainedDuplicate() { - return (PluginMessage) super.retainedDuplicate(); + public PluginMessagePacket retainedDuplicate() { + return (PluginMessagePacket) super.retainedDuplicate(); } @Override - public PluginMessage replace(ByteBuf content) { - return (PluginMessage) super.replace(content); + public PluginMessagePacket replace(ByteBuf content) { + return (PluginMessagePacket) super.replace(content); } @Override - public PluginMessage retain() { - return (PluginMessage) super.retain(); + public PluginMessagePacket retain() { + return (PluginMessagePacket) super.retain(); } @Override - public PluginMessage retain(int increment) { - return (PluginMessage) super.retain(increment); + public PluginMessagePacket retain(int increment) { + return (PluginMessagePacket) super.retain(increment); } @Override - public PluginMessage touch() { - return (PluginMessage) super.touch(); + public PluginMessagePacket touch() { + return (PluginMessagePacket) super.touch(); } @Override - public PluginMessage touch(Object hint) { - return (PluginMessage) super.touch(hint); + public PluginMessagePacket touch(Object hint) { + return (PluginMessagePacket) super.touch(hint); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequestPacket.java similarity index 78% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequest.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequestPacket.java index 435b5fb53..1bd277173 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackRequestPacket.java @@ -2,14 +2,14 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; -public class ResourcePackRequest implements MinecraftPacket { +public class ResourcePackRequestPacket implements Packet { private @MonotonicNonNull String url; private @MonotonicNonNull String hash; @@ -31,13 +31,13 @@ public class ResourcePackRequest implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { this.url = ProtocolUtils.readString(buf); this.hash = ProtocolUtils.readString(buf); } @Override - public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { if (url == null || hash == null) { throw new IllegalStateException("Packet not fully filled in yet!"); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponsePacket.java similarity index 78% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponse.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponsePacket.java index 16f47ac3c..d5c1b1ef0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ResourcePackResponsePacket.java @@ -3,13 +3,13 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent.Status; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; -public class ResourcePackResponse implements MinecraftPacket { +public class ResourcePackResponsePacket implements Packet { private String hash = ""; private @MonotonicNonNull Status status; @@ -22,7 +22,7 @@ public class ResourcePackResponse implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) { this.hash = ProtocolUtils.readString(buf); } @@ -30,7 +30,7 @@ public class ResourcePackResponse implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) { ProtocolUtils.writeString(buf, hash); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/RespawnPacket.java similarity index 89% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/RespawnPacket.java index 9a5aee432..53cf1b5db 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/RespawnPacket.java @@ -4,12 +4,13 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionInfo; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.adventure.nbt.CompoundBinaryTag; -public class Respawn implements MinecraftPacket { +public class RespawnPacket implements Packet { private int dimension; private long partialHashedSeed; @@ -21,12 +22,12 @@ public class Respawn implements MinecraftPacket { private short previousGamemode; // 1.16+ private DimensionData currentDimensionData; // 1.16.2+ - public Respawn() { + public RespawnPacket() { } - public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode, - String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, - short previousGamemode, DimensionData currentDimensionData) { + public RespawnPacket(int dimension, long partialHashedSeed, short difficulty, short gamemode, + String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, + short previousGamemode, DimensionData currentDimensionData) { this.dimension = dimension; this.partialHashedSeed = partialHashedSeed; this.difficulty = difficulty; @@ -111,7 +112,7 @@ public class Respawn implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { String dimensionIdentifier = null; String levelName = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { @@ -146,7 +147,7 @@ public class Respawn implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginPacket.java similarity index 76% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginPacket.java index ebd7489e9..500fe4cdd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginPacket.java @@ -3,22 +3,23 @@ package com.velocitypowered.proxy.protocol.packet; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class ServerLogin implements MinecraftPacket { +public class ServerLoginPacket implements Packet { private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!"); private @Nullable String username; - public ServerLogin() { + public ServerLoginPacket() { } - public ServerLogin(String username) { + public ServerLoginPacket(String username) { this.username = Preconditions.checkNotNull(username, "username"); } @@ -37,7 +38,7 @@ public class ServerLogin implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { username = ProtocolUtils.readString(buf, 16); if (username.isEmpty()) { throw EMPTY_USERNAME; @@ -45,7 +46,7 @@ public class ServerLogin implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (username == null) { throw new IllegalStateException("No username found!"); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccessPacket.java similarity index 86% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccessPacket.java index b7a3e54de..11b7defba 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccessPacket.java @@ -3,13 +3,14 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.util.UuidUtils; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; -public class ServerLoginSuccess implements MinecraftPacket { +public class ServerLoginSuccessPacket implements Packet { private @Nullable UUID uuid; private @Nullable String username; @@ -45,7 +46,7 @@ public class ServerLoginSuccess implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { uuid = ProtocolUtils.readUuidIntArray(buf); } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) { @@ -57,7 +58,7 @@ public class ServerLoginSuccess implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (uuid == null) { throw new IllegalStateException("No UUID specified!"); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompressionPacket.java similarity index 66% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompressionPacket.java index 50996cc1c..71a93b56f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompressionPacket.java @@ -2,18 +2,19 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; -public class SetCompression implements MinecraftPacket { +public class SetCompressionPacket implements Packet { private int threshold; - public SetCompression() { + public SetCompressionPacket() { } - public SetCompression(int threshold) { + public SetCompressionPacket(int threshold) { this.threshold = threshold; } @@ -33,12 +34,12 @@ public class SetCompression implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { this.threshold = ProtocolUtils.readVarInt(buf); } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { ProtocolUtils.writeVarInt(buf, threshold); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPing.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPingPacket.java similarity index 54% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPing.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPingPacket.java index 7d61e6996..712559d93 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPing.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusPingPacket.java @@ -2,21 +2,21 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import io.netty.buffer.ByteBuf; -public class StatusPing implements MinecraftPacket { +public class StatusPingPacket implements Packet { private long randomId; @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { randomId = buf.readLong(); } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { buf.writeLong(randomId); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequestPacket.java similarity index 52% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequest.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequestPacket.java index 7d1b9bc57..9e5d8b41a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusRequestPacket.java @@ -2,25 +2,25 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import io.netty.buffer.ByteBuf; -public class StatusRequest implements MinecraftPacket { +public class StatusRequestPacket implements Packet { - public static final StatusRequest INSTANCE = new StatusRequest(); + public static final StatusRequestPacket INSTANCE = new StatusRequestPacket(); - private StatusRequest() { + private StatusRequestPacket() { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { // There is no additional data to decode. } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { // There is no data to decode. } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponsePacket.java similarity index 70% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponsePacket.java index df0d856cc..36199352f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponsePacket.java @@ -2,19 +2,20 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class StatusResponse implements MinecraftPacket { +public class StatusResponsePacket implements Packet { private @Nullable CharSequence status; - public StatusResponse() { + public StatusResponsePacket() { } - public StatusResponse(CharSequence status) { + public StatusResponsePacket(CharSequence status) { this.status = status; } @@ -33,12 +34,12 @@ public class StatusResponse implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { status = ProtocolUtils.readString(buf, Short.MAX_VALUE); } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (status == null) { throw new IllegalStateException("Status is not specified"); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequestPacket.java similarity index 90% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequestPacket.java index 30bf616a0..21abfd0a8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequestPacket.java @@ -7,12 +7,13 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9; import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class TabCompleteRequest implements MinecraftPacket { +public class TabCompleteRequestPacket implements Packet { private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048; @@ -77,7 +78,7 @@ public class TabCompleteRequest implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(MINECRAFT_1_13) >= 0) { this.transactionId = ProtocolUtils.readVarInt(buf); this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN); @@ -96,7 +97,7 @@ public class TabCompleteRequest implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (command == null) { throw new IllegalStateException("Command is not specified"); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponsePacket.java similarity index 92% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponsePacket.java index d63ac9279..1c3f4dc38 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponsePacket.java @@ -5,7 +5,8 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13; import com.google.common.base.MoreObjects; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -13,7 +14,7 @@ import java.util.List; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; -public class TabCompleteResponse implements MinecraftPacket { +public class TabCompleteResponsePacket implements Packet { private int transactionId; private int start; @@ -59,7 +60,7 @@ public class TabCompleteResponse implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(MINECRAFT_1_13) >= 0) { this.transactionId = ProtocolUtils.readVarInt(buf); this.start = ProtocolUtils.readVarInt(buf); @@ -80,7 +81,7 @@ public class TabCompleteResponse implements MinecraftPacket { } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { if (version.compareTo(MINECRAFT_1_13) >= 0) { ProtocolUtils.writeVarInt(buf, this.transactionId); ProtocolUtils.writeVarInt(buf, this.start); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java index 085936ae8..35f5b1194 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java @@ -2,12 +2,13 @@ package com.velocitypowered.proxy.protocol.packet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class TitlePacket implements MinecraftPacket { +public class TitlePacket implements Packet { public static final int SET_TITLE = 0; public static final int SET_SUBTITLE = 1; @@ -26,12 +27,12 @@ public class TitlePacket implements MinecraftPacket { private int fadeOut; @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { throw new UnsupportedOperationException(); // encode only } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { ProtocolUtils.writeVarInt(buf, action); if (version.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) { // 1.11+ shifted the action enum by 1 to handle the action bar diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyDisconnectPacket.java similarity index 83% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyDisconnectPacket.java index 9a4f22cdd..0965bb26b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyDisconnectPacket.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.protocol.packet.legacy; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.proxy.server.ServerPing; @@ -8,7 +8,7 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; -public class LegacyDisconnect { +public class LegacyDisconnectPacket { private static final ServerPing.Players FAKE_PLAYERS = new ServerPing.Players(0, 0, ImmutableList.of()); @@ -17,7 +17,7 @@ public class LegacyDisconnect { private final String reason; - private LegacyDisconnect(String reason) { + private LegacyDisconnectPacket(String reason) { this.reason = reason; } @@ -27,8 +27,8 @@ public class LegacyDisconnect { * @param version the requesting clients' version * @return the disconnect packet */ - public static LegacyDisconnect fromServerPing(ServerPing response, - LegacyMinecraftPingVersion version) { + public static LegacyDisconnectPacket fromServerPing(ServerPing response, + LegacyMinecraftPingVersion version) { Players players = response.getPlayers().orElse(FAKE_PLAYERS); switch (version) { @@ -36,7 +36,7 @@ public class LegacyDisconnect { // Minecraft 1.3 and below use the section symbol as a delimiter. Accordingly, we must // remove all section symbols, along with fetching just the first line of an (unformatted) // MOTD. - return new LegacyDisconnect(String.join(LEGACY_COLOR_CODE, + return new LegacyDisconnectPacket(String.join(LEGACY_COLOR_CODE, cleanSectionSymbol(getFirstLine(PlainComponentSerializer.plain().serialize( response.getDescription()))), Integer.toString(players.getOnline()), @@ -44,7 +44,7 @@ public class LegacyDisconnect { case MINECRAFT_1_4: case MINECRAFT_1_6: // Minecraft 1.4-1.6 provide support for more fields, and additionally support color codes. - return new LegacyDisconnect(String.join("\0", + return new LegacyDisconnectPacket(String.join("\0", LEGACY_COLOR_CODE + "1", Integer.toString(response.getVersion().getProtocol()), response.getVersion().getName(), @@ -72,10 +72,10 @@ public class LegacyDisconnect { * @param component the component to convert * @return the disconnect packet */ - public static LegacyDisconnect from(TextComponent component) { + public static LegacyDisconnectPacket from(TextComponent component) { // We intentionally use the legacy serializers, because the old clients can't understand JSON. String serialized = LegacyComponentSerializer.legacySection().serialize(component); - return new LegacyDisconnect(serialized); + return new LegacyDisconnectPacket(serialized); } public String getReason() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyHandshakePacket.java new file mode 100644 index 000000000..efc1cb8c9 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyHandshakePacket.java @@ -0,0 +1,25 @@ +package com.velocitypowered.proxy.protocol.packet.legacy; + +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.connection.MinecraftSessionHandler; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; +import io.netty.buffer.ByteBuf; + +public class LegacyHandshakePacket implements Packet { + + @Override + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + throw new UnsupportedOperationException(); + } + + @Override + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean handle(MinecraftSessionHandler handler) { + return handler.handle(this); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPing.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPingPacket.java similarity index 63% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPing.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPingPacket.java index eb8e754c6..87b55b25f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPing.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/legacy/LegacyPingPacket.java @@ -1,25 +1,25 @@ -package com.velocitypowered.proxy.protocol.packet; +package com.velocitypowered.proxy.protocol.packet.legacy; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.MinecraftPacket; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.Packet; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import io.netty.buffer.ByteBuf; import java.net.InetSocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; -public class LegacyPing implements MinecraftPacket { +public class LegacyPingPacket implements Packet { private final LegacyMinecraftPingVersion version; private final @Nullable InetSocketAddress vhost; - public LegacyPing(LegacyMinecraftPingVersion version) { + public LegacyPingPacket(LegacyMinecraftPingVersion version) { this.version = version; this.vhost = null; } - public LegacyPing(LegacyMinecraftPingVersion version, InetSocketAddress vhost) { + public LegacyPingPacket(LegacyMinecraftPingVersion version, InetSocketAddress vhost) { this.version = version; this.vhost = vhost; } @@ -33,12 +33,12 @@ public class LegacyPing implements MinecraftPacket { } @Override - public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { throw new UnsupportedOperationException(); } @Override - public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { + public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { throw new UnsupportedOperationException(); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java index c91a1967b..0059eac38 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java @@ -7,7 +7,7 @@ import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.util.ProxyVersion; import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.packet.PluginMessage; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.nio.charset.StandardCharsets; @@ -34,7 +34,7 @@ public final class PluginMessageUtil { * @param message the plugin message * @return whether or not this is a brand plugin message */ - public static boolean isMcBrand(PluginMessage message) { + public static boolean isMcBrand(PluginMessagePacket message) { checkNotNull(message, "message"); return message.getChannel().equals(BRAND_CHANNEL_LEGACY) || message.getChannel() .equals(BRAND_CHANNEL); @@ -45,7 +45,7 @@ public final class PluginMessageUtil { * @param message the plugin message * @return whether we are registering plugin channels or not */ - public static boolean isRegister(PluginMessage message) { + public static boolean isRegister(PluginMessagePacket message) { checkNotNull(message, "message"); return message.getChannel().equals(REGISTER_CHANNEL_LEGACY) || message.getChannel() .equals(REGISTER_CHANNEL); @@ -56,7 +56,7 @@ public final class PluginMessageUtil { * @param message the plugin message * @return whether we are unregistering plugin channels or not */ - public static boolean isUnregister(PluginMessage message) { + public static boolean isUnregister(PluginMessagePacket message) { checkNotNull(message, "message"); return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY) || message.getChannel() .equals(UNREGISTER_CHANNEL); @@ -67,7 +67,7 @@ public final class PluginMessageUtil { * @param message the plugin message * @return whether this is a legacy register message */ - public static boolean isLegacyRegister(PluginMessage message) { + public static boolean isLegacyRegister(PluginMessagePacket message) { checkNotNull(message, "message"); return message.getChannel().equals(REGISTER_CHANNEL_LEGACY); } @@ -78,7 +78,7 @@ public final class PluginMessageUtil { * @param message the plugin message * @return whether this is a legacy unregister message */ - public static boolean isLegacyUnregister(PluginMessage message) { + public static boolean isLegacyUnregister(PluginMessagePacket message) { checkNotNull(message, "message"); return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY); } @@ -88,7 +88,7 @@ public final class PluginMessageUtil { * @param message the message to get the channels from * @return the channels, as an immutable list */ - public static List getChannels(PluginMessage message) { + public static List getChannels(PluginMessagePacket message) { checkNotNull(message, "message"); checkArgument(isRegister(message) || isUnregister(message), "Unknown channel type %s", message.getChannel()); @@ -107,15 +107,15 @@ public final class PluginMessageUtil { * @param channels the channels to register * @return the plugin message to send */ - public static PluginMessage constructChannelsPacket(ProtocolVersion protocolVersion, - Collection channels) { + public static PluginMessagePacket constructChannelsPacket(ProtocolVersion protocolVersion, + Collection channels) { checkNotNull(channels, "channels"); checkArgument(!channels.isEmpty(), "no channels specified"); String channelName = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY; ByteBuf contents = Unpooled.buffer(); contents.writeCharSequence(String.join("\0", channels), StandardCharsets.UTF_8); - return new PluginMessage(channelName, contents); + return new PluginMessagePacket(channelName, contents); } /** @@ -124,8 +124,9 @@ public final class PluginMessageUtil { * @param version the proxy version * @return the rewritten plugin message */ - public static PluginMessage rewriteMinecraftBrand(PluginMessage message, ProxyVersion version, - ProtocolVersion protocolVersion) { + public static PluginMessagePacket rewriteMinecraftBrand(PluginMessagePacket message, + ProxyVersion version, + ProtocolVersion protocolVersion) { checkNotNull(message, "message"); checkNotNull(version, "version"); checkArgument(isMcBrand(message), "message is not a brand plugin message"); @@ -140,7 +141,7 @@ public final class PluginMessageUtil { rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8); } - return new PluginMessage(message.getChannel(), rewrittenBuf); + return new PluginMessagePacket(message.getChannel(), rewrittenBuf); } private static String readBrandMessage(ByteBuf content) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index cdc1e2555..b608afcf6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -7,9 +7,9 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.proxy.protocol.packet.Handshake; -import com.velocitypowered.proxy.protocol.packet.StatusRequest; -import com.velocitypowered.proxy.protocol.packet.StatusResponse; +import com.velocitypowered.proxy.protocol.packet.HandshakePacket; +import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; +import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -33,7 +33,7 @@ public class PingSessionHandler implements MinecraftSessionHandler { @Override public void activated() { - Handshake handshake = new Handshake(); + HandshakePacket handshake = new HandshakePacket(); handshake.setNextStatus(StateRegistry.STATUS_ID); SocketAddress address = server.getServerInfo().getAddress(); @@ -49,13 +49,13 @@ public class PingSessionHandler implements MinecraftSessionHandler { connection.delayedWrite(handshake); connection.setState(StateRegistry.STATUS); - connection.delayedWrite(StatusRequest.INSTANCE); + connection.delayedWrite(StatusRequestPacket.INSTANCE); connection.flush(); } @Override - public boolean handle(StatusResponse packet) { + public boolean handle(StatusResponsePacket packet) { // All good! completed = true; connection.close(true); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index ec741287b..65b9df82b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -19,7 +19,7 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; @@ -90,9 +90,9 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, - new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) + new MinecraftDecoder(ProtocolDirection.CLIENTBOUND)) .addLast(MINECRAFT_ENCODER, - new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)); + new MinecraftEncoder(ProtocolDirection.SERVERBOUND)); ch.pipeline().addLast(HANDLER, new MinecraftConnection(ch, server)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index 09c8e5c0b..5a5100b39 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -5,8 +5,8 @@ import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.connection.MinecraftConnection; -import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; -import com.velocitypowered.proxy.protocol.packet.PlayerListItem; +import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket; +import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -31,12 +31,12 @@ public class VelocityTabList implements TabList { net.kyori.adventure.text.Component footer) { Preconditions.checkNotNull(header, "header"); Preconditions.checkNotNull(footer, "footer"); - connection.write(HeaderAndFooter.create(header, footer, connection.getProtocolVersion())); + connection.write(HeaderAndFooterPacket.create(header, footer, connection.getProtocolVersion())); } @Override public void clearHeaderAndFooter() { - connection.write(HeaderAndFooter.reset()); + connection.write(HeaderAndFooterPacket.reset()); } @Override @@ -49,9 +49,9 @@ public class VelocityTabList implements TabList { Preconditions.checkArgument(entry instanceof VelocityTabListEntry, "Not a Velocity tab list entry"); - PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); - connection.write( - new PlayerListItem(PlayerListItem.ADD_PLAYER, Collections.singletonList(packetItem))); + PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry); + connection.write(new PlayerListItemPacket(PlayerListItemPacket.ADD_PLAYER, + Collections.singletonList(packetItem))); entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry); } @@ -61,9 +61,9 @@ public class VelocityTabList implements TabList { TabListEntry entry = entries.remove(uuid); if (entry != null) { - PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); - connection.write( - new PlayerListItem(PlayerListItem.REMOVE_PLAYER, Collections.singletonList(packetItem))); + PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry); + connection.write(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER, + Collections.singletonList(packetItem))); } return Optional.ofNullable(entry); @@ -85,12 +85,12 @@ public class VelocityTabList implements TabList { if (listEntries.isEmpty()) { return; } - List items = new ArrayList<>(listEntries.size()); + List items = new ArrayList<>(listEntries.size()); for (TabListEntry value : listEntries) { - items.add(PlayerListItem.Item.from(value)); + items.add(PlayerListItemPacket.Item.from(value)); } entries.clear(); - connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, items)); + connection.delayedWrite(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER, items)); } @Override @@ -109,19 +109,19 @@ public class VelocityTabList implements TabList { * * @param packet the packet to process */ - public void processBackendPacket(PlayerListItem packet) { + public void processBackendPacket(PlayerListItemPacket packet) { // Packets are already forwarded on, so no need to do that here - for (PlayerListItem.Item item : packet.getItems()) { + for (PlayerListItemPacket.Item item : packet.getItems()) { UUID uuid = item.getUuid(); assert uuid != null : "1.7 tab list entry given to modern tab list handler!"; - if (packet.getAction() != PlayerListItem.ADD_PLAYER && !entries.containsKey(uuid)) { + if (packet.getAction() != PlayerListItemPacket.ADD_PLAYER && !entries.containsKey(uuid)) { // Sometimes UPDATE_GAMEMODE is sent before ADD_PLAYER so don't want to warn here continue; } switch (packet.getAction()) { - case PlayerListItem.ADD_PLAYER: { + case PlayerListItemPacket.ADD_PLAYER: { // ensure that name and properties are available String name = item.getName(); List properties = item.getProperties(); @@ -137,24 +137,24 @@ public class VelocityTabList implements TabList { .build()); break; } - case PlayerListItem.REMOVE_PLAYER: + case PlayerListItemPacket.REMOVE_PLAYER: entries.remove(uuid); break; - case PlayerListItem.UPDATE_DISPLAY_NAME: { + case PlayerListItemPacket.UPDATE_DISPLAY_NAME: { VelocityTabListEntry entry = entries.get(uuid); if (entry != null) { entry.setDisplayNameInternal(item.getDisplayName()); } break; } - case PlayerListItem.UPDATE_LATENCY: { + case PlayerListItemPacket.UPDATE_LATENCY: { VelocityTabListEntry entry = entries.get(uuid); if (entry != null) { entry.setLatencyInternal(item.getLatency()); } break; } - case PlayerListItem.UPDATE_GAMEMODE: { + case PlayerListItemPacket.UPDATE_GAMEMODE: { VelocityTabListEntry entry = entries.get(uuid); if (entry != null) { entry.setGameModeInternal(item.getGameMode()); @@ -170,8 +170,8 @@ public class VelocityTabList implements TabList { void updateEntry(int action, TabListEntry entry) { if (entries.containsKey(entry.getProfile().getId())) { - PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); - connection.write(new PlayerListItem(action, Collections.singletonList(packetItem))); + PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry); + connection.write(new PlayerListItemPacket(action, Collections.singletonList(packetItem))); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java index b11aedc30..5c62b281a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java @@ -3,7 +3,7 @@ package com.velocitypowered.proxy.tablist; import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; -import com.velocitypowered.proxy.protocol.packet.PlayerListItem; +import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; import java.util.Optional; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; @@ -43,7 +43,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setDisplayName(net.kyori.adventure.text.@Nullable Component displayName) { this.displayName = displayName; - tabList.updateEntry(PlayerListItem.UPDATE_DISPLAY_NAME, this); + tabList.updateEntry(PlayerListItemPacket.UPDATE_DISPLAY_NAME, this); return this; } @@ -59,7 +59,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setLatency(int latency) { this.latency = latency; - tabList.updateEntry(PlayerListItem.UPDATE_LATENCY, this); + tabList.updateEntry(PlayerListItemPacket.UPDATE_LATENCY, this); return this; } @@ -75,7 +75,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setGameMode(int gameMode) { this.gameMode = gameMode; - tabList.updateEntry(PlayerListItem.UPDATE_GAMEMODE, this); + tabList.updateEntry(PlayerListItemPacket.UPDATE_GAMEMODE, this); return this; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java index 7e39343ba..aad866bcb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java @@ -4,8 +4,8 @@ import com.google.common.collect.ImmutableList; import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.connection.MinecraftConnection; -import com.velocitypowered.proxy.protocol.packet.PlayerListItem; -import com.velocitypowered.proxy.protocol.packet.PlayerListItem.Item; +import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; +import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket.Item; import java.util.Collections; import java.util.Map; import java.util.Optional; @@ -46,19 +46,19 @@ public class VelocityTabListLegacy extends VelocityTabList { @Override public void clearAll() { for (TabListEntry value : entries.values()) { - connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, - Collections.singletonList(PlayerListItem.Item.from(value)))); + connection.delayedWrite(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER, + Collections.singletonList(PlayerListItemPacket.Item.from(value)))); } entries.clear(); nameMapping.clear(); } @Override - public void processBackendPacket(PlayerListItem packet) { + public void processBackendPacket(PlayerListItemPacket packet) { Item item = packet.getItems().get(0); // Only one item per packet in 1.7 switch (packet.getAction()) { - case PlayerListItem.ADD_PLAYER: + case PlayerListItemPacket.ADD_PLAYER: if (nameMapping.containsKey(item.getName())) { // ADD_PLAYER also used for updating ping VelocityTabListEntry entry = entries.get(nameMapping.get(item.getName())); if (entry != null) { @@ -74,7 +74,7 @@ public class VelocityTabListLegacy extends VelocityTabList { .build()); } break; - case PlayerListItem.REMOVE_PLAYER: + case PlayerListItemPacket.REMOVE_PLAYER: UUID removedUuid = nameMapping.remove(item.getName()); if (removedUuid != null) { entries.remove(removedUuid); @@ -91,11 +91,12 @@ public class VelocityTabListLegacy extends VelocityTabList { void updateEntry(int action, TabListEntry entry) { if (entries.containsKey(entry.getProfile().getId())) { switch (action) { - case PlayerListItem.UPDATE_LATENCY: - case PlayerListItem.UPDATE_DISPLAY_NAME: // Add here because we removed beforehand + case PlayerListItemPacket.UPDATE_LATENCY: + case PlayerListItemPacket.UPDATE_DISPLAY_NAME: // Add here because we removed beforehand connection - .write(new PlayerListItem(PlayerListItem.ADD_PLAYER, // ADD_PLAYER also updates ping - Collections.singletonList(PlayerListItem.Item.from(entry)))); + // ADD_PLAYER also updates ping + .write(new PlayerListItemPacket(PlayerListItemPacket.ADD_PLAYER, + Collections.singletonList(PlayerListItemPacket.Item.from(entry)))); break; default: // Can't do anything else diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index 7552e2202..74cb50925 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -4,6 +4,7 @@ import com.google.common.collect.MapMaker; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.BossBarPacket; import com.velocitypowered.proxy.util.collect.Enum2IntMap; import com.velocitypowered.proxy.util.concurrent.Once; import java.util.Collections; @@ -106,9 +107,9 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - com.velocitypowered.proxy.protocol.packet.BossBar pre116Packet = holder.createTitleUpdate( + BossBarPacket pre116Packet = holder.createTitleUpdate( newName, ProtocolVersion.MINECRAFT_1_15_2); - com.velocitypowered.proxy.protocol.packet.BossBar rgbPacket = holder.createTitleUpdate( + BossBarPacket rgbPacket = holder.createTitleUpdate( newName, ProtocolVersion.MINECRAFT_1_16); for (ConnectedPlayer player : holder.subscribers) { if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { @@ -125,7 +126,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - com.velocitypowered.proxy.protocol.packet.BossBar packet = holder + BossBarPacket packet = holder .createPercentUpdate(newPercent); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); @@ -139,7 +140,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - com.velocitypowered.proxy.protocol.packet.BossBar packet = holder.createColorUpdate(newColor); + BossBarPacket packet = holder.createColorUpdate(newColor); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); } @@ -152,7 +153,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - com.velocitypowered.proxy.protocol.packet.BossBar packet = holder + BossBarPacket packet = holder .createOverlayUpdate(newOverlay); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); @@ -166,7 +167,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - com.velocitypowered.proxy.protocol.packet.BossBar packet = holder.createFlagsUpdate(); + BossBarPacket packet = holder.createFlagsUpdate(); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); } @@ -187,15 +188,14 @@ public class AdventureBossBarManager implements BossBar.Listener { registrationOnce.run(() -> this.bar.addListener(AdventureBossBarManager.this)); } - com.velocitypowered.proxy.protocol.packet.BossBar createRemovePacket() { - return com.velocitypowered.proxy.protocol.packet.BossBar.createRemovePacket(this.id); + BossBarPacket createRemovePacket() { + return BossBarPacket.createRemovePacket(this.id); } - com.velocitypowered.proxy.protocol.packet.BossBar createAddPacket(ProtocolVersion version) { - com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered - .proxy.protocol.packet.BossBar(); + BossBarPacket createAddPacket(ProtocolVersion version) { + BossBarPacket packet = new BossBarPacket(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.ADD); + packet.setAction(BossBarPacket.ADD); packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(bar.name())); packet.setColor(COLORS_TO_PROTOCOL.get(bar.color())); packet.setOverlay(bar.overlay().ordinal()); @@ -204,54 +204,49 @@ public class AdventureBossBarManager implements BossBar.Listener { return packet; } - com.velocitypowered.proxy.protocol.packet.BossBar createPercentUpdate(float newPercent) { - com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered - .proxy.protocol.packet.BossBar(); + BossBarPacket createPercentUpdate(float newPercent) { + BossBarPacket packet = new BossBarPacket(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_PERCENT); + packet.setAction(BossBarPacket.UPDATE_PERCENT); packet.setPercent(newPercent); return packet; } - com.velocitypowered.proxy.protocol.packet.BossBar createColorUpdate(Color color) { - com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered - .proxy.protocol.packet.BossBar(); + BossBarPacket createColorUpdate(Color color) { + BossBarPacket packet = new BossBarPacket(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_NAME); + packet.setAction(BossBarPacket.UPDATE_NAME); packet.setColor(COLORS_TO_PROTOCOL.get(color)); packet.setFlags(serializeFlags(bar.flags())); return packet; } - com.velocitypowered.proxy.protocol.packet.BossBar createTitleUpdate(Component name, - ProtocolVersion version) { - com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered - .proxy.protocol.packet.BossBar(); + BossBarPacket createTitleUpdate(Component name, + ProtocolVersion version) { + BossBarPacket packet = new BossBarPacket(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_NAME); + packet.setAction(BossBarPacket.UPDATE_NAME); packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(name)); return packet; } - com.velocitypowered.proxy.protocol.packet.BossBar createFlagsUpdate() { + BossBarPacket createFlagsUpdate() { return createFlagsUpdate(bar.flags()); } - com.velocitypowered.proxy.protocol.packet.BossBar createFlagsUpdate(Set newFlags) { - com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered - .proxy.protocol.packet.BossBar(); + BossBarPacket createFlagsUpdate(Set newFlags) { + BossBarPacket packet = new BossBarPacket(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_PROPERTIES); + packet.setAction(BossBarPacket.UPDATE_PROPERTIES); packet.setColor(COLORS_TO_PROTOCOL.get(this.bar.color())); packet.setFlags(this.serializeFlags(newFlags)); return packet; } - com.velocitypowered.proxy.protocol.packet.BossBar createOverlayUpdate(Overlay overlay) { - com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered - .proxy.protocol.packet.BossBar(); + BossBarPacket createOverlayUpdate(Overlay overlay) { + BossBarPacket packet = new BossBarPacket(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_PROPERTIES); + packet.setAction(BossBarPacket.UPDATE_PROPERTIES); packet.setOverlay(OVERLAY_TO_PROTOCOL.get(overlay)); return packet; } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java index e1c40091a..a386dbbbc 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java @@ -15,8 +15,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.packet.Handshake; -import com.velocitypowered.proxy.protocol.packet.StatusPing; +import com.velocitypowered.proxy.protocol.packet.HandshakePacket; +import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; import org.junit.jupiter.api.Test; @@ -24,8 +24,8 @@ class PacketRegistryTest { private StateRegistry.PacketRegistry setupRegistry() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolUtils.Direction.CLIENTBOUND); - registry.register(Handshake.class, Handshake::new, + ProtocolDirection.CLIENTBOUND); + registry.register(HandshakePacket.class, HandshakePacket::new, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false)); return registry; @@ -34,9 +34,9 @@ class PacketRegistryTest { @Test void packetRegistryWorks() { StateRegistry.PacketRegistry registry = setupRegistry(); - MinecraftPacket packet = registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0); + Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0); assertNotNull(packet, "Packet was not found in registry"); - assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class"); + assertEquals(HandshakePacket.class, packet.getClass(), "Registry returned wrong class"); assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12).getPacketId(packet), "Registry did not return the correct packet ID"); @@ -45,9 +45,9 @@ class PacketRegistryTest { @Test void packetRegistryLinkingWorks() { StateRegistry.PacketRegistry registry = setupRegistry(); - MinecraftPacket packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0); + Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0); assertNotNull(packet, "Packet was not found in registry"); - assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class"); + assertEquals(HandshakePacket.class, packet.getClass(), "Registry returned wrong class"); assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12_1).getPacketId(packet), "Registry did not return the correct packet ID"); assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_14_2).getPacketId(packet), @@ -61,23 +61,24 @@ class PacketRegistryTest { @Test void failOnNoMappings() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolUtils.Direction.CLIENTBOUND); + ProtocolDirection.CLIENTBOUND); assertThrows(IllegalArgumentException.class, - () -> registry.register(Handshake.class, Handshake::new)); + () -> registry.register(HandshakePacket.class, HandshakePacket::new)); assertThrows(IllegalArgumentException.class, - () -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN).getPacketId(new Handshake())); + () -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN) + .getPacketId(new HandshakePacket())); } @Test void failOnWrongOrder() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolUtils.Direction.CLIENTBOUND); + ProtocolDirection.CLIENTBOUND); assertThrows(IllegalArgumentException.class, - () -> registry.register(Handshake.class, Handshake::new, + () -> registry.register(HandshakePacket.class, HandshakePacket::new, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false))); assertThrows(IllegalArgumentException.class, - () -> registry.register(Handshake.class, Handshake::new, + () -> registry.register(HandshakePacket.class, HandshakePacket::new, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false))); } @@ -85,22 +86,22 @@ class PacketRegistryTest { @Test void failOnDuplicate() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolUtils.Direction.CLIENTBOUND); - registry.register(Handshake.class, Handshake::new, + ProtocolDirection.CLIENTBOUND); + registry.register(HandshakePacket.class, HandshakePacket::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false)); assertThrows(IllegalArgumentException.class, - () -> registry.register(Handshake.class, Handshake::new, + () -> registry.register(HandshakePacket.class, HandshakePacket::new, new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12, false))); assertThrows(IllegalArgumentException.class, - () -> registry.register(StatusPing.class, StatusPing::new, + () -> registry.register(StatusPingPacket.class, StatusPingPacket::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_13, false))); } @Test void shouldNotFailWhenRegisterLatestProtocolVersion() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolUtils.Direction.CLIENTBOUND); - assertDoesNotThrow(() -> registry.register(Handshake.class, Handshake::new, + ProtocolDirection.CLIENTBOUND); + assertDoesNotThrow(() -> registry.register(HandshakePacket.class, HandshakePacket::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS), false))); @@ -109,20 +110,20 @@ class PacketRegistryTest { @Test void registrySuppliesCorrectPacketsByProtocol() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( - ProtocolUtils.Direction.CLIENTBOUND); - registry.register(Handshake.class, Handshake::new, + ProtocolDirection.CLIENTBOUND); + registry.register(HandshakePacket.class, HandshakePacket::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false), new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, false)); - assertEquals(Handshake.class, + assertEquals(HandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass()); - assertEquals(Handshake.class, + assertEquals(HandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0x01).getClass()); - assertEquals(Handshake.class, + assertEquals(HandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_12_2).createPacket(0x01).getClass()); - assertEquals(Handshake.class, + assertEquals(HandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_13).createPacket(0x02).getClass()); - assertEquals(Handshake.class, + assertEquals(HandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_14_2).createPacket(0x02).getClass()); } } \ No newline at end of file