mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-25 12:45:35 +01:00
Sanity checks in item rewriting
This commit is contained in:
parent
73647ee4fb
commit
483920b729
@ -49,20 +49,22 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
CompoundTag display = item.tag() != null ? item.tag().get("display") : null;
|
CompoundTag display = item.tag() != null ? item.tag().get("display") : null;
|
||||||
if (protocol.getTranslatableRewriter() != null && display != null) {
|
if (protocol.getTranslatableRewriter() != null && display != null) {
|
||||||
// Handle name and lore components
|
// Handle name and lore components
|
||||||
StringTag name = display.get("Name");
|
Tag name = display.get("Name");
|
||||||
if (name != null) {
|
if (name instanceof StringTag) {
|
||||||
String newValue = protocol.getTranslatableRewriter().processText(name.getValue()).toString();
|
StringTag nameStringTag = (StringTag) name;
|
||||||
|
String newValue = protocol.getTranslatableRewriter().processText(nameStringTag.getValue()).toString();
|
||||||
if (!newValue.equals(name.getValue())) {
|
if (!newValue.equals(name.getValue())) {
|
||||||
saveStringTag(display, name, "Name");
|
saveStringTag(display, nameStringTag, "Name");
|
||||||
}
|
}
|
||||||
|
|
||||||
name.setValue(newValue);
|
nameStringTag.setValue(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListTag lore = display.get("Lore");
|
Tag lore = display.get("Lore");
|
||||||
if (lore != null) {
|
if (lore instanceof ListTag) {
|
||||||
|
ListTag loreListTag = (ListTag) lore;
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (Tag loreEntryTag : lore) {
|
for (Tag loreEntryTag : loreListTag) {
|
||||||
if (!(loreEntryTag instanceof StringTag)) {
|
if (!(loreEntryTag instanceof StringTag)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -72,7 +74,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
if (!changed && !newValue.equals(loreEntry.getValue())) {
|
if (!changed && !newValue.equals(loreEntry.getValue())) {
|
||||||
// Backup original lore before doing any modifications
|
// Backup original lore before doing any modifications
|
||||||
changed = true;
|
changed = true;
|
||||||
saveListTag(display, lore, "Lore");
|
saveListTag(display, loreListTag, "Lore");
|
||||||
}
|
}
|
||||||
|
|
||||||
loreEntry.setValue(newValue);
|
loreEntry.setValue(newValue);
|
||||||
|
Loading…
Reference in New Issue
Block a user