@Nullable public static ConfigurationSection itemToConfig(ItemStack item, ConfigurationSection stateNode) { Object wandNode = InventoryUtils.getNode(item, WAND_KEY); if (wandNode == null) { wandNode = InventoryUtils.getNode(item, UPGRADE_KEY); if (wandNode == null) { return null; } } ConfigurationUtils.loadAllTagsFromNBT(stateNode, wandNode); return stateNode; }
public static boolean isBound(ItemStack item) { Object wandSection = InventoryUtils.getNode(item, WAND_KEY); if (wandSection == null) return false; String boundValue = InventoryUtils.getMetaString(wandSection, "owner_id"); return boundValue != null; }
@Nullable public static String getSpell(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; Object spellNode = InventoryUtils.getNode(item, "spell"); if (spellNode == null) return null; return InventoryUtils.getMetaString(spellNode, "key"); }
@Nullable public static String getSpellClass(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; Object spellNode = InventoryUtils.getNode(item, "spell"); if (spellNode == null) return null; return InventoryUtils.getMetaString(spellNode, "class"); }
@Nullable public static String getBrush(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; Object brushNode = InventoryUtils.getNode(item, "brush"); if (brushNode == null) return null; return InventoryUtils.getMetaString(brushNode, "key"); }
@Nullable public static String getWandId(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; Object wandNode = InventoryUtils.getNode(item, WAND_KEY); if (wandNode == null) return null; return InventoryUtils.getMetaString(wandNode, "id"); }
@Nullable public static String getSpellArgs(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; Object spellNode = InventoryUtils.getNode(item, "spell"); if (spellNode == null) return null; return InventoryUtils.getMetaString(spellNode, "args"); }
@Nullable public static Double getCurrencyAmount(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; Object currencyNode = InventoryUtils.getNode(item, "currency"); if (currencyNode == null) return null; return InventoryUtils.getMetaDouble(currencyNode, "amount"); }
@Nullable public static String getCurrencyType(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; Object currencyNode = InventoryUtils.getNode(item, "currency"); if (currencyNode == null) return null; return InventoryUtils.getMetaString(currencyNode, "type"); }
public static boolean isQuickCastSkill(ItemStack item) { if (InventoryUtils.isEmpty(item)) return false; Object spellNode = InventoryUtils.getNode(item, "spell"); if (spellNode == null) return false; Boolean quickCast = InventoryUtils.containsNode(spellNode, "quick_cast") ? InventoryUtils.getMetaBoolean(spellNode, "quick_cast") : null; return quickCast == null ? true : quickCast; }
@Nullable @Override public Object getWandProperty(ItemStack item, String key) { Preconditions.checkNotNull(key, "key"); if (InventoryUtils.isEmpty(item)) return null; Object wandNode = InventoryUtils.getNode(item, Wand.WAND_KEY); if (wandNode == null) return null; Object value = InventoryUtils.getMetaObject(wandNode, key); if (value == null) { WandTemplate template = getWandTemplate(InventoryUtils.getMetaString(wandNode, "template")); if (template != null) { value = template.getProperty(key); } } return value; }
@Override public <T> T getWandProperty(ItemStack item, String key, T defaultValue) { Preconditions.checkNotNull(key, "key"); Preconditions.checkNotNull(defaultValue, "defaultValue"); if (InventoryUtils.isEmpty(item)) { return defaultValue; } Object wandNode = InventoryUtils.getNode(item, Wand.WAND_KEY); if (wandNode == null) { return defaultValue; } // Obtain the type via the default value. // (This is unchecked because of type erasure) @SuppressWarnings("unchecked") Class<? extends T> clazz = (Class<? extends T>) defaultValue.getClass(); // Value directly stored on wand Object value = InventoryUtils.getMetaObject(wandNode, key); if (value != null) { if (clazz.isInstance(value)) { return clazz.cast(value); } return defaultValue; } String tplName = InventoryUtils.getMetaString(wandNode, "template"); WandTemplate template = getWandTemplate(tplName); if (template != null) { return template.getProperty(key, defaultValue); } return defaultValue; }
public static boolean configureSkillItem(ItemStack skillItem, String skillClass, ConfigurationSection skillConfig) { if (skillItem == null) return false; Object handle = getHandle(skillItem); if (handle == null) return false; Object tag = getTag(handle); if (tag == null) return false; setMetaBoolean(tag, "skill", true); if (skillConfig == null) { return true; } if (skillConfig.getBoolean("undroppable", false)) { setMetaBoolean(tag, "undroppable", true); } if (skillConfig.getBoolean("keep", false)) { setMetaBoolean(tag, "keep", true); } boolean quickCast = skillConfig.getBoolean("quick_cast", true); if (skillClass != null || !quickCast) { Object spellNode = InventoryUtils.getNode(skillItem, "spell"); if (spellNode != null) { if (skillClass != null) { InventoryUtils.setMeta(spellNode, "class", skillClass); } if (!quickCast) { InventoryUtils.setMetaBoolean(spellNode, "quick_cast", false); } } } return true; }
node = InventoryUtils.getNode(node, key); } else { InventoryUtils.setMetaTyped(node, key, value);