From d87c255059dc2bc9e9feb595b659798334cc145c Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Fri, 5 Jan 2024 17:34:16 -0600 Subject: [PATCH] Support 1.20.4 --- pom.xml | 2 +- .../Aust1n46/chat/utilities/Format.java | 50 +++++++++++++++---- .../chat/versions/VersionHandler.java | 5 ++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index cb75388b..eaf9cb65 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 mineverse.Aust1n46.chat VentureChat - 3.6.0 + 3.7.0 https://bitbucket.org/Aust1n46/venturechat/src/master https://bitbucket.org/Aust1n46/venturechat/src/master diff --git a/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java b/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java index 5afbfb52..c5a5d0b7 100644 --- a/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java +++ b/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java @@ -343,15 +343,35 @@ private static String convertToJsonColors(String s, String extensions) { underlined = false; } if (bold) - modifier += ",\"bold\":\"true\""; + if (VersionHandler.isAtLeast_1_20_4()) { + modifier += ",\"bold\":true"; + } else { + modifier += ",\"bold\":\"true\""; + } if (obfuscated) - modifier += ",\"obfuscated\":\"true\""; + if (VersionHandler.isAtLeast_1_20_4()) { + modifier += ",\"obfuscated\":true"; + } else { + modifier += ",\"obfuscated\":\"true\""; + } if (italic) - modifier += ",\"italic\":\"true\""; + if (VersionHandler.isAtLeast_1_20_4()) { + modifier += ",\"italic\":true"; + } else { + modifier += ",\"italic\":\"true\""; + } if (underlined) - modifier += ",\"underlined\":\"true\""; + if (VersionHandler.isAtLeast_1_20_4()) { + modifier += ",\"underlined\":true"; + } else { + modifier += ",\"underlined\":\"true\""; + } if (strikethrough) - modifier += ",\"strikethrough\":\"true\""; + if (VersionHandler.isAtLeast_1_20_4()) { + modifier += ",\"strikethrough\":true"; + } else { + modifier += ",\"strikethrough\":\"true\""; + } remaining = remaining.substring(colorLength); colorLength = LEGACY_COLOR_CODE_LENGTH; indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX); @@ -448,16 +468,20 @@ public static String formatModerationGUI(String json, Player player, String send public static PacketContainer createPacketPlayOutChat(String json) { final PacketContainer container; - if (VersionHandler.isAbove_1_19()) { + if (VersionHandler.isAtLeast_1_20_4()) { // 1.20.4+ + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getChatComponents().write(0, WrappedChatComponent.fromJson(json)); + container.getBooleans().write(0, false); + } else if (VersionHandler.isAbove_1_19()) { // 1.19.1 -> 1.20.3 container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container.getStrings().write(0, json); container.getBooleans().write(0, false); - } else if (VersionHandler.isUnder_1_19()) { + } else if (VersionHandler.isUnder_1_19()) { // 1.7 -> 1.19 WrappedChatComponent component = WrappedChatComponent.fromJson(json); container = new PacketContainer(PacketType.Play.Server.CHAT); container.getModifier().writeDefaults(); container.getChatComponents().write(0, component); - } else { + } else { // 1.19 container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container.getStrings().write(0, json); container.getIntegers().write(0, 1); @@ -467,15 +491,19 @@ public static PacketContainer createPacketPlayOutChat(String json) { public static PacketContainer createPacketPlayOutChat(WrappedChatComponent component) { final PacketContainer container; - if (VersionHandler.isAbove_1_19()) { + if (VersionHandler.isAtLeast_1_20_4()) { // 1.20.4+ + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getChatComponents().write(0, component); + container.getBooleans().write(0, false); + } else if (VersionHandler.isAbove_1_19()) { // 1.19.1 -> 1.20.3 container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container.getStrings().write(0, component.getJson()); container.getBooleans().write(0, false); - } else if (VersionHandler.isUnder_1_19()) { + } else if (VersionHandler.isUnder_1_19()) { // 1.7 -> 1.19 container = new PacketContainer(PacketType.Play.Server.CHAT); container.getModifier().writeDefaults(); container.getChatComponents().write(0, component); - } else { + } else { // 1.19 container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container.getStrings().write(0, component.getJson()); container.getIntegers().write(0, 1); diff --git a/src/main/java/mineverse/Aust1n46/chat/versions/VersionHandler.java b/src/main/java/mineverse/Aust1n46/chat/versions/VersionHandler.java index 6447bb23..06a3cc4c 100644 --- a/src/main/java/mineverse/Aust1n46/chat/versions/VersionHandler.java +++ b/src/main/java/mineverse/Aust1n46/chat/versions/VersionHandler.java @@ -7,6 +7,7 @@ public final class VersionHandler { public static final MinecraftVersion SERVER_VERSION = MinecraftVersion.getCurrentVersion(); private static final MinecraftVersion MC1_19 = new MinecraftVersion(1, 19, 0); private static final MinecraftVersion MC1_19_1 = new MinecraftVersion(1, 19, 1); + private static final MinecraftVersion MC1_20_4 = new MinecraftVersion(1, 20, 4); private VersionHandler() { } @@ -74,4 +75,8 @@ public static boolean isUnder_1_19() { public static boolean isAbove_1_19() { return SERVER_VERSION.isAtLeast(MC1_19_1); } + + public static boolean isAtLeast_1_20_4() { + return SERVER_VERSION.isAtLeast(MC1_20_4); + } }