@Nullable public static Integer getSP(ItemStack item) { if (InventoryUtils.isEmpty(item)) return null; String spNode = InventoryUtils.getMetaString(item, "sp"); if (spNode == null) return null; Integer sp = null; try { sp = Integer.parseInt(spNode); } catch (Exception ex) { sp = null; } return sp; }
@Nullable public static String getWandTemplate(ItemStack item) { Object wandNode = getWandOrUpgradeNode(item); if (wandNode == null) return null; return InventoryUtils.getMetaString(wandNode, "template"); }
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 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"); }
@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"); }
public BlockSign(Object tag) { for (int i = 0; i < 4; ++i) { String line = InventoryUtils.getMetaString(tag, "Text" + (i + 1)); if (line != null && !line.startsWith("{")) { try { if (gson == null) { gson = new Gson(); } JsonReader reader = new JsonReader(new StringReader(line)); reader.setLenient(true); line = gson.fromJson(reader, String.class); if (line == null) line = ""; } catch (Exception ex) { Bukkit.getLogger().log(Level.WARNING, "Error loading sign data", ex); line = ""; } } this.lines[i] = line; } }
@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 @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; }
String set = InventoryUtils.getMetaString(item, "brush_set", null); if (set != null) { if (set.equals("schematics")) {
int slotIndex = Integer.parseInt(InventoryUtils.getMetaString(item, "slot")); MageController controller = context.getController(); String unpurchasableMessage = InventoryUtils.getMetaString(item, "unpurchasable"); if (unpurchasableMessage != null && !unpurchasableMessage.isEmpty()) { context.showMessage(unpurchasableMessage);
int slotIndex = Integer.parseInt(InventoryUtils.getMetaString(item, "shop")); MageController controller = context.getController(); Wand wand = mage.getActiveWand(); return; String unpurchasableMessage = InventoryUtils.getMetaString(shopItem.getItem(), "unpurchasable"); if (unpurchasableMessage != null && !unpurchasableMessage.isEmpty()) { context.showMessage(unpurchasableMessage);