Java Code Examples for org.bukkit.inventory.ItemStack#hasItemMeta()
The following examples show how to use
org.bukkit.inventory.ItemStack#hasItemMeta() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnhancedItemListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 6 votes |
/** * Prevents enhanced item from dropping. * * @param e */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onItemDrop(PlayerDropItemEvent e) { Item droppedItem = e.getItemDrop(); ItemStack DroppedItemStack = droppedItem.getItemStack(); Player p = e.getPlayer(); // Checks if the item is a bounded item if ((DroppedItemStack.hasItemMeta()) && (DroppedItemStack.getItemMeta() .getLore() != null)) { if (DroppedItemStack.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor( SettingsManager.lang.getString("lore.untradeableLore")))) { e.setCancelled(true); Util.sendMessage(SettingsManager.lang.getString( "messages.noDrop"), p); } } }
Example 2
Source File: BlockListeners.java From CratesPlus with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent event) { if (!cratesPlus.getConfigHandler().isDisableKeySwapping() || event.getView().getTitle().equals("Claim Crate Keys")) return; if (!event.getInventory().getType().toString().contains("PLAYER") && event.getCurrentItem() != null) { String title; ItemStack item = event.getCurrentItem(); for (Map.Entry<String, Crate> crate : cratesPlus.getConfigHandler().getCrates().entrySet()) { if (!(crate.getValue() instanceof KeyCrate)) { continue; } KeyCrate keyCrate = (KeyCrate) crate.getValue(); Key key = keyCrate.getKey(); if (key == null) continue; title = key.getName(); if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains(title)) { // Send message? event.setCancelled(true); return; } } } }
Example 3
Source File: EnhancedItemListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 6 votes |
/** * Prevents enhanced item from storing. * * @param e */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onInventoryClick(InventoryClickEvent e) { if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) { if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) { ItemStack itemMoved = e.getWhoClicked().getInventory().getItem(e.getHotbarButton()); if ((itemMoved.hasItemMeta()) && (itemMoved.getItemMeta().hasLore())) { if (itemMoved.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) { e.setCancelled(true); Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked()); } } } if (e.getCurrentItem() != null) { if ((e.getCurrentItem().hasItemMeta()) && (e.getCurrentItem().getItemMeta().hasLore())) { if (e.getCurrentItem().getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) { e.setCancelled(true); Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked()); } } } } }
Example 4
Source File: ItemUtils.java From AdditionsAPI with MIT License | 5 votes |
public static String getVisibleName(ItemStack item) { if (item.hasItemMeta()) { ItemMeta meta = item.getItemMeta(); if (meta.hasDisplayName()) { return meta.getDisplayName(); } } return item.getType().toString().toLowerCase(); }
Example 5
Source File: SchematicUtil.java From PlotMe-Core with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private Item getItem(ItemStack is, Byte slot) { byte count = (byte) is.getAmount(); short damage = (short) is.getData().getData(); short itemid = (short) is.getTypeId(); ItemTag itemtag = null; if (is.hasItemMeta()) { List<Ench> enchants = null; ItemMeta im = is.getItemMeta(); Map<Enchantment, Integer> isEnchants = im.getEnchants(); if (isEnchants != null) { enchants = new ArrayList<>(); for (Enchantment ench : isEnchants.keySet()) { enchants.add(new Ench((short) ench.getId(), isEnchants.get(ench).shortValue())); } } List<String> lore = im.getLore(); String name = im.getDisplayName(); Display display = new Display(name, lore); String author = null; String title = null; List<String> pages = null; if (im instanceof BookMeta) { BookMeta bm = (BookMeta) im; author = bm.getAuthor(); title = bm.getTitle(); pages = bm.getPages(); } itemtag = new ItemTag(0, enchants, display, author, title, pages); } return new Item(count, slot, damage, itemid, itemtag); }
Example 6
Source File: Pyro.java From AnnihilationPro with MIT License | 5 votes |
@Override protected boolean isSpecialItem(ItemStack stack) { if(stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) { String name = stack.getItemMeta().getDisplayName(); if(name.contains(getSpecialItemName()) && KitUtils.isSoulbound(stack)) return true; } return false; }
Example 7
Source File: CVItem.java From Civs with GNU General Public License v3.0 | 5 votes |
public static boolean isCivsItem(ItemStack is) { if (is == null || !is.hasItemMeta()) { return false; } ItemMeta im = is.getItemMeta(); if (im == null || im.getDisplayName() == null) { return false; } if (im.getLore() == null || im.getLore().size() < 2 || ItemManager.getInstance().getItemType(im.getLore().get(1)) == null) { return false; } return true; }
Example 8
Source File: SlimefunUtils.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
/** * This method checks whether the given {@link ItemStack} is considered {@link Soulbound}. * * @param item * The {@link ItemStack} to check for * @return Whether the given item is soulbound */ public static boolean isSoulbound(ItemStack item) { if (item == null || item.getType() == Material.AIR) { return false; } else { ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null; if (meta != null && SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) { PersistentDataContainer container = meta.getPersistentDataContainer(); if (container.has(SOULBOUND_KEY, PersistentDataType.BYTE)) { return true; } } if (SlimefunPlugin.getThirdPartySupportService().isEmeraldEnchantsInstalled()) { // We wanna operate on a copy now item = item.clone(); for (ItemEnchantment enchantment : EmeraldEnchants.getInstance().getRegistry().getEnchantments(item)) { EmeraldEnchants.getInstance().getRegistry().applyEnchantment(item, enchantment.getEnchantment(), 0); } } SlimefunItem sfItem = SlimefunItem.getByItem(item); if (sfItem instanceof Soulbound) { return !sfItem.isDisabled(); } else if (meta != null) { return meta.hasLore() && meta.getLore().contains(SOULBOUND_LORE); } return false; } }
Example 9
Source File: EnchantManager.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
public static Boolean hasEnchantments(ItemStack toTest) { if (toTest != null) if (toTest.hasItemMeta() && toTest.getItemMeta().hasLore()) for (String s : toTest.getItemMeta().getLore()) if (containsEnchantment(s)) return true; return false; }
Example 10
Source File: Scorpio.java From AnnihilationPro with MIT License | 5 votes |
private boolean isHookItem(ItemStack stack) { if(stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) { String name = stack.getItemMeta().getDisplayName(); if(name.contains(this.hookItemName) && KitUtils.isSoulbound(stack)) return true; } return false; }
Example 11
Source File: CoolerListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private boolean consumeJuice(Player p, PlayerBackpack backpack) { Inventory inv = backpack.getInventory(); int slot = -1; for (int i = 0; i < inv.getSize(); i++) { ItemStack stack = inv.getItem(i); if (stack != null && stack.getType() == Material.POTION && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) { slot = i; break; } } if (slot >= 0) { PotionMeta im = (PotionMeta) inv.getItem(slot).getItemMeta(); for (PotionEffect effect : im.getCustomEffects()) { p.addPotionEffect(effect); } p.setSaturation(6F); p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1F, 1F); inv.setItem(slot, null); backpack.markDirty(); return true; } return false; }
Example 12
Source File: Assassin.java From AnnihilationPro with MIT License | 5 votes |
@Override protected boolean isSpecialItem(ItemStack stack) { if(stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) { String name = stack.getItemMeta().getDisplayName(); if(name.contains(getSpecialItemName()) && KitUtils.isSoulbound(stack)) return true; } return false; }
Example 13
Source File: Gun.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static int getDurabilityDamage(ItemStack is) { if(is!=null && is.hasItemMeta() && is.getItemMeta().hasLore()) for (String lore : is.getItemMeta().getLore()) { if (ChatColor.stripColor(lore).startsWith(QAMain.S_ITEM_DURIB)) { return Integer.parseInt(lore.split(":")[1].split("/")[0].trim()); } } return -1; }
Example 14
Source File: ItemStackUtils.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
/** * Checks if two items are the same and only amount may be different * * @param itemStack1 item 1 * @param itemStack2 item 2 * @return boolean */ public static boolean isSimilar(ItemStack itemStack1, ItemStack itemStack2) { if(itemStack1 == null && itemStack2 != null || itemStack2 == null) { return false; } if(itemStack1.getType() != itemStack2.getType()) { return false; } if((itemStack1.hasItemMeta() || itemStack2.hasItemMeta()) && !itemStack1.getItemMeta().equals(itemStack2.getItemMeta())) { return false; } if(itemStack1.getDurability() != itemStack2.getDurability()) { return false; } if(!itemStack1.getEnchantments().equals(itemStack2.getEnchantments())) { return false; } if(itemStack1.getMaxStackSize() != itemStack2.getMaxStackSize()) { return false; } return true; }
Example 15
Source File: Methods.java From Crazy-Auctions with MIT License | 5 votes |
public static ItemStack addLore(ItemStack item, List<String> list) { if (item != null && item.getType() != Material.AIR) { ArrayList<String> lore = new ArrayList<>(); ItemMeta m = item.getItemMeta(); if (item.hasItemMeta() && item.getItemMeta().hasLore()) { lore.addAll(item.getItemMeta().getLore()); } for (String i : list) lore.add(color(i)); m.setLore(lore); item.setItemMeta(m); } return item; }
Example 16
Source File: ItemBuilder.java From Crazy-Crates with MIT License | 5 votes |
private ItemStack hideFlags(ItemStack item) { if (hideItemFlags) { if (item != null && item.hasItemMeta()) { ItemMeta itemMeta = item.getItemMeta(); itemMeta.addItemFlags(ItemFlag.values()); item.setItemMeta(itemMeta); return item; } } return item; }
Example 17
Source File: Gun.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static ItemStack removeCalculatedExtra(ItemStack is) { if (is.hasItemMeta() && is.getItemMeta().hasLore()) { ItemMeta im = is.getItemMeta(); List<String> lore = is.getItemMeta().getLore(); for (int i = 0; i < lore.size(); i++) { if (lore.get(i).startsWith(CALCTEXT)) { lore.remove(i); } } im.setLore(lore); is.setItemMeta(im); } return is; }
Example 18
Source File: AutoBrewer.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private MachineRecipe findRecipe(BlockMenu menu) { ItemStack input1 = menu.getItemInSlot(getInputSlots()[0]); ItemStack input2 = menu.getItemInSlot(getInputSlots()[1]); if (input1 == null || input2 == null) { return null; } if (isPotion(input1.getType()) || isPotion(input2.getType())) { boolean slot = isPotion(input1.getType()); ItemStack ingredient = slot ? input2 : input1; // Reject any named items if (ingredient.hasItemMeta()) { return null; } ItemStack potionItem = slot ? input1 : input2; PotionMeta potion = (PotionMeta) potionItem.getItemMeta(); ItemStack output = brew(ingredient.getType(), potionItem.getType(), potion); if (output == null) { return null; } output.setItemMeta(potion); return new MachineRecipe(30, new ItemStack[] { input1, input2 }, new ItemStack[] { output }); } else { return null; } }
Example 19
Source File: Succubus.java From AnnihilationPro with MIT License | 5 votes |
private boolean isSuccubusItem(ItemStack stack) { if(stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) { String name = stack.getItemMeta().getDisplayName(); if(name.contains(this.sucItemName) && KitUtils.isSoulbound(stack)) return true; } return false; }
Example 20
Source File: ItemUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static void updateMetaIfPresent(@Nullable ItemStack item, Consumer<ItemMeta> mutator) { if(item != null && item.hasItemMeta()) { updateMeta(item, mutator); } }