diff --git a/ README.md b/ README.md deleted file mode 100644 index 7360054..0000000 --- a/ README.md +++ /dev/null @@ -1 +0,0 @@ -AuLib \ No newline at end of file diff --git a/src/main/java/com/io/yutian/aulib/gui/button/ItemButton.java b/src/main/java/com/io/yutian/aulib/gui/button/ItemButton.java index bbd2da2..3025344 100644 --- a/src/main/java/com/io/yutian/aulib/gui/button/ItemButton.java +++ b/src/main/java/com/io/yutian/aulib/gui/button/ItemButton.java @@ -1,5 +1,7 @@ package com.io.yutian.aulib.gui.button; +import com.io.yutian.aulib.nbt.NBTItem; +import com.io.yutian.aulib.nbt.NBTString; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -18,10 +20,11 @@ public class ItemButton extends Button { public ItemButton(ItemStack itemStack) { super(itemStack); - - NBTItem nbtItem = new NBTItem(item); - nbtItem.setString("gui_meta", "item_button"); - setItemStack(nbtItem.getItem()); + NBTItem nbtItem = new NBTItem(itemStack); + nbtItem.editTag((nbtCompound -> { + nbtCompound.putString("gui_meta", "item_button"); + })); + setItemStack(nbtItem.getItemStack()); } public ItemButton setItem(ItemStack item) { @@ -49,7 +52,7 @@ public class ItemButton extends Button { public boolean isItem(ItemStack item) { NBTItem nbtItem = new NBTItem(item); - return nbtItem.hasTag("gui_meta", NBTType.NBTTagString) && nbtItem.getString("gui_meta").equalsIgnoreCase("item_button"); + return nbtItem.has("gui_meta", NBTString.TYPE_ID) && ((NBTString) nbtItem.get("gui_meta")).getString().equals("item_button"); } public ItemButton clickItem(BiConsumer consumer) { diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java b/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java index 9cf5fd3..a61c438 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTByteArray.java @@ -2,7 +2,7 @@ package com.io.yutian.aulib.nbt; import java.util.Arrays; -public class NBTByteArray extends INBT { +public class NBTByteArray implements INBT { public static byte TYPE_ID = 7; diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTHelper.java b/src/main/java/com/io/yutian/aulib/nbt/NBTHelper.java index 101bdd6..7e70cc6 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTHelper.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTHelper.java @@ -33,7 +33,7 @@ public class NBTHelper { } public static Object convertNMSNBT(INBT nbt) { - return nbt.getNMSNBT(); + return INBT.asNMS(nbt); } } diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java b/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java index b087a20..e04f2c4 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTIntArray.java @@ -1,6 +1,6 @@ package com.io.yutian.aulib.nbt; -public class NBTIntArray extends INBT { +public class NBTIntArray implements INBT { public static byte TYPE_ID = 11; diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTItemStack.java b/src/main/java/com/io/yutian/aulib/nbt/NBTItem.java similarity index 63% rename from src/main/java/com/io/yutian/aulib/nbt/NBTItemStack.java rename to src/main/java/com/io/yutian/aulib/nbt/NBTItem.java index 6b00655..12be16b 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTItemStack.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTItem.java @@ -3,21 +3,24 @@ package com.io.yutian.aulib.nbt; import net.minecraft.nbt.NBTTagCompound; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import javax.annotation.Nullable; import java.util.function.Consumer; -public class NBTItemStack { +public class NBTItem { private ItemStack originalItemStack; private net.minecraft.world.item.ItemStack nmsItemStack; protected ItemStack resultItemStack; - public NBTItemStack(ItemStack itemStack) { + public NBTItem(ItemStack itemStack) { this.originalItemStack = itemStack; this.nmsItemStack = CraftItemStack.asNMSCopy(itemStack); } + @NotNull public NBTCompound getTag() { NBTTagCompound tag = nmsItemStack.u(); if (tag == null) { @@ -26,6 +29,22 @@ public class NBTItemStack { return (NBTCompound) INBT.as(tag); } + public boolean has(String key) { + NBTCompound nbtCompound = getTag(); + return nbtCompound.hasKey(key); + } + + public boolean has(String key, int type) { + NBTCompound nbtCompound = getTag(); + return nbtCompound.hasKey(key, type); + } + + @Nullable + public INBT get(String key) { + NBTCompound nbtCompound = getTag(); + return nbtCompound.hasKey(key) ? nbtCompound.get(key) : null; + } + public void editTag(Consumer consumer) { NBTCompound tag = getTag(); consumer.accept(tag); @@ -49,13 +68,13 @@ public class NBTItemStack { return nmsItemStack; } - public static NBTItemStack build(ItemStack itemStack) { - return new NBTItemStack(itemStack); + public static NBTItem build(ItemStack itemStack) { + return new NBTItem(itemStack); } - public static NBTItemStack build(NBTCompound nbtCompound) { + public static NBTItem build(NBTCompound nbtCompound) { net.minecraft.world.item.ItemStack nmsItemStack = net.minecraft.world.item.ItemStack.a((NBTTagCompound) INBT.asNMS(nbtCompound)); - return new NBTItemStack(CraftItemStack.asBukkitCopy(nmsItemStack)); + return new NBTItem(CraftItemStack.asBukkitCopy(nmsItemStack)); } } diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTList.java b/src/main/java/com/io/yutian/aulib/nbt/NBTList.java index 2bbde58..488513a 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTList.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTList.java @@ -3,7 +3,7 @@ package com.io.yutian.aulib.nbt; import java.util.ArrayList; import java.util.List; -public class NBTList extends INBT { +public class NBTList implements INBT { public static byte TYPE_ID = 9; diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java b/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java index 5231ee7..221ca91 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTLongArray.java @@ -1,6 +1,6 @@ package com.io.yutian.aulib.nbt; -public class NBTLongArray extends INBT { +public class NBTLongArray implements INBT { public static byte TYPE_ID = 12; diff --git a/src/main/java/com/io/yutian/aulib/nbt/NBTString.java b/src/main/java/com/io/yutian/aulib/nbt/NBTString.java index 0c35e12..b20d99d 100644 --- a/src/main/java/com/io/yutian/aulib/nbt/NBTString.java +++ b/src/main/java/com/io/yutian/aulib/nbt/NBTString.java @@ -1,6 +1,6 @@ package com.io.yutian.aulib.nbt; -public class NBTString extends INBT { +public class NBTString implements INBT { public static byte TYPE_ID = 8;