/** * Gets the level of the specified enchantment on this item stack * * @param ench Enchantment to check * @return Level of the enchantment, or 0 */ public int getEnchantmentLevel(Enchantment ench) { return meta == null ? 0 : meta.getEnchantLevel(ench); }
/** * Checks if this ItemStack contains the given {@link Enchantment} * * @param ench Enchantment to test * @return True if this has the given enchantment */ public boolean containsEnchantment(Enchantment ench) { return meta == null ? false : meta.hasEnchant(ench); }
/** * Gets the book meta currently on the book. * <p> * Note: this is a copy of the book meta. You cannot use this object to * change the existing book meta. * * @return the book meta currently on the book */ public BookMeta getPreviousBookMeta() { return previousBookMeta.clone(); }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link BookMeta}, its title, author, pages and generation are copied; otherwise, the new book * is blank. * @param meta the {@link ItemMeta} to copy */ public GlowMetaBook(ItemMeta meta) { super(meta); if (!(meta instanceof BookMeta)) { return; } BookMeta book = (BookMeta) meta; title = book.getTitle(); author = book.getAuthor(); if (book.hasPages()) { pages = new ArrayList<>(book instanceof GlowMetaBook ? ((GlowMetaBook) book).pages : book.getPages()); filterPages(); } if (hasGeneration()) { this.generation = book.getGeneration().ordinal(); } }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link EnchantmentStorageMeta}, its enchantments are copied; otherwise, the new book has no * enchantments. * @param meta the {@link ItemMeta} to copy */ public GlowMetaEnchantedBook(ItemMeta meta) { super(meta); if (!(meta instanceof EnchantmentStorageMeta)) { return; } EnchantmentStorageMeta book = (EnchantmentStorageMeta) meta; if (book.hasStoredEnchants()) { storedEnchants = new HashMap<>(book instanceof GlowMetaEnchantedBook ? ((GlowMetaEnchantedBook) book).storedEnchants : book.getStoredEnchants()); } }
@Override public Collection<PotionEffect> getEffects() { if (item == null) { return Collections.emptyList(); } ItemMeta meta = item.getItemMeta(); return meta instanceof PotionMeta ? ((PotionMeta) meta).getCustomEffects() : Collections.emptyList(); } }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link FireworkMeta}, its effects and power are copied; otherwise, the new firework has no * effects and zero power. * @param meta the {@link ItemMeta} to copy */ public GlowMetaFirework(ItemMeta meta) { super(meta); if (!(meta instanceof FireworkMeta)) { return; } FireworkMeta firework = (FireworkMeta) meta; effects.addAll(firework instanceof GlowMetaFirework ? ((GlowMetaFirework) firework).effects : firework.getEffects()); power = firework.getPower(); }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link BannerMeta}, its patterns are copied; otherwise, the new banner is blank. * @param meta the {@link ItemMeta} to copy */ public GlowMetaBanner(ItemMeta meta) { super(meta); if (!(meta instanceof BannerMeta)) { return; } BannerMeta banner = (BannerMeta) meta; patterns = banner.getPatterns(); baseColor = banner.getBaseColor(); }
/** * Gets a map containing all enchantments and their levels on this item. * * @return Map of enchantments. */ public Map<Enchantment, Integer> getEnchantments() { return meta == null ? ImmutableMap.<Enchantment, Integer>of() : meta.getEnchants(); }
public ImmutableItemStack(ItemStack stack) throws IllegalArgumentException { super(stack); itemMeta = stack.getItemMeta().clone(); }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link LeatherArmorMeta}, its color is copied; otherwise, the new item is undyed. * @param meta the {@link ItemMeta} to copy */ public GlowMetaLeatherArmor(ItemMeta meta) { super(meta); if (meta instanceof LeatherArmorMeta) { color = ((LeatherArmorMeta) meta).getColor(); } }
/** * Removes the specified {@link Enchantment} if it exists on this * ItemStack * * @param ench Enchantment to remove * @return Previous level, or 0 */ public int removeEnchantment(Enchantment ench) { int level = getEnchantmentLevel(ench); if (level == 0 || meta == null) { return level; } meta.removeEnchant(ench); return level; }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link FireworkEffectMeta}, it is copied fully; otherwise, the {@link FireworkEffect} is * null. * @param meta the {@link ItemMeta} to copy */ public GlowMetaFireworkEffect(ItemMeta meta) { super(meta); if (meta instanceof FireworkEffectMeta) { effect = ((FireworkEffectMeta) meta).getEffect(); } }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link KnowledgeBookMeta}, its recipes are copied; otherwise, the new book is empty. * @param meta the {@link ItemMeta} to copy */ public GlowMetaKnowledgeBook(ItemMeta meta) { super(meta); if (!(meta instanceof KnowledgeBookMeta)) { return; } KnowledgeBookMeta book = (KnowledgeBookMeta) meta; if (book.hasRecipes()) { recipes.addAll(book instanceof GlowMetaKnowledgeBook ? ((GlowMetaKnowledgeBook) book).recipes : book.getRecipes()); } }
@Override public Generation getGeneration() { if (generation == null) { return null; } return Generation.values()[generation]; }
@Override public void setGeneration(Generation generation) { if (generation == null) { this.generation = null; return; } this.generation = generation.ordinal(); }
/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link SpawnEggMeta}, the creature type is copied; if it's a {@link GlowMetaSpawn}, any * custom NBT for the spawned entity is also copied. * @param meta the {@link ItemMeta} to copy */ public GlowMetaSpawn(ItemMeta meta) { super(meta); if (meta instanceof SpawnEggMeta) { this.spawnedType = ((SpawnEggMeta) meta).getSpawnedType(); if (meta instanceof GlowMetaSpawn) { entityTag = ((GlowMetaSpawn) meta).entityTag; } } }
private boolean setItemMeta0(ItemMeta itemMeta, Material material) { if (itemMeta == null) { this.meta = null; return true; } if (!Bukkit.getItemFactory().isApplicable(itemMeta, material)) { return false; } this.meta = Bukkit.getItemFactory().asMetaFor(itemMeta, material); if (this.meta == itemMeta) { this.meta = itemMeta.clone(); } return true; } }
/** * Gets the book meta that the player is attempting to add to the book. * <p> * Note: this is a copy of the proposed new book meta. Use {@link * #setNewBookMeta(BookMeta)} to change what will actually be added to the * book. * * @return the book meta that the player is attempting to add */ public BookMeta getNewBookMeta() { return newBookMeta.clone(); }