Skip to content

Commit 638784e

Browse files
authored
Merge pull request #1403 from Privatech38/fix/revert-5-hover-tag-change
refactor(minimessage): revert change to Hover tag SNBT resolution
2 parents 8c7e647 + cfe857e commit 638784e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

  • text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard

text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/HoverTag.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ public HoverEvent.ShowItem parse(final ArgumentQueue args, final Context ctx) th
129129
final Key key = Key.key(args.popOr("Show item hover needs at least an item ID").value());
130130
final int count = args.hasNext() ? args.pop().asInt().orElseThrow(() -> ctx.newException("The count argument was not a valid integer")) : 1;
131131
if (args.hasNext()) {
132-
// if the value starts with a '{' we assume it's SNBT. The previous behavior of legacy parsing has
133-
// been removed in Adventure 5.0.0.
132+
// Compatibility with legacy versions:
133+
// if the value starts with a '{' we assume it's SNBT, and parse it as such to create a legacy holder
134+
// otherwise, we'll parse argument pairs as a map of ResourceLocation -> SNBT value
134135
final String value = args.peek().value();
135136
if (value.startsWith("{")) {
136-
throw ctx.newException("Legacy SNBT serializing is since Adventure 5.0.0 no longer supported.");
137+
args.pop();
138+
return legacyShowItem(key, count, value);
137139
}
138140

139141
final Map<Key, DataComponentValue> datas = new HashMap<>();
@@ -152,6 +154,10 @@ public HoverEvent.ShowItem parse(final ArgumentQueue args, final Context ctx) th
152154
}
153155
}
154156

157+
private static HoverEvent.ShowItem legacyShowItem(final Key id, final int count, final String value) {
158+
return HoverEvent.ShowItem.showItem(id, count, BinaryTagHolder.binaryTagHolder(value));
159+
}
160+
155161
@Override
156162
public void emit(final HoverEvent.ShowItem event, final TokenEmitter emit) {
157163
emit.argument(compactAsString(event.item()));

0 commit comments

Comments
 (0)