/** * Create a GlowMetaItem, copying from another if possible. * * @param meta The meta to copy from, or null. */ public GlowMetaItem(ItemMeta meta) { if (meta == null) { return; } displayName = meta.getDisplayName(); if (meta.hasLore()) { lore = new ArrayList<>(meta.getLore()); } if (meta.hasEnchants()) { enchants = new HashMap<>(meta.getEnchants()); } if (meta instanceof GlowMetaItem) { hideFlag = ((GlowMetaItem) meta).hideFlag; } else { for (ItemFlag flag : meta.getItemFlags()) { addItemFlags(flag); } } }
@Override public boolean hasLore() { return im.hasLore(); }
public static boolean hasRPGMetadata(ItemStack item) { if (!item.hasItemMeta()) return false; ItemMeta meta = item.getItemMeta(); if (!meta.hasLore()) return false; List<String> lore = meta.getLore(); return lore.size() != 0 && lore.get(0).contains(METADATA_PREFIX); }
ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); if (itemInMainHand != null && itemInMainHand.hasItemMeta()) { ItemMeta metaOfItemInHand = itemInMainHand.getItemMeta(); if (metaOfItemInHand.hasLore()) { List<String> loreInHand = metaOfItemInHand.getLore(); if(!loreInHand.stream().filter(s -> s.contains("lore")) .collect(Collectors.toList()).isEmpty()) { //do stuff } } }
public static boolean isMcMMOItem(ItemStack item) { if (!item.hasItemMeta()) { return false; } ItemMeta itemMeta = item.getItemMeta(); return itemMeta.hasLore() && itemMeta.getLore().contains("mcMMO Item"); }
ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); if (itemInMainHand != null && itemInMainHand.hasItemMeta()) { ItemMeta metaOfItemInHand = itemInMainHand.getItemMeta(); if (metaOfItemInHand.hasLore()) { List<String> loreInHand = metaOfItemInHand.getLore(); for(String loreLine : loreInHand) { if(loreLine.contains("lore") { //do stuff } } } }
ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); if (itemInMainHand != null && itemInMainHand.hasItemMeta()) { ItemMeta metaOfItemInHand = itemInMainHand.getItemMeta(); if (metaOfItemInHand.hasLore() && String.join(" ", metaOfItemInHand.getLore()).contains("lore")) { //do stuff } }
private List<String> filterLores(ItemStack i) { List<String> ret = new ArrayList<>(); List<PowerLoreFilter> patterns = getPower(PowerLoreFilter.class).stream() .filter(p -> !Strings.isNullOrEmpty(p.regex)) .map(PowerLoreFilter::compile) .collect(Collectors.toList()); if (patterns.isEmpty()) return Collections.emptyList(); if (!i.hasItemMeta() || !i.getItemMeta().hasLore()) return Collections.emptyList(); for (String str : i.getItemMeta().getLore()) { for (PowerLoreFilter p : patterns) { Matcher matcher = p.pattern().matcher(ChatColor.stripColor(str)); if (p.find ? matcher.find() : matcher.matches()) { ret.add(str); break; } } } return ret; }
public static ItemStack delLore(ItemStack is, int line) { ItemMeta meta = is.getItemMeta(); if (meta.hasLore()) { List<String> l = meta.getLore(); if (l.size() >= line) { l.remove(line); meta.setLore(l); is.setItemMeta(meta); } } return is; }
public static ItemStack addLore(ItemStack is, String line) { ItemMeta meta = is.getItemMeta(); List<String> lore = meta.hasLore() ? meta.getLore() : Collections.emptyList(); lore.add(TLocale.Translate.setColored(line)); is.setItemMeta(meta); return is; }
@SuppressWarnings("unchecked") public IconMenuItem setMeta(ItemMeta meta, boolean useTitle, boolean useLore) { this.meta = null; if (useTitle && meta.hasDisplayName()) { this.title = meta.getDisplayName(); hasChanged = true; } if (useLore && meta.hasLore()) { this.lore.clear(); this.lore.addAll(meta.getLore()); hasChanged = true; } if (this.bukkitMeta != meta) { this.bukkitMeta = meta; hasChanged = true; } return this; }
/** * Get the number of uses this circuit has left. * * @param im the ItemMeta to check * @return the number of uses */ private int getUses(ItemMeta im) { int uses = 0; if (im.hasLore()) { List<String> lore = im.getLore(); String stripped = ChatColor.stripColor(lore.get(1)); if (!stripped.equals("unlimited")) { uses = TARDISNumberParsers.parseInt(stripped); } } return uses; } }
public static float getMaxEnergy(ItemStack item) { if (item == null || item.getType() == null || item.getType().equals(Material.AIR)) return 0F; if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F; for (String line: item.getItemMeta().getLore()) { if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) { return Float.valueOf(line.split(" / ")[1].replace(" J", "")); } } return 0F; }
public ItemMetaMock(ItemMeta meta) { if (meta.hasDisplayName()) displayName = meta.getDisplayName(); if (meta.hasLore()) lore = meta.getLore(); }
public static float getStoredEnergy(ItemStack item) { if (item == null || item.getType() == null || item.getType().equals(Material.AIR)) return 0F; if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F; for (String line: item.getItemMeta().getLore()) { if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) { return Float.valueOf(line.split(" / ")[0].replace(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7"), "")); } } return 0F; }
public static boolean hasBiomeDisk(ItemStack[] stack, String biome) { boolean found = false; for (int s = 27; s < stack.length; s++) { ItemStack disk = stack[s]; if (disk != null && disk.hasItemMeta()) { ItemMeta diskim = disk.getItemMeta(); if (diskim.hasLore()) { List<String> lore = diskim.getLore(); if (lore.contains(biome)) { found = true; break; } } } } return found; }
public IconMaker replaceLore(String oldlore, String newlore) { if (this.item != null && this.item.hasItemMeta() && this.item.getItemMeta().hasLore()) { oldlore = ChatColor.translateAlternateColorCodes('&', oldlore); newlore = ChatColor.translateAlternateColorCodes('&', newlore); List<String> colorLore = new ArrayList<>(); for (String l : this.item.getItemMeta().getLore()) { colorLore.add(l.replace(oldlore, newlore)); } ItemMeta m = this.item.getItemMeta(); m.setLore(colorLore); this.item.setItemMeta(m); return this; } return this; }
/** * Checks if the ItemStack is a quest item * * @param item * ItemStack to check * @return true if the supplied ItemStack is a quest item, false otherwise */ public static boolean isQuestItem(ItemStack item) { if (item == null) { return false; } if (item.hasItemMeta() && item.getItemMeta().hasLore() && item.getItemMeta().getLore().contains(Config.getMessage(Config.getLanguage(), "quest_item"))) { return true; } return false; }
public ItemBuilder colored() { if (itemMeta.hasDisplayName()) { itemMeta.setDisplayName(TLocale.Translate.setColored(itemMeta.getDisplayName())); } if (itemMeta.hasLore()) { itemMeta.setLore(TLocale.Translate.setColored(itemMeta.getLore())); } return this; }
public static void removeAbilityBuff(ItemStack item) { if (item == null || item.getType() == Material.AIR || (!ItemUtils.isPickaxe(item) && !ItemUtils.isShovel(item)) || !item.containsEnchantment(Enchantment.DIG_SPEED)) { return; } ItemMeta itemMeta = item.getItemMeta(); if (itemMeta.hasLore()) { List<String> itemLore = itemMeta.getLore(); if (itemLore.remove("mcMMO Ability Tool")) { int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED); if (efficiencyLevel <= AdvancedConfig.getInstance().getEnchantBuff()) { itemMeta.removeEnchant(Enchantment.DIG_SPEED); } else { itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel - AdvancedConfig.getInstance().getEnchantBuff(), true); } itemMeta.setLore(itemLore); item.setItemMeta(itemMeta); } } }