From 6d2ff1a6b9300d6b84bac6c448ed0f23bc75afb0 Mon Sep 17 00:00:00 2001 From: MiGoYAm Date: Fri, 10 Dec 2021 17:28:04 +0100 Subject: [PATCH] Optimize imports and delete command declaration packet --- .../limbo/configuration/LimboConfig.java | 5 +- .../connection/ClientChannelInitializer.java | 2 +- .../limbo/connection/ClientConnection.java | 11 +--- .../connection/pipeline/PacketDecoder.java | 3 +- .../packets/play/PacketDeclareCommands.java | 56 ------------------- .../packets/status/PacketStatusRequest.java | 3 +- .../packets/status/PacketStatusResponse.java | 3 +- .../nanit/limbo/protocol/registry/State.java | 13 +---- 8 files changed, 17 insertions(+), 79 deletions(-) delete mode 100644 src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java diff --git a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java index caea498a..91aa40e3 100644 --- a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java +++ b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java @@ -7,7 +7,10 @@ import ru.nanit.limbo.server.data.*; import ru.nanit.limbo.util.Colors; -import java.io.*; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.net.SocketAddress; import java.nio.file.Files; import java.nio.file.Path; diff --git a/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java b/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java index 827fc999..879eca16 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientChannelInitializer.java @@ -4,9 +4,9 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.handler.timeout.ReadTimeoutHandler; -import ru.nanit.limbo.connection.pipeline.VarIntFrameDecoder; import ru.nanit.limbo.connection.pipeline.PacketDecoder; import ru.nanit.limbo.connection.pipeline.PacketEncoder; +import ru.nanit.limbo.connection.pipeline.VarIntFrameDecoder; import ru.nanit.limbo.connection.pipeline.VarIntLengthEncoder; import ru.nanit.limbo.server.LimboServer; diff --git a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java index 10daaf2c..16ed46d7 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java @@ -10,13 +10,13 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import ru.nanit.limbo.LimboConstants; +import ru.nanit.limbo.connection.pipeline.PacketDecoder; +import ru.nanit.limbo.connection.pipeline.PacketEncoder; import ru.nanit.limbo.protocol.ByteMessage; import ru.nanit.limbo.protocol.PreEncodedPacket; +import ru.nanit.limbo.protocol.packets.PacketHandshake; import ru.nanit.limbo.protocol.packets.login.*; import ru.nanit.limbo.protocol.packets.play.*; -import ru.nanit.limbo.connection.pipeline.PacketDecoder; -import ru.nanit.limbo.connection.pipeline.PacketEncoder; -import ru.nanit.limbo.protocol.packets.PacketHandshake; import ru.nanit.limbo.protocol.packets.status.PacketStatusPing; import ru.nanit.limbo.protocol.packets.status.PacketStatusRequest; import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse; @@ -33,7 +33,6 @@ import java.net.SocketAddress; import java.security.InvalidKeyException; import java.security.MessageDigest; -import java.util.Collections; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; @@ -404,16 +403,12 @@ public static void initPackets(LimboServer server) { info.setGameMode(server.getConfig().getGameMode()); info.setUuid(uuid); - PacketDeclareCommands declareCommands = new PacketDeclareCommands(); - declareCommands.setCommands(Collections.singletonList("limbo")); - PACKET_LOGIN_SUCCESS = PreEncodedPacket.of(loginSuccess); PACKET_JOIN_GAME = PreEncodedPacket.of(joinGame); PACKET_PLUGIN_MESSAGE = PreEncodedPacket.of(pluginMessage); PACKET_PLAYER_ABILITIES = PreEncodedPacket.of(playerAbilities); PACKET_PLAYER_POS = PreEncodedPacket.of(positionAndLook); PACKET_PLAYER_INFO = PreEncodedPacket.of(info); - PACKET_DECLARE_COMMANDS = PreEncodedPacket.of(declareCommands); if (server.getConfig().isUseJoinMessage()) { PacketChatMessage joinMessage = new PacketChatMessage(); diff --git a/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java b/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java index e25eff8e..62d499be 100644 --- a/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java +++ b/src/main/java/ru/nanit/limbo/connection/pipeline/PacketDecoder.java @@ -3,7 +3,8 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; -import ru.nanit.limbo.protocol.*; +import ru.nanit.limbo.protocol.ByteMessage; +import ru.nanit.limbo.protocol.Packet; import ru.nanit.limbo.protocol.registry.State; import ru.nanit.limbo.protocol.registry.Version; import ru.nanit.limbo.util.Logger; diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java deleted file mode 100644 index c804b51f..00000000 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketDeclareCommands.java +++ /dev/null @@ -1,56 +0,0 @@ -package ru.nanit.limbo.protocol.packets.play; - -import ru.nanit.limbo.protocol.ByteMessage; -import ru.nanit.limbo.protocol.PacketOut; -import ru.nanit.limbo.protocol.registry.Version; - -import java.util.List; - -/** - * Packet for 1.13+ - */ -public class PacketDeclareCommands implements PacketOut { - - private List commands; - - public void setCommands(List commands) { - this.commands = commands; - } - - @Override - public void encode(ByteMessage msg, Version version) { - msg.writeVarInt(commands.size() * 2 + 1); // +1 because declaring root node - - // Declare root node - - msg.writeByte(0); - msg.writeVarInt(commands.size()); - - for (int i = 1; i <= commands.size() * 2; i++) { - msg.writeVarInt(i++); - } - - // Declare other commands - - int i = 1; - for (String cmd : commands) { - msg.writeByte(1 | 0x04); - msg.writeVarInt(1); - msg.writeVarInt(i + 1); - msg.writeString(cmd); - i++; - - msg.writeByte(2 | 0x04 | 0x10); - msg.writeVarInt(1); - msg.writeVarInt(i); - msg.writeString("arg"); - msg.writeString("brigadier:string"); - msg.writeVarInt(0); - msg.writeString("minecraft:ask_server"); - i++; - } - - msg.writeVarInt(0); - } - -} diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java index ed18d344..ff3b92ef 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusRequest.java @@ -1,6 +1,7 @@ package ru.nanit.limbo.protocol.packets.status; -import ru.nanit.limbo.protocol.*; +import ru.nanit.limbo.protocol.ByteMessage; +import ru.nanit.limbo.protocol.PacketIn; import ru.nanit.limbo.protocol.registry.Version; public class PacketStatusRequest implements PacketIn { diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java index bacbfd1a..df081426 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/status/PacketStatusResponse.java @@ -1,6 +1,7 @@ package ru.nanit.limbo.protocol.packets.status; -import ru.nanit.limbo.protocol.*; +import ru.nanit.limbo.protocol.ByteMessage; +import ru.nanit.limbo.protocol.PacketOut; import ru.nanit.limbo.protocol.registry.Version; import ru.nanit.limbo.server.LimboServer; diff --git a/src/main/java/ru/nanit/limbo/protocol/registry/State.java b/src/main/java/ru/nanit/limbo/protocol/registry/State.java index cd3350e5..a30c4bd7 100644 --- a/src/main/java/ru/nanit/limbo/protocol/registry/State.java +++ b/src/main/java/ru/nanit/limbo/protocol/registry/State.java @@ -1,18 +1,18 @@ package ru.nanit.limbo.protocol.registry; import ru.nanit.limbo.protocol.Packet; -import ru.nanit.limbo.protocol.packets.*; +import ru.nanit.limbo.protocol.packets.PacketHandshake; import ru.nanit.limbo.protocol.packets.login.*; import ru.nanit.limbo.protocol.packets.play.*; import ru.nanit.limbo.protocol.packets.status.PacketStatusPing; import ru.nanit.limbo.protocol.packets.status.PacketStatusRequest; import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse; -import static ru.nanit.limbo.protocol.registry.Version.*; - import java.util.*; import java.util.function.Supplier; +import static ru.nanit.limbo.protocol.registry.Version.*; + public enum State { HANDSHAKING(0) { @@ -70,13 +70,6 @@ public enum State { map(0x0F, V1_17, V1_18) ); - clientBound.register(PacketDeclareCommands::new, - map(0x11, V1_13, V1_14_4), - map(0x12, V1_15, V1_15_2), - map(0x11, V1_16, V1_16_1), - map(0x10, V1_16_2, V1_16_4), - map(0x12, V1_17, V1_18) - ); clientBound.register(PacketJoinGame::new, map(0x01, V1_8, V1_8), map(0x23, V1_9, V1_12_2),