mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Better handling of invalid display tags
This commit is contained in:
parent
a6004af083
commit
6667a53bca
2 changed files with 8 additions and 9 deletions
|
@ -469,9 +469,8 @@ public abstract class ItemTranslator {
|
|||
public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemMapping mapping, char translationColor) {
|
||||
boolean hasCustomName = false;
|
||||
if (tag != null) {
|
||||
CompoundTag display = tag.get("display");
|
||||
if (display != null && display.contains("Name")) {
|
||||
String name = ((StringTag) display.get("Name")).getValue();
|
||||
if (tag.get("display") instanceof CompoundTag display && display.get("Name") instanceof StringTag tagName) {
|
||||
String name = tagName.getValue();
|
||||
|
||||
// Get the translated name and prefix it with a reset char
|
||||
name = MessageTranslator.convertMessageLenient(name, session.getLocale());
|
||||
|
@ -491,8 +490,10 @@ public abstract class ItemTranslator {
|
|||
if (tag == null) {
|
||||
tag = new CompoundTag("");
|
||||
}
|
||||
CompoundTag display = tag.get("display");
|
||||
if (display == null) {
|
||||
CompoundTag display;
|
||||
if (tag.get("display") instanceof CompoundTag oldDisplay) {
|
||||
display = oldDisplay;
|
||||
} else {
|
||||
display = new CompoundTag("display");
|
||||
// Add to the new root tag
|
||||
tag.put(display);
|
||||
|
|
|
@ -51,13 +51,11 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
|||
}
|
||||
}
|
||||
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag == null) {
|
||||
if (!(itemTag.get("display") instanceof CompoundTag displayTag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Tag loreTag = displayTag.get("Lore");
|
||||
if (loreTag instanceof ListTag listTag) {
|
||||
if (displayTag.get("Lore") instanceof ListTag listTag) {
|
||||
List<Tag> lore = new ArrayList<>();
|
||||
for (Tag tag : listTag.getValue()) {
|
||||
if (!(tag instanceof StringTag)) continue;
|
||||
|
|
Loading…
Reference in a new issue