Skip to content

Commit d65b2ab

Browse files
committed
Ignore invalid data in signs
1 parent 03313a1 commit d65b2ab

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

common/src/main/java/com/viaversion/viaversion/protocols/v1_21_4to1_21_5/rewriter/BlockItemPacketRewriter1_21_5.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ private void updateSignMessages(final UserConnection connection, final CompoundT
305305
}
306306

307307
final ListTag<StringTag> messages = tag.getListTag("messages", StringTag.class);
308-
tag.put("messages", protocol.getComponentRewriter().updateComponentList(connection, messages));
308+
tag.put("messages", protocol.getComponentRewriter().updateComponentList(connection, messages, true));
309309

310310
final ListTag<StringTag> filteredMessages = tag.getListTag("filtered_messages", StringTag.class);
311311
if (filteredMessages != null) {
312-
tag.put("filtered_messages", protocol.getComponentRewriter().updateComponentList(connection, filteredMessages));
312+
tag.put("filtered_messages", protocol.getComponentRewriter().updateComponentList(connection, filteredMessages, true));
313313
}
314314
}
315315

common/src/main/java/com/viaversion/viaversion/protocols/v1_21_4to1_21_5/rewriter/ComponentRewriter1_21_5.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,22 @@ private void updateUglyJson(final CompoundTag componentsTag, final UserConnectio
248248
final String loreKey = TagUtil.getNamespacedTagKey(componentsTag, "lore");
249249
final ListTag<StringTag> lore = componentsTag.getListTag(loreKey, StringTag.class);
250250
if (lore != null) {
251-
componentsTag.put(loreKey, updateComponentList(connection, lore));
251+
componentsTag.put(loreKey, updateComponentList(connection, lore, false));
252252
}
253253
}
254254

255-
public ListTag<CompoundTag> updateComponentList(final UserConnection connection, final ListTag<StringTag> messages) {
255+
public ListTag<CompoundTag> updateComponentList(final UserConnection connection, final ListTag<StringTag> messages, final boolean skipInvalid) {
256256
final ListTag<CompoundTag> updatedMessages = new ListTag<>(CompoundTag.class);
257257
for (final StringTag message : messages) {
258258
// Convert and make sure they're all of the same type
259-
final Tag output = uglyJsonToTag(connection, message.getValue());
259+
final Tag output;
260+
try {
261+
output = skipInvalid ? uglyJsonToTagUncaught(connection, message.getValue()) : uglyJsonToTag(connection, message.getValue());
262+
} catch (final Exception e) {
263+
// Signs ignore invalid data...
264+
continue;
265+
}
266+
260267
final CompoundTag wrappedComponent = new CompoundTag();
261268
wrappedComponent.putString("text", "");
262269
wrappedComponent.put("extra", new ListTag<>(List.of(output)));
@@ -300,20 +307,22 @@ private void updateShowEntityHover(final UserConnection connection, final Compou
300307
}
301308
}
302309

303-
public Tag uglyJsonToTag(final UserConnection connection, final String value) {
310+
public Tag uglyJsonToTagUncaught(final UserConnection connection, final String value) {
304311
// Use the same version for deserializing and serializing, as we handle the remaining changes ourselves
305-
final Tag contents;
312+
final Tag contents = SerializerVersion.V1_21_4.toTag(SerializerVersion.V1_21_4.toComponent(value));
313+
processTag(connection, contents);
314+
return contents;
315+
}
316+
317+
public Tag uglyJsonToTag(final UserConnection connection, final String value) {
306318
try {
307-
contents = SerializerVersion.V1_21_4.toTag(SerializerVersion.V1_21_4.toComponent(value));
319+
return uglyJsonToTagUncaught(connection, value);
308320
} catch (final Exception e) {
309321
if (!Via.getConfig().isSuppressConversionWarnings()) {
310322
Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting json text component: " + value, e);
311323
}
312324
return new StringTag("<error>");
313325
}
314-
315-
processTag(connection, contents);
316-
return contents;
317326
}
318327

319328
@Override

0 commit comments

Comments
 (0)