mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +01:00
Catch component parsing exceptions separately instead of failing the entire item
This commit is contained in:
parent
d2ca6a82be
commit
8df0c0ae2e
@ -1089,11 +1089,23 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
if (filteredPagesTag != null) {
|
if (filteredPagesTag != null) {
|
||||||
final StringTag filteredPage = filteredPagesTag.getStringTag(String.valueOf(i));
|
final StringTag filteredPage = filteredPagesTag.getStringTag(String.valueOf(i));
|
||||||
if (filteredPage != null) {
|
if (filteredPage != null) {
|
||||||
filtered = jsonToTag(connection, filteredPage);
|
try {
|
||||||
|
filtered = jsonToTag(connection, filteredPage);
|
||||||
|
} catch (final Exception e) {
|
||||||
|
// A 1.20.4 client would display the broken json raw, but a 1.20.5 client would die
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Tag parsedPage = jsonToTag(connection, page);
|
final Tag parsedPage;
|
||||||
|
try {
|
||||||
|
parsedPage = jsonToTag(connection, page);
|
||||||
|
} catch (final Exception e) {
|
||||||
|
// Same as above
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
pages.add(new FilterableComponent(parsedPage, filtered));
|
pages.add(new FilterableComponent(parsedPage, filtered));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1291,13 +1303,22 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
|
|
||||||
final StringTag nameTag = displayTag.getStringTag("Name");
|
final StringTag nameTag = displayTag.getStringTag("Name");
|
||||||
if (nameTag != null) {
|
if (nameTag != null) {
|
||||||
data.set(StructuredDataKey.CUSTOM_NAME, jsonToTag(connection, nameTag));
|
try {
|
||||||
|
final Tag convertedName = jsonToTag(connection, nameTag);
|
||||||
|
data.set(StructuredDataKey.CUSTOM_NAME, convertedName);
|
||||||
|
} catch (final Exception ignored) {
|
||||||
|
// No display name if it fails to parse
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ListTag<StringTag> loreTag = displayTag.getListTag("Lore", StringTag.class);
|
final ListTag<StringTag> loreTag = displayTag.getListTag("Lore", StringTag.class);
|
||||||
if (loreTag != null) {
|
if (loreTag != null) {
|
||||||
// Apply limit as per new network codec. Some servers send these lores to do trickery with shaders
|
// Apply limit as per new network codec. Some servers send these lores to do trickery with shaders
|
||||||
data.set(StructuredDataKey.LORE, loreTag.stream().limit(256).map(t -> jsonToTag(connection, t)).toArray(Tag[]::new));
|
try {
|
||||||
|
data.set(StructuredDataKey.LORE, loreTag.stream().limit(256).map(t -> jsonToTag(connection, t)).toArray(Tag[]::new));
|
||||||
|
} catch (final Exception ignored) {
|
||||||
|
// No lore if any one of them fail to parse
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final NumberTag colorTag = displayTag.getNumberTag("color");
|
final NumberTag colorTag = displayTag.getNumberTag("color");
|
||||||
|
@ -110,14 +110,7 @@ public final class ComponentUtil {
|
|||||||
if (json == null) {
|
if (json == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return to.toTag(from.jsonSerializer.deserialize(json));
|
||||||
try {
|
|
||||||
final ATextComponent component = from.jsonSerializer.deserialize(json);
|
|
||||||
return to.toTag(component);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting component: " + json, e);
|
|
||||||
return new StringTag("<error>");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
|
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
|
||||||
|
Loading…
Reference in New Issue
Block a user