Fix item preview in version >= 1.17

This commit is contained in:
Flowsqy 2021-12-30 10:52:48 +01:00
parent d4cddcab37
commit 8b0bd54a1d
3 changed files with 11 additions and 2 deletions

View File

@ -23,6 +23,11 @@ public interface TextComponentHelper {
player.spigot().sendMessage(component);
}
/**
* Get the 'tag' json object containing the item's data
* @param itemStack The item stack that will be displayed
* @return A string representing a json object of the 'tag'
*/
String getNbt(ItemStack itemStack);
default Consumer<Player> getSendableItemInfo(String message, String itemPlaceHolder, ItemStack itemStack, String productName){

View File

@ -2,12 +2,14 @@ package de.epiceric.shopchest.nms.v1_17_1_R1;
import de.epiceric.shopchest.nms.TextComponentHelper;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class TextComponentHelperImpl implements TextComponentHelper {
@Override
public String getNbt(ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack).save(new CompoundTag()).getAsString();
final Tag tag = CraftItemStack.asNMSCopy(itemStack).save(new CompoundTag()).get("tag");
return tag == null ? null : tag.getAsString();
}
}

View File

@ -2,12 +2,14 @@ package de.epiceric.shopchest.nms.v1_17_R1;
import de.epiceric.shopchest.nms.TextComponentHelper;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class TextComponentHelperImpl implements TextComponentHelper {
@Override
public String getNbt(ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack).save(new CompoundTag()).getAsString();
final Tag tag = CraftItemStack.asNMSCopy(itemStack).save(new CompoundTag()).get("tag");
return tag == null ? null : tag.getAsString();
}
}