Skip to content

Commit d6e43de

Browse files
NBTAPI: 1.20 Support for setting sign text
1 parent c52d7e0 commit d6e43de

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.maxgamer.quickshop.shop;
2121

2222
import com.lishid.openinv.IOpenInv;
23+
import de.tr7zw.nbtapi.NBTCompound;
24+
import de.tr7zw.nbtapi.NBTList;
2325
import de.tr7zw.nbtapi.NBTTileEntity;
2426
import io.papermc.lib.PaperLib;
2527
import lombok.EqualsAndHashCode;
@@ -35,6 +37,7 @@
3537
import org.bukkit.block.BlockState;
3638
import org.bukkit.block.Sign;
3739
import org.bukkit.block.data.type.Chest;
40+
import org.bukkit.block.sign.Side;
3841
import org.bukkit.configuration.ConfigurationSection;
3942
import org.bukkit.configuration.file.YamlConfiguration;
4043
import org.bukkit.enchantments.Enchantment;
@@ -72,6 +75,7 @@
7275
import org.maxgamer.quickshop.api.shop.ShopType;
7376
import org.maxgamer.quickshop.chat.platform.minedown.BungeeQuickChat;
7477
import org.maxgamer.quickshop.economy.Trader;
78+
import org.maxgamer.quickshop.util.GameVersion;
7579
import org.maxgamer.quickshop.util.MsgUtil;
7680
import org.maxgamer.quickshop.util.PlayerFinder;
7781
import org.maxgamer.quickshop.util.Util;
@@ -847,9 +851,26 @@ public void setSignText(@NotNull List<ComponentPackage> lines) {
847851
for (Sign sign : signs) {
848852
if (this.plugin.getNbtapi() != null) {
849853
NBTTileEntity tileSign = new NBTTileEntity(sign);
854+
NBTList<String> messageNBTList = null;
855+
if (plugin.getGameVersion().ordinal() >= GameVersion.v1_20_R1.ordinal()) {
856+
NBTCompound frontNBTCompound = tileSign.getCompound("front_text");
857+
if (frontNBTCompound == null) {
858+
// It should never run into there, but just in case
859+
sign.getSide(Side.FRONT).setLine(0, "[Fix]");
860+
sign.update(true);
861+
frontNBTCompound = tileSign.getCompound("front_text");
862+
}
863+
messageNBTList = frontNBTCompound.getStringList("messages");
864+
}
850865
for (int i = 0; i < lines.size(); i++) {
851866
try {
852-
tileSign.setString("Text" + (i + 1), Util.componentsToJson(lines.get(i).getComponents()));
867+
if (plugin.getGameVersion().ordinal() >= GameVersion.v1_20_R1.ordinal()) {
868+
if (messageNBTList != null) {
869+
messageNBTList.set(i, Util.componentsToJson(lines.get(i).getComponents()));
870+
}
871+
} else {
872+
tileSign.setString("Text" + (i + 1), Util.componentsToJson(lines.get(i).getComponents()));
873+
}
853874
} catch (Exception e) {
854875
plugin.getLogger().log(Level.WARNING, "NBTAPI support is broken, dsiable and fallback... (You can safely ignore this)", e);
855876
plugin.disableNBTAPI();

0 commit comments

Comments
 (0)