Skip to content

Commit

Permalink
Fix binary tag holder for adventure <4.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Aug 17, 2024
1 parent 06cc25b commit 52559f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@

public final class BackwardCompatUtil {

public static final boolean IS_4_10_0_OR_NEWER;
public static final boolean IS_4_13_0_OR_NEWER;
public static final boolean IS_4_15_0_OR_NEWER;
public static final boolean IS_4_17_0_OR_NEWER;

static {
boolean is4_10_0OrNewer = false;
try {
// some methods were renamed in 4.10.0
BinaryTagHolder.binaryTagHolder("");
is4_10_0OrNewer = true;
} catch (Throwable ignored) {
}
IS_4_10_0_OR_NEWER = is4_10_0OrNewer;

boolean is4_13_0OrNewer = false;
try {
// translatable fallback support was added in 4.13.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,21 @@ public HoverEvent.ShowItem read(final JsonReader in) throws IOException {
} else if (fieldName.equals(LEGACY_SHOW_ITEM_TAG)) {
final JsonToken token = in.peek();
if (token == JsonToken.STRING || token == JsonToken.NUMBER) {
nbt = BinaryTagHolder.binaryTagHolder(in.nextString());
// packetevents patch start
if (BackwardCompatUtil.IS_4_10_0_OR_NEWER) {
nbt = BinaryTagHolder.binaryTagHolder(in.nextString());
} else {
nbt = BinaryTagHolder.of(in.nextString());
}
// packetevents patch end
} else if (token == JsonToken.BOOLEAN) {
nbt = BinaryTagHolder.binaryTagHolder(String.valueOf(in.nextBoolean()));
// packetevents patch start
if (BackwardCompatUtil.IS_4_10_0_OR_NEWER) {
nbt = BinaryTagHolder.binaryTagHolder(String.valueOf(in.nextBoolean()));
} else {
nbt = BinaryTagHolder.of(String.valueOf(in.nextBoolean()));
}
// packetevents patch end
} else if (token == JsonToken.NULL) {
in.nextNull();
} else {
Expand Down

0 comments on commit 52559f6

Please sign in to comment.