forked from GeyserMC/Geyser
Fix Anvil renames by trying a component first then fallback to plain text (#1052)
Closes #1039
This commit is contained in:
parent
b10e5d5af3
commit
11300254f0
1 changed files with 13 additions and 4 deletions
|
@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.inventory;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
import com.nukkitx.nbt.NbtMap;
|
import com.nukkitx.nbt.NbtMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.*;
|
import com.nukkitx.protocol.bedrock.data.inventory.*;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
@ -108,8 +109,12 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
|
||||||
NbtMap tag = itemName.getTag();
|
NbtMap tag = itemName.getTag();
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
String name = tag.getCompound("display").getString("Name");
|
String name = tag.getCompound("display").getString("Name");
|
||||||
|
try {
|
||||||
Component component = GsonComponentSerializer.gson().deserialize(name);
|
Component component = GsonComponentSerializer.gson().deserialize(name);
|
||||||
rename = LegacyComponentSerializer.legacySection().serialize(component);
|
rename = LegacyComponentSerializer.legacySection().serialize(component);
|
||||||
|
} catch (JsonSyntaxException e) {
|
||||||
|
rename = name;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rename = "";
|
rename = "";
|
||||||
}
|
}
|
||||||
|
@ -141,8 +146,12 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
|
||||||
CompoundTag displayTag = tag.get("display");
|
CompoundTag displayTag = tag.get("display");
|
||||||
if (displayTag != null && displayTag.contains("Name")) {
|
if (displayTag != null && displayTag.contains("Name")) {
|
||||||
String itemName = displayTag.get("Name").getValue().toString();
|
String itemName = displayTag.get("Name").getValue().toString();
|
||||||
|
try {
|
||||||
Component component = GsonComponentSerializer.gson().deserialize(itemName);
|
Component component = GsonComponentSerializer.gson().deserialize(itemName);
|
||||||
rename = LegacyComponentSerializer.legacySection().serialize(component);
|
rename = LegacyComponentSerializer.legacySection().serialize(component);
|
||||||
|
} catch (JsonSyntaxException e) {
|
||||||
|
rename = itemName;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rename = "";
|
rename = "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue