Java Code Examples for org.bukkit.inventory.ItemStack#getItemMeta()
The following examples show how to use
org.bukkit.inventory.ItemStack#getItemMeta() .
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: ChildrenLeftUnattended.java From UhcCore with GNU General Public License v3.0 | 6 votes |
private void giveTeamReward(Player player){ Wolf wolf = (Wolf) player.getWorld().spawnEntity(player.getLocation(), EntityType.WOLF); wolf.setTamed(true); wolf.setOwner(player); wolf.setAdult(); ItemStack potion = new ItemStack(Material.POTION); PotionMeta meta = (PotionMeta) potion.getItemMeta(); meta.setMainEffect(PotionEffectType.SPEED); PotionEffect potionEffect = new PotionEffect(PotionEffectType.SPEED, 8*60*20, 0); meta.addCustomEffect(potionEffect, true); meta.setDisplayName(ChatColor.WHITE + "Potion of Swiftness"); potion.setItemMeta(meta); player.getWorld().dropItem(player.getLocation(), potion); }
Example 2
Source File: CommandHandler.java From NyaaUtils with MIT License | 6 votes |
@SubCommand(value = "addlore", permission = "nu.setlore") public void addlore(CommandSender sender, Arguments args) { if (!(args.length() > 1)) { msg(sender, "manual.addlore.usage"); return; } String lore = args.next().replace("ยง", ""); Player p = asPlayer(sender); lore = ChatColor.translateAlternateColorCodes('&', lore); ItemStack item = p.getInventory().getItemInMainHand(); if (item == null || item.getType().equals(Material.AIR)) { msg(sender, "user.info.no_item_hand"); return; } String[] line = lore.split("/n"); List<String> lines = item.getItemMeta().getLore() == null ? new ArrayList<>() : item.getItemMeta().getLore(); for (String s : line) { lines.add(ChatColor.translateAlternateColorCodes('&', s)); } ItemMeta itemStackMeta = item.getItemMeta(); itemStackMeta.setLore(lines); item.setItemMeta(itemStackMeta); msg(sender, "user.setlore.success", lore); }
Example 3
Source File: QuickShopItemMatcherImpl.java From QuickShop-Reremake with GNU General Public License v3.0 | 6 votes |
boolean matches(ItemStack requireStack, ItemStack givenStack) { if (requireStack.hasItemMeta() != givenStack.hasItemMeta()) { return false; } if (!requireStack.hasItemMeta()) { return true; // Passed check. no meta need to check. } ItemMeta meta1 = requireStack.getItemMeta(); ItemMeta meta2 = givenStack.getItemMeta(); for (Matcher matcher : matcherList) { if (!matcher.match(meta1, meta2)) { return false; } } return true; }
Example 4
Source File: RedProtectUtil.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean denyPotion(ItemStack result, Player p) { List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_potions; if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) { String potname = ""; if (RedProtect.get().bukkitVersion >= 190) { PotionMeta pot = (PotionMeta) result.getItemMeta(); potname = pot.getBasePotionData().getType().name(); } if (RedProtect.get().bukkitVersion <= 180 && Potion.fromItemStack(result) != null) { potname = Potion.fromItemStack(result).getType().name(); } if (Pots.contains(potname)) { RedProtect.get().lang.sendMessage(p, "playerlistener.denypotion"); return true; } } return false; }
Example 5
Source File: KitParser.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException { int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1); // must be CraftItemStack to keep track of NBT data ItemStack itemStack = CraftItemStack.asCraftCopy(new ItemStack(type, amount, damage)); if (itemStack.getType() != type) { throw new InvalidXMLException("Invalid item/block", el); } ItemMeta meta = itemStack.getItemMeta(); if (meta != null) { // This happens if the item is "air" parseItemMeta(el, meta); itemStack.setItemMeta(meta); } parseCustomNBT(el, itemStack); return itemStack; }
Example 6
Source File: MarkerPlacementManager.java From civcraft with GNU General Public License v2.0 | 6 votes |
public static void addToPlacementMode(Player player, Structure structure, String markerName) throws CivException { if (player.getItemInHand() != null && ItemManager.getId(player.getItemInHand()) != CivData.AIR) { throw new CivException("You must not be holding anything to enter placement mode."); } playersInPlacementMode.put(player.getName(), structure); markers.put(player.getName(), new ArrayList<Location>()); ItemStack stack = ItemManager.createItemStack(CivData.REDSTONE_TORCH_OFF, 2); ItemMeta meta = stack.getItemMeta(); if (markerName != null) { meta.setDisplayName(markerName); } else { meta.setDisplayName("Marker"); } stack.setItemMeta(meta); player.setItemInHand(stack); CivMessage.send(player, "You're now in placement mode for a "+structure.getDisplayName()); }
Example 7
Source File: AutoDisenchanter.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private void transferEnchantments(ItemStack item, ItemStack book, Map<Enchantment, Integer> enchantments) { ItemMeta itemMeta = item.getItemMeta(); ItemMeta bookMeta = book.getItemMeta(); ((Repairable) bookMeta).setRepairCost(((Repairable) itemMeta).getRepairCost()); ((Repairable) itemMeta).setRepairCost(0); item.setItemMeta(itemMeta); book.setItemMeta(bookMeta); EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta(); for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) { item.removeEnchantment(entry.getKey()); meta.addStoredEnchant(entry.getKey(), entry.getValue(), true); } book.setItemMeta(meta); }
Example 8
Source File: Items.java From CardinalPGM with MIT License | 5 votes |
public static ItemStack createBook(Material material, int amount, String name, String author) { ItemStack item = createItem(material, amount, (short) 0, name); BookMeta meta = (BookMeta) item.getItemMeta(); meta.setAuthor(author); meta.setPages(Collections.singletonList("")); item.setItemMeta(meta); return item; }
Example 9
Source File: UhcItems.java From UhcCore with GNU General Public License v3.0 | 5 votes |
public static ItemStack createRegenHead(UhcPlayer player) { String name = player.getName(); ItemStack item = VersionUtils.getVersionUtils().createPlayerSkull(name, player.getUuid()); ItemMeta im = item.getItemMeta(); // Setting up lore with team members im.setLore(Collections.singletonList(Lang.ITEMS_REGEN_HEAD)); im.setDisplayName(name); item.setItemMeta(im); return item; }
Example 10
Source File: TNTCannon.java From Civs with GNU General Public License v3.0 | 5 votes |
@Override public boolean createRegionHandler(Block block, Player player, RegionType regionType) { Location location = block.getLocation(); ItemStack controllerWand = new ItemStack(Material.STICK, 1); ItemMeta im = controllerWand.getItemMeta(); im.setDisplayName("Cannon Controller " + Region.locationToString(location)); controllerWand.setItemMeta(im); location.getWorld().dropItemNaturally(block.getRelative(BlockFace.UP, 2).getLocation(), controllerWand); return true; }
Example 11
Source File: AbstractConfigMenu.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
protected ItemStack createItem(Material icon, int subType, String title, List<String> lore) { ItemStack itemStack = new ItemStack(icon, 1, (short) (subType & 0xff)); ItemMeta meta = itemStack.getItemMeta(); meta.setDisplayName(title); meta.setLore(lore); itemStack.setItemMeta(meta); return itemStack; }
Example 12
Source File: BlockPlacer.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void placeBlock(ItemStack item, Block facedBlock, Dispenser dispenser) { facedBlock.setType(item.getType()); if (item.hasItemMeta()) { ItemMeta meta = item.getItemMeta(); if (meta.hasDisplayName()) { BlockState blockState = facedBlock.getState(); if ((blockState instanceof Nameable)) { ((Nameable) blockState).setCustomName(meta.getDisplayName()); } // Update block state after changing name blockState.update(); } } facedBlock.getWorld().playEffect(facedBlock.getLocation(), Effect.STEP_SOUND, item.getType()); if (dispenser.getInventory().containsAtLeast(item, 2)) { dispenser.getInventory().removeItem(new CustomItem(item, 1)); } else { Slimefun.runSync(() -> dispenser.getInventory().removeItem(item), 2L); } }
Example 13
Source File: AbstractConfigMenu.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
protected ItemStack createItem(String item) { if (item == null) { return null; } Matcher m = UUID_PATTERN.matcher(item); if (m.matches()) { ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD, 1); Bukkit.getUnsafe().modifyItemStack(itemStack, item); ItemMeta itemMeta = itemStack.getItemMeta(); itemMeta.setDisplayName(tr(itemMeta.getDisplayName())); itemStack.setItemMeta(itemMeta); return itemStack; } return null; }
Example 14
Source File: InventoryForVillagerOffers.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
public void updateBottleButton() { ItemStack item = getItem(43); ItemMeta meta = item.getItemMeta(); if (_rewardExp[_selected]) { item.setType(Material.EXPERIENCE_BOTTLE); meta.setDisplayName("XP reward is ON."); } else { item.setType(Material.GLASS_BOTTLE); meta.setDisplayName("XP reward is OFF."); } item.setItemMeta(meta); }
Example 15
Source File: LoreStoreage.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static String getType(ItemStack stack) { ItemMeta meta = stack.getItemMeta(); if (meta.hasLore()) { List<String> lore = meta.getLore(); return lore.get(0); } else { return "none"; } }
Example 16
Source File: ColorChanger.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public static ItemStack changeLeatherArmorColor(ItemStack itemStack, TeamColor color) { Material material = itemStack.getType(); if (material.toString().contains("LEATHER_") && !material.toString().contains("LEATHER_HORSE_")) { LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta(); meta.setColor(color.leatherColor); itemStack.setItemMeta(meta); return itemStack; } return itemStack; }
Example 17
Source File: NMSHandler.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
public ItemStack getItemStack(Material material, List<String> lore, String message) { ItemStack addItem = new ItemStack(material, 1); ItemMeta addItemMeta = addItem.getItemMeta(); addItemMeta.setDisplayName(message); addItemMeta.setLore(lore); addItemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); addItemMeta.addItemFlags(ItemFlag.HIDE_DESTROYS); addItemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); addItemMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); addItemMeta.addItemFlags(ItemFlag.HIDE_PLACED_ON); addItemMeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); addItem.setItemMeta(addItemMeta); return addItem; }
Example 18
Source File: ChallengeLogic.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
public int populateChallengeRank(Inventory menu, final Rank rank, int location, final PlayerInfo playerInfo, boolean isAdminAccess) { List<String> lores = new ArrayList<>(); ItemStack currentChallengeItem = rank.getDisplayItem(); ItemMeta meta4 = currentChallengeItem.getItemMeta(); meta4.setDisplayName("\u00a7e\u00a7l" + tr("Rank: {0}", rank.getName())); lores.add(tr("\u00a7fComplete most challenges in")); lores.add(tr("\u00a7fthis rank to unlock the next rank.")); if (location < (CHALLENGE_PAGESIZE / 2)) { lores.add(tr("\u00a7eClick here to show previous page")); } else { lores.add(tr("\u00a7eClick here to show next page")); } meta4.setLore(lores); currentChallengeItem.setItemMeta(meta4); menu.setItem(location, currentChallengeItem); List<String> missingRankRequirements = rank.getMissingRequirements(playerInfo); for (Challenge challenge : rank.getChallenges()) { if (challenge.getOffset() == -1 && !currentChallengeItem.getItemMeta().hasEnchants()) { continue; // skip } location += challenge.getOffset() + 1; if ((location % 9) == 0) { location++; // Skip rank-row } if (location >= CHALLENGE_PAGESIZE) { break; } lores.clear(); String challengeName = challenge.getName(); try { currentChallengeItem = getItemStack(playerInfo, challengeName); List<String> missingReqs = challenge.getMissingRequirements(playerInfo); if (!missingRankRequirements.isEmpty() || !missingReqs.isEmpty()) { if (!isAdminAccess) { ItemStack locked = challenge.getLockedDisplayItem(); if (locked == null) { locked = lockedItemMap.get(challenge.getType()); } if (locked != null) { currentChallengeItem.setType(locked.getType()); currentChallengeItem.setDurability(locked.getDurability()); } else if (lockedItem != null) { currentChallengeItem.setType(lockedItem.getType()); currentChallengeItem.setDurability(lockedItem.getDurability()); } } else { lores = currentChallengeItem.getItemMeta().getLore(); } meta4 = currentChallengeItem.getItemMeta(); if (defaults.showLockedChallengeName) { lores.add(meta4.getDisplayName()); } meta4.setDisplayName(tr("\u00a74\u00a7lLocked Challenge")); lores.addAll(missingReqs); lores.addAll(missingRankRequirements); meta4.setLore(lores); currentChallengeItem.setItemMeta(meta4); } menu.setItem(location, currentChallengeItem); } catch (Exception e) { plugin.getLogger().log(Level.SEVERE, "Invalid challenge " + challenge, e); } } return location; }
Example 19
Source File: SettingsHandler.java From CratesPlus with GNU General Public License v3.0 | 4 votes |
private void openCrateColor(final Player player, final Crate crate) { GUI gui = new GUI("Edit Crate Color"); ItemStack aqua = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 3); ItemMeta aquaMeta = aqua.getItemMeta(); aquaMeta.setDisplayName(ChatColor.AQUA + "Aqua"); aqua.setItemMeta(aquaMeta); gui.addItem(aqua, getColorClickHandler(crate, ChatColor.AQUA)); ItemStack black = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 15); ItemMeta blackMeta = black.getItemMeta(); blackMeta.setDisplayName(ChatColor.BLACK + "Black"); black.setItemMeta(blackMeta); gui.addItem(black, getColorClickHandler(crate, ChatColor.BLACK)); ItemStack blue = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 9); ItemMeta blueMeta = blue.getItemMeta(); blueMeta.setDisplayName(ChatColor.BLUE + "Blue"); blue.setItemMeta(blueMeta); gui.addItem(blue, getColorClickHandler(crate, ChatColor.BLUE)); ItemStack darkAqua = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 3); ItemMeta darkAquaMeta = darkAqua.getItemMeta(); darkAquaMeta.setDisplayName(ChatColor.DARK_AQUA + "Dark Aqua"); darkAqua.setItemMeta(darkAquaMeta); gui.addItem(darkAqua, getColorClickHandler(crate, ChatColor.DARK_AQUA)); ItemStack darkBlue = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 11); ItemMeta darkBlueMeta = darkBlue.getItemMeta(); darkBlueMeta.setDisplayName(ChatColor.DARK_BLUE + "Dark Blue"); darkBlue.setItemMeta(darkBlueMeta); gui.addItem(darkBlue, getColorClickHandler(crate, ChatColor.DARK_BLUE)); ItemStack darkGray = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 7); ItemMeta darkGrayMeta = darkGray.getItemMeta(); darkGrayMeta.setDisplayName(ChatColor.DARK_GRAY + "Dark Gray"); darkGray.setItemMeta(darkGrayMeta); gui.addItem(darkGray, getColorClickHandler(crate, ChatColor.DARK_GRAY)); ItemStack darkGreen = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 13); ItemMeta darkGreenMeta = darkGreen.getItemMeta(); darkGreenMeta.setDisplayName(ChatColor.DARK_GREEN + "Dark Green"); darkGreen.setItemMeta(darkGreenMeta); gui.addItem(darkGreen, getColorClickHandler(crate, ChatColor.DARK_GREEN)); ItemStack darkPurple = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 10); ItemMeta darkPurpleMeta = darkPurple.getItemMeta(); darkPurpleMeta.setDisplayName(ChatColor.DARK_PURPLE + "Dark Purple"); darkPurple.setItemMeta(darkPurpleMeta); gui.addItem(darkPurple, getColorClickHandler(crate, ChatColor.DARK_PURPLE)); ItemStack darkRed = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 14); ItemMeta darkRedMeta = darkRed.getItemMeta(); darkRedMeta.setDisplayName(ChatColor.DARK_RED + "Dark Red"); darkRed.setItemMeta(darkRedMeta); gui.addItem(darkRed, getColorClickHandler(crate, ChatColor.DARK_RED)); ItemStack gold = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 1); ItemMeta goldMeta = gold.getItemMeta(); goldMeta.setDisplayName(ChatColor.GOLD + "Gold"); gold.setItemMeta(goldMeta); gui.addItem(gold, getColorClickHandler(crate, ChatColor.GOLD)); ItemStack gray = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 8); ItemMeta grayMeta = gray.getItemMeta(); grayMeta.setDisplayName(ChatColor.GRAY + "Gray"); gray.setItemMeta(grayMeta); gui.addItem(gray, getColorClickHandler(crate, ChatColor.GRAY)); ItemStack green = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 5); ItemMeta greenMeta = gray.getItemMeta(); greenMeta.setDisplayName(ChatColor.GREEN + "Green"); green.setItemMeta(greenMeta); gui.addItem(green, getColorClickHandler(crate, ChatColor.GREEN)); ItemStack lightPurple = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 2); ItemMeta lightPurpleMeta = lightPurple.getItemMeta(); lightPurpleMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Light Purple"); lightPurple.setItemMeta(lightPurpleMeta); gui.addItem(lightPurple, getColorClickHandler(crate, ChatColor.LIGHT_PURPLE)); ItemStack red = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 14); ItemMeta redMeta = red.getItemMeta(); redMeta.setDisplayName(ChatColor.RED + "Red"); red.setItemMeta(redMeta); gui.addItem(red, getColorClickHandler(crate, ChatColor.RED)); ItemStack white = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 0); ItemMeta whiteMeta = white.getItemMeta(); whiteMeta.setDisplayName(ChatColor.WHITE + "White"); white.setItemMeta(whiteMeta); gui.addItem(white, getColorClickHandler(crate, ChatColor.WHITE)); ItemStack yellow = new ItemStack(LegacyMaterial.WOOL.getMaterial(), 1, (short) 4); ItemMeta yellowMeta = yellow.getItemMeta(); yellowMeta.setDisplayName(ChatColor.YELLOW + "Yellow"); yellow.setItemMeta(yellowMeta); gui.addItem(yellow, getColorClickHandler(crate, ChatColor.YELLOW)); gui.open(player); }
Example 20
Source File: ItemStackFlag.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@Override public ItemStack parseInput(SpleefPlayer player, String input) throws InputParseException { String components[] = splitWithQuotes(input, " "); if (components.length == 0) { throw new InputParseException("No value was given for this itemstack flag\n" + HELP_STRING); } int amount = 1; MaterialData data = parseMaterial(components[0]); if (components.length > 1) { try { amount = Integer.parseInt(components[1]); } catch (NumberFormatException e) { throw new InputParseException("Invalid amount '" + components[1] + "' given\n" + HELP_STRING); } } ItemStack stack = data.toItemStack(amount); if (components.length > 2) { String displayName = ChatColor.translateAlternateColorCodes(TRANSLATE_CHAR, components[2]); ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(displayName); if (components.length > 3) { List<String> lore = Lists.newArrayList(); for (int i = 3; i < components.length; i++) { String loreLine = components[i]; loreLine = ChatColor.translateAlternateColorCodes(TRANSLATE_CHAR, loreLine); lore.add(loreLine); } meta.setLore(lore); } stack.setItemMeta(meta); } return stack; }