Skip to content

Commit

Permalink
fix(text-serializer-gson): Only emit legacy show achievement as part …
Browse files Browse the repository at this point in the history
…of legacy hover values
  • Loading branch information
zml2008 committed Jun 7, 2023
1 parent 27f6aa9 commit 37f030b
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,17 @@ public void write(final JsonWriter out, final Style value) throws IOException {
out.name(HOVER_EVENT_ACTION);
final HoverEvent.Action<?> action = hoverEvent.action();
this.gson.toJson(action, SerializerFactory.HOVER_ACTION_TYPE, out);
out.name(HOVER_EVENT_CONTENTS);
if (action == HoverEvent.Action.SHOW_ITEM) {
this.gson.toJson(hoverEvent.value(), SerializerFactory.SHOW_ITEM_TYPE, out);
} else if (action == HoverEvent.Action.SHOW_ENTITY) {
this.gson.toJson(hoverEvent.value(), SerializerFactory.SHOW_ENTITY_TYPE, out);
} else if (action == HoverEvent.Action.SHOW_TEXT) {
this.gson.toJson(hoverEvent.value(), SerializerFactory.COMPONENT_TYPE, out);
} else if (action == HoverEvent.Action.SHOW_ACHIEVEMENT) {
this.gson.toJson(hoverEvent.value(), SerializerFactory.STRING_TYPE, out);
} else {
throw new JsonParseException("Don't know how to serialize " + hoverEvent.value());
if (action != HoverEvent.Action.SHOW_ACHIEVEMENT) { // legacy action has no modern contents value
out.name(HOVER_EVENT_CONTENTS);
if (action == HoverEvent.Action.SHOW_ITEM) {
this.gson.toJson(hoverEvent.value(), SerializerFactory.SHOW_ITEM_TYPE, out);
} else if (action == HoverEvent.Action.SHOW_ENTITY) {
this.gson.toJson(hoverEvent.value(), SerializerFactory.SHOW_ENTITY_TYPE, out);
} else if (action == HoverEvent.Action.SHOW_TEXT) {
this.gson.toJson(hoverEvent.value(), SerializerFactory.COMPONENT_TYPE, out);
} else {
throw new JsonParseException("Don't know how to serialize " + hoverEvent.value());
}
}
if (this.emitLegacyHover) {
out.name(HOVER_EVENT_VALUE);
Expand All @@ -306,6 +306,8 @@ public void write(final JsonWriter out, final Style value) throws IOException {
private void serializeLegacyHoverEvent(final HoverEvent<?> hoverEvent, final JsonWriter out) throws IOException {
if (hoverEvent.action() == HoverEvent.Action.SHOW_TEXT) { // serialization is the same
this.gson.toJson(hoverEvent.value(), SerializerFactory.COMPONENT_TYPE, out);
} else if (hoverEvent.action() == HoverEvent.Action.SHOW_ACHIEVEMENT) {
this.gson.toJson(hoverEvent.value(), String.class, out);
} else if (this.legacyHover != null) { // for data formats that require knowledge of SNBT
Component serialized = null;
try {
Expand Down

0 comments on commit 37f030b

Please sign in to comment.