From 8b1e1f20cf96597bacd421d8bec609e14f6f4c20 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 31 Jul 2018 16:22:21 -0400 Subject: [PATCH] A little more documentation. --- .../api/util/LegacyChatColorUtils.java | 15 ++++++++++++--- .../client/ClientPlaySessionHandler.java | 6 ++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/util/LegacyChatColorUtils.java b/api/src/main/java/com/velocitypowered/api/util/LegacyChatColorUtils.java index 9116a8158..31703fe81 100644 --- a/api/src/main/java/com/velocitypowered/api/util/LegacyChatColorUtils.java +++ b/api/src/main/java/com/velocitypowered/api/util/LegacyChatColorUtils.java @@ -8,11 +8,15 @@ import java.util.regex.Pattern; * LegacyChatColorUtils contains utilities for handling legacy Minecraft color codes. Generally, you should prefer * JSON-based components, but for convenience Velocity provides a limited set of tools to handle Minecraft color codes. */ -public enum LegacyChatColorUtils { - ; +public class LegacyChatColorUtils { + private LegacyChatColorUtils() { + throw new AssertionError(); + } + /** + * Represents the legacy Minecraft format character, the section symbol. + */ public static final char FORMAT_CHAR = '\u00a7'; - private static final Pattern CHAT_COLOR_MATCHER = Pattern.compile("(?i)" + Character.toString(FORMAT_CHAR) + "[0-9A-FL-OR]"); /** * Translates a string with Minecraft color codes prefixed with a different character than the section symbol into @@ -44,6 +48,11 @@ public enum LegacyChatColorUtils { return new String(textChars); } + /** + * A regex that matches all Minecraft color codes and removes them. + */ + private static final Pattern CHAT_COLOR_MATCHER = Pattern.compile("(?i)" + Character.toString(FORMAT_CHAR) + "[0-9A-FL-OR]"); + /** * Removes all Minecraft color codes from the string. * @param text the text to remove color codes from 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 93c251192..8d5ca2ef0 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 @@ -134,11 +134,17 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { idRemapper = EntityIdRemapper.getMapper(joinGame.getEntityId(), player.getConnection().getProtocolVersion()); } else { // In order to handle switching to another server we will need send three packets: + // // - The join game packet from the backend server // - A respawn packet with a different dimension // - Another respawn with the correct dimension + // // We can't simply ignore the packet with the different dimension. If you try to be smart about it it doesn't // work. + // + // Most notably, by having the client accept the join game packet, we can work around the need to perform + // entity ID rewrites, eliminating potential issues from rewriting packets and improving compatibility with + // mods. idRemapper.setServerEntityId(joinGame.getEntityId()); player.getConnection().delayedWrite(joinGame); int tempDim = joinGame.getDimension() == 0 ? -1 : 0;