public String asNBTString(){ Object comp = NBTReflectionUtil.gettoCompount(getCompound(), this); if(comp == null)return "{}"; return comp.toString(); }
public static String getContent(NBTCompound comp, String key) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return null; Object workingtag = gettoCompount(rootnbttag, comp); Method method; try { method = workingtag.getClass().getMethod("get", String.class); return method.invoke(workingtag, key).toString(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
public static Boolean valideCompound(NBTCompound comp) { Object root = comp.getCompound(); if (root == null) { root = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } return (gettoCompount(root, comp)) != null; }
public static NBTList getList(NBTCompound comp, String key, NBTType type) { Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return null; Object workingtag = gettoCompount(rootnbttag, comp); Method method; try { method = workingtag.getClass().getMethod("getList", String.class, int.class); return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId())); } catch (Exception ex) { ex.printStackTrace(); } return null; }
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 set(NBTCompound comp, String key, Object val) { if (val == null) { remove(comp, key); return; } Object rootnbttag = comp.getCompound(); if (rootnbttag == null) { rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) { new Throwable("InvalideCompound").printStackTrace(); return; } Object workingtag = gettoCompount(rootnbttag, comp); Method method; try { method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz()); method.invoke(workingtag, key, val); comp.setCompound(rootnbttag); } catch (Exception ex) { ex.printStackTrace(); } }
public static void addNBTTagCompound(NBTCompound comp, String name) { if (name == null) { remove(comp, name); return; } Object nbttag = comp.getCompound(); if (nbttag == null) { nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(); } if (!valideCompound(comp)) return; Object workingtag = gettoCompount(nbttag, comp); Method method; try { method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz()); method.invoke(workingtag, name, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance()); comp.setCompound(nbttag); return; } catch (Exception ex) { ex.printStackTrace(); } return; }
@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 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(); } }
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 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); }