This commit is contained in:
YuTian 2024-07-15 21:02:38 +08:00
parent 5382cf64a0
commit 25182aff4c
9 changed files with 39 additions and 18 deletions

View File

@ -1 +0,0 @@
AuLib

View File

@ -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<Player, ItemStack> consumer) {

View File

@ -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;

View File

@ -33,7 +33,7 @@ public class NBTHelper {
}
public static Object convertNMSNBT(INBT nbt) {
return nbt.getNMSNBT();
return INBT.asNMS(nbt);
}
}

View File

@ -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;

View File

@ -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<NBTCompound> 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));
}
}

View File

@ -3,7 +3,7 @@ package com.io.yutian.aulib.nbt;
import java.util.ArrayList;
import java.util.List;
public class NBTList<T extends INBT> extends INBT {
public class NBTList<T extends INBT> implements INBT {
public static byte TYPE_ID = 9;

View File

@ -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;

View File

@ -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;