public static void remove(NBTCompound comp, String key) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(rootnbttag, comp); ReflectionMethod.COMPOUND_REMOVE_KEY.run(workingtag, key); comp.setCompound(rootnbttag); }
public static Boolean valideCompound(NBTCompound comp) { Object root = comp.getCompound(); if (root == null) { root = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } return (gettoCompount(root, comp)) != null; }
public NBTCompound getCompound(String name) { NBTCompound next = new NBTCompound(this, name); if (NBTReflectionUtil.valideCompound(next)) return next; return null; }
public NBTCompound addCompound(String name) { if(getType(name) == NBTType.NBTTagCompound)return getCompound(name); NBTReflectionUtil.addNBTTagCompound(this, name); return getCompound(name); }
public NBTType getType(String name) { if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) return null; Object o = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_TYPE, name); if(o == null)return null; return NBTType.valueOf((byte) o); }
public NBTFile(File file) throws IOException { super(null, null); this.file = file; if (file.exists()) { FileInputStream inputsteam = new FileInputStream(file); nbt = NBTReflectionUtil.readNBTFile(inputsteam); } else { nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); save(); } }
public static NBTContainer convertItemtoNBT(ItemStack item){ return NBTReflectionUtil.convertNMSItemtoNBTCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, item)); }
public static ItemStack convertNBTtoItem(NBTCompound comp){ return (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp)); }
/** * This may return true even when the NBT is empty. * * @return Does the ItemStack have a NBTCompound. */ public boolean hasNBTData(){ return getCompound() != null; }
protected Object getCompound() { return NBTReflectionUtil.getItemRootNBTTagCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem)); }
public String asNBTString(){ Object comp = NBTReflectionUtil.gettoCompount(getCompound(), this); if(comp == null)return "{}"; return comp.toString(); }
public Boolean hasKey(String key) { Boolean b = (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_HAS_KEY, key); if(b == null)return false; return b; }
public NBTContainer() { super(null, null); nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); }
@SuppressWarnings("unchecked") public static Set<String> getKeys(NBTCompound comp) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return null; Object workingtag = gettoCompount(rootnbttag, comp); return (Set<String>) ReflectionMethod.COMPOUND_GET_KEYS.run(workingtag); }
public static Object getData(NBTCompound comp, ReflectionMethod type, String key) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { return null; } if (!valideCompound(comp)) return null; Object workingtag = gettoCompount(rootnbttag, comp); return type.run(workingtag, key); }
public static void setData(NBTCompound comp, ReflectionMethod type, String key, Object data) { if (data == null) { remove(comp, key); return; } Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(rootnbttag, comp); type.run(workingtag, key, data); comp.setCompound(rootnbttag); }
public static void addOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompound) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(rootnbttag, comp); try { ReflectionMethod.COMPOUND_ADD.run(workingtag, nbtcompound.getCompound()); comp.setCompound(rootnbttag); } catch (Exception ex) { ex.printStackTrace(); } }