From dc6d9367b0d71733a6848e71622dcf4ea0f42ed4 Mon Sep 17 00:00:00 2001 From: Plancke Date: Sun, 21 Oct 2018 22:56:11 +0200 Subject: [PATCH 1/5] Rewrite scoreboard team member names to fix the color changing --- .../Protocol1_13To1_12_2.java | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 381513d4c..ce6707aa5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -30,6 +30,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Particle1_13Type import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.util.GsonUtil; +import java.util.EnumMap; import java.util.Map; // Development of 1.13 support! @@ -96,6 +97,28 @@ public class Protocol1_13To1_12_2 extends Protocol { } }; + // @formatter:off + // These are arbitrary rewrite values, it just needs an invalid color code character. + protected static EnumMap SCOREBOARD_TEAM_NAME_REWRITE = new EnumMap(ChatColor.class) {{ + put(ChatColor.BLACK, ChatColor.COLOR_CHAR + "g"); + put(ChatColor.DARK_BLUE, ChatColor.COLOR_CHAR + "h"); + put(ChatColor.DARK_GREEN, ChatColor.COLOR_CHAR + "i"); + put(ChatColor.DARK_AQUA, ChatColor.COLOR_CHAR + "j"); + put(ChatColor.DARK_RED, ChatColor.COLOR_CHAR + "p"); + put(ChatColor.DARK_PURPLE, ChatColor.COLOR_CHAR + "q"); + put(ChatColor.GOLD, ChatColor.COLOR_CHAR + "s"); + put(ChatColor.GRAY, ChatColor.COLOR_CHAR + "t"); + put(ChatColor.DARK_GRAY, ChatColor.COLOR_CHAR + "u"); + put(ChatColor.BLUE, ChatColor.COLOR_CHAR + "v"); + put(ChatColor.GREEN, ChatColor.COLOR_CHAR + "w"); + put(ChatColor.AQUA, ChatColor.COLOR_CHAR + "x"); + put(ChatColor.RED, ChatColor.COLOR_CHAR + "y"); + put(ChatColor.LIGHT_PURPLE, ChatColor.COLOR_CHAR + "z"); + put(ChatColor.YELLOW, ChatColor.COLOR_CHAR + "!"); + put(ChatColor.WHITE, ChatColor.COLOR_CHAR + "?"); + }}; + // @formatter:on + static { MappingData.init(); } @@ -424,12 +447,41 @@ public class Protocol1_13To1_12_2 extends Protocol { wrapper.write(Type.STRING, ChatRewriter.legacyTextToJson(prefix)); // Prefix wrapper.write(Type.STRING, ChatRewriter.legacyTextToJson(suffix)); // Suffix } + + if (action == 0 || action == 3 || action == 4) { + wrapper.passthrough(Type.INT); // Entity Count + + String[] names = wrapper.read(Type.STRING_ARRAY); // Entities + for (int i = 0; i < names.length; i++) { + names[i] = rewriteTeamMemberName(names[i]); + } + wrapper.write(Type.STRING_ARRAY, names); + } } }); } }); - registerOutgoing(State.PLAY, 0x45, 0x48); + registerOutgoing(State.PLAY, 0x45, 0x48, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + String displayName = wrapper.read(Type.STRING); // Display Name + displayName = rewriteTeamMemberName(displayName); + wrapper.write(Type.STRING, displayName); + + byte action = wrapper.read(Type.BYTE); + wrapper.write(Type.BYTE, action); + wrapper.passthrough(Type.STRING); // Objective Name + if (action != 1) { + wrapper.passthrough(Type.VAR_INT); // Value + } + } + }); + } + }); registerOutgoing(State.PLAY, 0x46, 0x49); registerOutgoing(State.PLAY, 0x47, 0x4A); registerOutgoing(State.PLAY, 0x48, 0x4B); @@ -876,4 +928,18 @@ public class Protocol1_13To1_12_2 extends Protocol { return ChatColor.RESET; } + + protected String rewriteTeamMemberName(String name) { + // The Display Name is just colours which overwrites the suffix + // It also overwrites for ANY colour in name but most plugins + // will just send colour as 'invisible' character + if (ChatColor.stripColor(name).length() == 0) { + ChatColor color = ChatColor.getByChar(name.charAt(1)); + String newName = SCOREBOARD_TEAM_NAME_REWRITE.get(color); + if (newName != null) { // just in case + name = newName; + } + } + return name; + } } From 7d5c59aa34e71f84915696b3bb5cb94530bd137f Mon Sep 17 00:00:00 2001 From: Plancke Date: Sun, 21 Oct 2018 23:06:24 +0200 Subject: [PATCH 2/5] Don't read the array size --- .../protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index ce6707aa5..95e6dd4c6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -449,8 +449,6 @@ public class Protocol1_13To1_12_2 extends Protocol { } if (action == 0 || action == 3 || action == 4) { - wrapper.passthrough(Type.INT); // Entity Count - String[] names = wrapper.read(Type.STRING_ARRAY); // Entities for (int i = 0; i < names.length; i++) { names[i] = rewriteTeamMemberName(names[i]); From 81514e4192b78ed28a9d9ee4f4d3eaa606a1d86d Mon Sep 17 00:00:00 2001 From: Plancke Date: Sun, 21 Oct 2018 23:19:54 +0200 Subject: [PATCH 3/5] convert every color in the name --- .../protocol1_13to1_12_2/Protocol1_13To1_12_2.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 95e6dd4c6..f775508d5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -932,11 +932,17 @@ public class Protocol1_13To1_12_2 extends Protocol { // It also overwrites for ANY colour in name but most plugins // will just send colour as 'invisible' character if (ChatColor.stripColor(name).length() == 0) { - ChatColor color = ChatColor.getByChar(name.charAt(1)); - String newName = SCOREBOARD_TEAM_NAME_REWRITE.get(color); - if (newName != null) { // just in case - name = newName; + StringBuilder newName = new StringBuilder(); + for (int i = 0; i < name.length() / 2; i++) { + ChatColor color = ChatColor.getByChar(name.charAt(i * 2 + 1)); + String rewrite = SCOREBOARD_TEAM_NAME_REWRITE.get(color); + if (rewrite != null) { // just in case, should never happen + newName.append(rewrite); + } else { + newName.append(name); + } } + name = newName.toString(); } return name; } From 0b7e4381288a0edf2bb4ba10eefb0a397ebaa1e2 Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Mon, 22 Oct 2018 11:29:22 +0200 Subject: [PATCH 4/5] fix #1044 --- .../protocol1_13_1to1_13/Protocol1_13_1To1_13.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java index 84cebc820..ff162030d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java @@ -44,6 +44,13 @@ public class Protocol1_13_1To1_13 extends Protocol { public void registerMap() { map(Type.FLAT_ITEM); map(Type.BOOLEAN); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item item = wrapper.get(Type.FLAT_ITEM, 0); + InventoryPackets.toServer(item); + } + }); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { From 162d6aa33af4e69992735e9c487330cf3d41fb5b Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Mon, 22 Oct 2018 15:18:23 +0200 Subject: [PATCH 5/5] 1.13.2 support --- .../java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index ecffe5b36..be8d588d4 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -65,7 +65,7 @@ public class ProtocolVersion { register(v1_12_2 = new ProtocolVersion(340, "1.12.2")); register(v1_13 = new ProtocolVersion(393, "1.13")); register(v1_13_1 = new ProtocolVersion(401, "1.13.1")); - register(v1_13_2 = new ProtocolVersion(403, "1.13.2")); + register(v1_13_2 = new ProtocolVersion(404, "1.13.2")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); }