public void rebuild() { for (String locale : Locale.getLocales()) { if (!localeMeta.containsKey(locale)) localeMeta.put(locale, getLocaleMeta("en_GB")); } for (String locale : Locale.getLocales()) { List<String> lines = getTooltipLines(locale); ItemMeta meta = getLocaleMeta(locale); meta.setDisplayName(lines.get(0)); lines.remove(0); meta.setLore(lines); setLocaleMeta(locale, meta); // item.setItemMeta(meta); } for (Player player : Bukkit.getOnlinePlayers()) { Iterator<ItemStack> it = player.getInventory().iterator(); String locale = Locale.getPlayerLocale(player); while (it.hasNext()) { ItemStack item = it.next(); if (ItemManager.toRPGItem(item) != null) updateItem(item, locale, false); } for (ItemStack item : player.getInventory().getArmorContents()) { if (ItemManager.toRPGItem(item) != null) updateItem(item, locale, false); } } resetRecipe(true); }
public static void updateItem( ItemStack item, String locale, RPGMetadata rpgMeta, boolean updateDurability) { RPGItem rItem = ItemManager.toRPGItem(item); if (rItem == null) return; item.setType(rItem.item.getType()); ItemMeta meta = rItem.getLocaleMeta(locale); if (!(meta instanceof LeatherArmorMeta) && updateDurability) { item.setDurability(rItem.item.getDurability()); } List<String> lore = meta.getLore(); rItem.addExtra(rpgMeta, item, lore); lore.set(0, meta.getLore().get(0) + rpgMeta.toMCString()); meta.setLore(lore); Map<Enchantment, Integer> enchantments = null; if (enchantmentSupport) enchantments = item.getEnchantments(); item.setItemMeta(meta); if (enchantmentSupport) item.addEnchantments(enchantments); }
public void resetRecipe(boolean removeOld) { if (removeOld) { Iterator<Recipe> it = Bukkit.recipeIterator(); while (it.hasNext()) { Recipe recipe = it.next(); RPGItem rpgitem = ItemManager.toRPGItem(recipe.getResult()); if (rpgitem == null) continue; if (rpgitem.getID() == getID()) { it.remove(); } } } if (hasRecipe) { Set<ItemStack> iSet = new HashSet<ItemStack>(); for (ItemStack m : recipe) { iSet.add(m); } ItemStack[] iList = iSet.toArray(new ItemStack[iSet.size()]); item.setItemMeta(getLocaleMeta("en_GB")); ShapedRecipe shapedRecipe = new ShapedRecipe(item); int i = 0; Map<ItemStack, Character> iMap = new HashMap<ItemStack, Character>(); for (ItemStack m : iList) { iMap.put(m, (char) (65 + i)); i++; } iMap.put(null, ' '); StringBuilder out = new StringBuilder(); for (ItemStack m : recipe) { out.append(iMap.get(m)); } String shape = out.toString(); shapedRecipe.shape(shape.substring(0, 3), shape.substring(3, 6), shape.substring(6, 9)); for (Entry<ItemStack, Character> e : iMap.entrySet()) { if (e.getKey() != null) { shapedRecipe.setIngredient( e.getValue(), e.getKey().getType(), e.getKey().getDurability()); } } Bukkit.addRecipe(shapedRecipe); } }