Skip to content

Commit

Permalink
Support 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Aust1n46 committed Jan 5, 2024
1 parent 0dfd13f commit d87c255
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>mineverse.Aust1n46.chat</groupId>
<artifactId>VentureChat</artifactId>
<version>3.6.0</version>
<version>3.7.0</version>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
<scm>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
Expand Down
50 changes: 39 additions & 11 deletions src/main/java/mineverse/Aust1n46/chat/utilities/Format.java
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Expand Up @@ -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() {
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit d87c255

Please sign in to comment.