From 7546270624668e927aaf52b9d10a6ac2cc3d02a9 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 29 Jul 2018 18:39:25 -0400 Subject: [PATCH] Support Minecraft 1.11/1.11.1+ --- .../proxy/protocol/ProtocolConstants.java | 6 ++++++ .../proxy/protocol/StateRegistry.java | 15 +++++++++++---- .../proxy/protocol/netty/MinecraftDecoder.java | 2 +- .../proxy/protocol/netty/MinecraftEncoder.java | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java b/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java index 9c99def6f..fc4a19306 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/ProtocolConstants.java @@ -3,11 +3,17 @@ package com.velocitypowered.proxy.protocol; import java.util.Arrays; public enum ProtocolConstants { ; + public static final int MINECRAFT_1_11 = 315; + public static final int MINECRAFT_1_11_1 = 316; public static final int MINECRAFT_1_12 = 335; public static final int MINECRAFT_1_12_1 = 338; public static final int MINECRAFT_1_12_2 = 340; + public static final int MINIMUM_VERSION_SUPPORTED = MINECRAFT_1_11; + public static final int[] SUPPORTED_VERSIONS = new int[] { + MINECRAFT_1_11, + MINECRAFT_1_11_1, MINECRAFT_1_12, MINECRAFT_1_12_1, MINECRAFT_1_12_2 diff --git a/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java index 18f06b17a..af97c37a5 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -7,9 +7,7 @@ import io.netty.util.collection.IntObjectMap; import java.util.*; import java.util.function.Supplier; -import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12; -import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_1; -import static com.velocitypowered.proxy.protocol.ProtocolConstants.MINECRAFT_1_12_2; +import static com.velocitypowered.proxy.protocol.ProtocolConstants.*; public enum StateRegistry { HANDSHAKE { @@ -34,24 +32,32 @@ public enum StateRegistry { PLAY { { SERVERBOUND.register(Chat.class, Chat::new, + map(0x02, MINECRAFT_1_11), map(0x03, MINECRAFT_1_12), map(0x02, MINECRAFT_1_12_2)); SERVERBOUND.register(KeepAlive.class, KeepAlive::new, + map(0x0B, MINECRAFT_1_11), map(0x0C, MINECRAFT_1_12), map(0x0B, MINECRAFT_1_12_1)); SERVERBOUND.register(ClientSettings.class, ClientSettings::new, + map(0x04, MINECRAFT_1_11), map(0x05, MINECRAFT_1_12), map(0x04, MINECRAFT_1_12_1)); CLIENTBOUND.register(Chat.class, Chat::new, + map(0x0F, MINECRAFT_1_11), map(0x0F, MINECRAFT_1_12)); CLIENTBOUND.register(Disconnect.class, Disconnect::new, + map(0x1A, MINECRAFT_1_11), map(0x1A, MINECRAFT_1_12)); CLIENTBOUND.register(KeepAlive.class, KeepAlive::new, + map(0x1F, MINECRAFT_1_11), map(0x1F, MINECRAFT_1_12)); CLIENTBOUND.register(JoinGame.class, JoinGame::new, + map(0x23, MINECRAFT_1_11), map(0x23, MINECRAFT_1_12)); CLIENTBOUND.register(Respawn.class, Respawn::new, + map(0x33, MINECRAFT_1_11), map(0x34, MINECRAFT_1_12), map(0x35, MINECRAFT_1_12_2)); } @@ -81,6 +87,7 @@ public enum StateRegistry { private static final IntObjectMap LINKED_PROTOCOL_VERSIONS = new IntObjectHashMap<>(); static { + LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_11, new int[] { MINECRAFT_1_11_1 }); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, new int[] { MINECRAFT_1_12_1 }); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12_1, new int[] { MINECRAFT_1_12_2 }); } @@ -204,6 +211,6 @@ public enum StateRegistry { } private static PacketMapping lowestVersion(int id) { - return new PacketMapping(id, MINECRAFT_1_12); + return new PacketMapping(id, MINECRAFT_1_11); } } diff --git a/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java b/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java index 625e68d5b..5e6e6cf90 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java @@ -17,7 +17,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder { public MinecraftDecoder(ProtocolConstants.Direction direction) { this.state = StateRegistry.HANDSHAKE; this.direction = Preconditions.checkNotNull(direction, "direction"); - this.setProtocolVersion(ProtocolConstants.MINECRAFT_1_12); + this.setProtocolVersion(ProtocolConstants.MINIMUM_VERSION_SUPPORTED); } @Override diff --git a/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java b/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java index 833504616..1ccf1e293 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftEncoder.java @@ -17,7 +17,7 @@ public class MinecraftEncoder extends MessageToByteEncoder { public MinecraftEncoder(ProtocolConstants.Direction direction) { this.state = StateRegistry.HANDSHAKE; this.direction = Preconditions.checkNotNull(direction, "direction"); - this.setProtocolVersion(ProtocolConstants.MINECRAFT_1_12); + this.setProtocolVersion(ProtocolConstants.MINIMUM_VERSION_SUPPORTED); } @Override