Support 1.20.4

This commit is contained in:
Aust1n46 2024-01-05 17:34:16 -06:00
parent 0dfd13f2de
commit d87c255059
3 changed files with 45 additions and 12 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>mineverse.Aust1n46.chat</groupId> <groupId>mineverse.Aust1n46.chat</groupId>
<artifactId>VentureChat</artifactId> <artifactId>VentureChat</artifactId>
<version>3.6.0</version> <version>3.7.0</version>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url> <url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
<scm> <scm>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url> <url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>

View File

@ -343,15 +343,35 @@ public class Format {
underlined = false; underlined = false;
} }
if (bold) if (bold)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"bold\":true";
} else {
modifier += ",\"bold\":\"true\""; modifier += ",\"bold\":\"true\"";
}
if (obfuscated) if (obfuscated)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"obfuscated\":true";
} else {
modifier += ",\"obfuscated\":\"true\""; modifier += ",\"obfuscated\":\"true\"";
}
if (italic) if (italic)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"italic\":true";
} else {
modifier += ",\"italic\":\"true\""; modifier += ",\"italic\":\"true\"";
}
if (underlined) if (underlined)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"underlined\":true";
} else {
modifier += ",\"underlined\":\"true\""; modifier += ",\"underlined\":\"true\"";
}
if (strikethrough) if (strikethrough)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"strikethrough\":true";
} else {
modifier += ",\"strikethrough\":\"true\""; modifier += ",\"strikethrough\":\"true\"";
}
remaining = remaining.substring(colorLength); remaining = remaining.substring(colorLength);
colorLength = LEGACY_COLOR_CODE_LENGTH; colorLength = LEGACY_COLOR_CODE_LENGTH;
indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX); indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX);
@ -448,16 +468,20 @@ public class Format {
public static PacketContainer createPacketPlayOutChat(String json) { public static PacketContainer createPacketPlayOutChat(String json) {
final PacketContainer container; 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 = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, json); container.getStrings().write(0, json);
container.getBooleans().write(0, false); 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); WrappedChatComponent component = WrappedChatComponent.fromJson(json);
container = new PacketContainer(PacketType.Play.Server.CHAT); container = new PacketContainer(PacketType.Play.Server.CHAT);
container.getModifier().writeDefaults(); container.getModifier().writeDefaults();
container.getChatComponents().write(0, component); container.getChatComponents().write(0, component);
} else { } else { // 1.19
container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, json); container.getStrings().write(0, json);
container.getIntegers().write(0, 1); container.getIntegers().write(0, 1);
@ -467,15 +491,19 @@ public class Format {
public static PacketContainer createPacketPlayOutChat(WrappedChatComponent component) { public static PacketContainer createPacketPlayOutChat(WrappedChatComponent component) {
final PacketContainer container; 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 = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, component.getJson()); container.getStrings().write(0, component.getJson());
container.getBooleans().write(0, false); 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 = new PacketContainer(PacketType.Play.Server.CHAT);
container.getModifier().writeDefaults(); container.getModifier().writeDefaults();
container.getChatComponents().write(0, component); container.getChatComponents().write(0, component);
} else { } else { // 1.19
container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, component.getJson()); container.getStrings().write(0, component.getJson());
container.getIntegers().write(0, 1); container.getIntegers().write(0, 1);

View File

@ -7,6 +7,7 @@ public final class VersionHandler {
public static final MinecraftVersion SERVER_VERSION = MinecraftVersion.getCurrentVersion(); 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 = new MinecraftVersion(1, 19, 0);
private static final MinecraftVersion MC1_19_1 = new MinecraftVersion(1, 19, 1); 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() { private VersionHandler() {
} }
@ -74,4 +75,8 @@ public final class VersionHandler {
public static boolean isAbove_1_19() { public static boolean isAbove_1_19() {
return SERVER_VERSION.isAtLeast(MC1_19_1); return SERVER_VERSION.isAtLeast(MC1_19_1);
} }
public static boolean isAtLeast_1_20_4() {
return SERVER_VERSION.isAtLeast(MC1_20_4);
}
} }