Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Catch component parsing exceptions separately instead of failing the entire item
Dieser Commit ist enthalten in:
Ursprung
d2ca6a82be
Commit
8df0c0ae2e
@ -1089,11 +1089,23 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
if (filteredPagesTag != null) {
|
||||
final StringTag filteredPage = filteredPagesTag.getStringTag(String.valueOf(i));
|
||||
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));
|
||||
}
|
||||
|
||||
@ -1291,13 +1303,22 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
|
||||
final StringTag nameTag = displayTag.getStringTag("Name");
|
||||
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);
|
||||
if (loreTag != null) {
|
||||
// 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");
|
||||
|
@ -110,14 +110,7 @@ public final class ComponentUtil {
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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>");
|
||||
}
|
||||
return to.toTag(from.jsonSerializer.deserialize(json));
|
||||
}
|
||||
|
||||
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren