v1.0
This commit is contained in:
parent
5382cf64a0
commit
25182aff4c
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class NBTHelper {
|
|||
}
|
||||
|
||||
public static Object convertNMSNBT(INBT nbt) {
|
||||
return nbt.getNMSNBT();
|
||||
return INBT.asNMS(nbt);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user