public void setString(String key, String value) { if (value == null) { remove(key); return; } try { compound.getClass().getMethod("setString", String.class, String.class).invoke(compound, key, value); owner.save(); } catch (Exception ex) { ex.printStackTrace(); } }
public NBTListCompound getCompound(int id) { if (type != NBTType.NBTTagCompound) { new Throwable("Using Compound method on a non Compound list!").printStackTrace(); return null; } try { Object compound = ReflectionMethod.LIST_GET.run(listObject, id); return new NBTListCompound(this, compound); } catch (Exception ex) { ex.printStackTrace(); } return null; }
lcomp.setDouble("double1", 0.3333); lcomp.setInteger("int1", 42); lcomp.setString("test1", "test1"); lcomp.setString("test2", "test2"); lcomp.remove("test1"); if (taglist.size() == 1) { lcomp = taglist.getCompound(0); if (lcomp.getKeys().size() != 3) { getLogger().warning("Wrong key amount in Taglist (" + lcomp.getKeys().size() + ")! The Item-NBT-API may not work!"); compatible = false; } else if (!(lcomp.getDouble("double1") == 0.3333 && lcomp.getInteger("int1") == 42 && lcomp.getString("test2").equals("test2") && !lcomp.hasKey("test1"))) { getLogger().warning("One key in the Taglist changed! The Item-NBT-API may not work!"); compatible = false;
public NBTListCompound addCompound() { if (type != NBTType.NBTTagCompound) { new Throwable("Using Compound method on a non Compound list!").printStackTrace(); return null; } try { Object compound = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance(); ReflectionMethod.LIST_ADD.run(listObject, compound); return new NBTListCompound(this, compound); } catch (Exception ex) { ex.printStackTrace(); } return null; }