3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-07-31 17:48:08 +02:00

Better handling of invalid display tags

Dieser Commit ist enthalten in:
Camotoy 2022-01-19 19:44:46 -05:00
Ursprung a6004af083
Commit 6667a53bca
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 8 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -469,9 +469,8 @@ public abstract class ItemTranslator {
public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemMapping mapping, char translationColor) { public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemMapping mapping, char translationColor) {
boolean hasCustomName = false; boolean hasCustomName = false;
if (tag != null) { if (tag != null) {
CompoundTag display = tag.get("display"); if (tag.get("display") instanceof CompoundTag display && display.get("Name") instanceof StringTag tagName) {
if (display != null && display.contains("Name")) { String name = tagName.getValue();
String name = ((StringTag) display.get("Name")).getValue();
// Get the translated name and prefix it with a reset char // Get the translated name and prefix it with a reset char
name = MessageTranslator.convertMessageLenient(name, session.getLocale()); name = MessageTranslator.convertMessageLenient(name, session.getLocale());
@ -491,8 +490,10 @@ public abstract class ItemTranslator {
if (tag == null) { if (tag == null) {
tag = new CompoundTag(""); tag = new CompoundTag("");
} }
CompoundTag display = tag.get("display"); CompoundTag display;
if (display == null) { if (tag.get("display") instanceof CompoundTag oldDisplay) {
display = oldDisplay;
} else {
display = new CompoundTag("display"); display = new CompoundTag("display");
// Add to the new root tag // Add to the new root tag
tag.put(display); tag.put(display);

Datei anzeigen

@ -51,13 +51,11 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
} }
} }
CompoundTag displayTag = itemTag.get("display"); if (!(itemTag.get("display") instanceof CompoundTag displayTag)) {
if (displayTag == null) {
return; return;
} }
Tag loreTag = displayTag.get("Lore"); if (displayTag.get("Lore") instanceof ListTag listTag) {
if (loreTag instanceof ListTag listTag) {
List<Tag> lore = new ArrayList<>(); List<Tag> lore = new ArrayList<>();
for (Tag tag : listTag.getValue()) { for (Tag tag : listTag.getValue()) {
if (!(tag instanceof StringTag)) continue; if (!(tag instanceof StringTag)) continue;