Java Code Examples for org.bukkit.inventory.meta.ItemMeta#getDisplayName()
The following examples show how to use
org.bukkit.inventory.meta.ItemMeta#getDisplayName() .
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: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
private void onClickCreateMenu(InventoryClickEvent event, Player p, ItemMeta meta, int slotIndex, int menuSize) { event.setCancelled(true); if (slotIndex == 0) { p.closeInventory(); p.performCommand("island create"); } else if (slotIndex == menuSize-2) { p.closeInventory(); p.performCommand("island spawn"); } else if (slotIndex == menuSize-1) { p.closeInventory(); p.performCommand("island accept"); } else if (meta != null && meta.getDisplayName() != null) { String schemeName = stripFormatting(meta.getDisplayName()); if (plugin.getPerkLogic().getSchemes(p).contains(schemeName)) { p.closeInventory(); p.performCommand("island create " + schemeName); } else { p.sendMessage(tr("\u00a7eYou do not have access to that island-schematic!")); } } }
Example 2
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
private void onClickRestartMenu(final InventoryClickEvent event, final Player p, ItemMeta meta, int slotIndex, ItemStack currentItem) { event.setCancelled(true); if (slotIndex == 0) { p.closeInventory(); p.openInventory(createMainMenu(p)); } else if (currentItem != null && meta != null && meta.getDisplayName() != null) { String schemeName = stripFormatting(meta.getDisplayName()); IslandPerk islandPerk = plugin.getPerkLogic().getIslandPerk(schemeName); if (plugin.getPerkLogic().getSchemes(p).contains(schemeName) && p.hasPermission(islandPerk.getPermission())) { if (plugin.getConfirmHandler().millisLeft(p, "/is restart") > 0) { p.closeInventory(); p.performCommand("island restart " + schemeName); } else { p.performCommand("island restart " + schemeName); updateRestartMenuTimer(p, event.getInventory()); } } } }
Example 3
Source File: ItemFactory.java From TradePlus with GNU General Public License v3.0 | 6 votes |
public ItemFactory(ItemStack stack) { damage = stack.getDurability(); material = stack.getType(); amount = stack.getAmount(); data = stack.getData().getData(); if (stack.hasItemMeta()) { ItemMeta meta = stack.getItemMeta(); if (meta.hasDisplayName()) { display = meta.getDisplayName(); } if (meta.hasLore()) { lore = meta.getLore(); } if (Sounds.version != 17) flags = new ArrayList<>(meta.getItemFlags()); } if (Sounds.version > 113) { customModelData = ItemUtils1_14.getCustomModelData(stack); } }
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: CustomItem.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
static String getItemName(ItemStack item) { if (item != null) { ItemMeta meta = item.getItemMeta(); if (meta != null) { if (meta instanceof BookMeta) { return ((BookMeta) meta).getTitle(); } else { return meta.getDisplayName(); } } } return null; }
Example 6
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 7
Source File: MerchantCategory.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private static ItemStack setResourceName(ItemStack item) { ItemMeta im = item.getItemMeta(); String name = im.getDisplayName(); // check if is ressource ConfigurationSection resourceSection = BedwarsRel.getInstance().getConfig().getConfigurationSection("resource"); for (String key : resourceSection.getKeys(false)) { List<Object> resourceList = (List<Object>) BedwarsRel.getInstance().getConfig() .getList("resource." + key + ".item"); for (Object resource : resourceList) { ItemStack itemStack = ItemStack.deserialize((Map<String, Object>) resource); if (itemStack != null && itemStack.getType().equals(item.getType()) && itemStack.getItemMeta() != null && itemStack.getItemMeta().getDisplayName() != null) { name = ChatColor.translateAlternateColorCodes('&', itemStack.getItemMeta().getDisplayName()); } } } im.setDisplayName(name); item.setItemMeta(im); return item; }
Example 8
Source File: ShopInventory.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
private static String getNameOrCustomNameOfItem(ItemStack stack) { try { if (stack.hasItemMeta()) { ItemMeta meta = stack.getItemMeta(); if (meta == null) { return ""; } if (meta.hasDisplayName()) { return meta.getDisplayName(); } if (meta.hasLocalizedName()) { return meta.getLocalizedName(); } } } catch (Throwable ignored) { } String normalItemName = stack.getType().name().replace("_", " ").toLowerCase(); String[] sArray = normalItemName.split(" "); StringBuilder stringBuilder = new StringBuilder(); for (String s : sArray) { stringBuilder.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).append(" "); } return stringBuilder.toString().trim(); }
Example 9
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 10
Source File: MapRatingsMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onButtonClick(final InventoryClickEvent event) { ItemStack stack = event.getCurrentItem(); final MatchPlayer player = this.getMatch().getPlayer(event.getWhoClicked()); if(stack == null || player == null) return; if(stack.getType() != Material.WOOL && stack.getType() != Material.CARPET) return; ItemMeta meta = stack.getItemMeta(); if(!meta.hasDisplayName()) return; String name = meta.getDisplayName(); if(!name.startsWith(BUTTON_PREFIX)) return; event.setCancelled(true); final int score = stack.getAmount(); if(!isScoreValid(score)) return; this.getMatch().getScheduler(MatchScope.LOADED).createTask(() -> { Integer oldScore = playerRatings.get(player); if(oldScore == null || oldScore != score) { player.playSound(Sound.UI_BUTTON_CLICK, 1, 2); rate(player, score); } else { player.getBukkit().closeInventory(); } }); }
Example 11
Source File: Items.java From TabooLib with MIT License | 5 votes |
public static ItemStack replaceName(ItemStack item, Map<String, String> map) { if (hasName(item)) { ItemMeta meta = item.getItemMeta(); String name = meta.getDisplayName(); for (Map.Entry<String, String> entry : map.entrySet()) { name = name.replace(entry.getKey(), entry.getValue()); } meta.setDisplayName(name); item.setItemMeta(meta); } return item; }
Example 12
Source File: SimpleI18n.java From TabooLib with MIT License | 5 votes |
public static String getCustomName(ItemStack item) { if (item != null) { ItemMeta itemMeta = item.getItemMeta(); return itemMeta != null && itemMeta.hasDisplayName() ? itemMeta.getDisplayName() : getName(item); } return getName(item); }
Example 13
Source File: ShopInventory.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
private static String getNameOrCustomNameOfItem(ItemStack stack) { try { if (stack.hasItemMeta()) { ItemMeta meta = stack.getItemMeta(); if (meta == null) { return ""; } if (meta.hasDisplayName()) { return meta.getDisplayName(); } if (meta.hasLocalizedName()) { return meta.getLocalizedName(); } } } catch (Throwable ignored) { } String normalItemName = stack.getType().name().replace("_", " ").toLowerCase(); String[] sArray = normalItemName.split(" "); StringBuilder stringBuilder = new StringBuilder(); for (String s : sArray) { stringBuilder.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).append(" "); } return stringBuilder.toString().trim(); }
Example 14
Source File: Anvil.java From AdditionsAPI with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onItemRename(PrepareAnvilEvent event) { if (event.getResult() == null) return; ItemStack resultItem = event.getResult(); if (!AdditionsAPI.isCustomItem(resultItem)) return; AnvilInventory inv = event.getInventory(); ItemMeta resultMeta = resultItem.getItemMeta(); CustomItemStack cStack = new CustomItemStack(resultItem); CustomItem cItem = cStack.getCustomItem(); ItemStack leftItem = inv.getItem(0); ItemMeta leftMeta = leftItem.getItemMeta(); /* * A fix for the bug that occurred due to the Display Name of the Custom * Item having a ChatColor.RESET in front. */ if (cItem.getDisplayName() != null && resultMeta.getDisplayName() != null) { String renamedDisplayName = resultMeta.getDisplayName(); if (cItem.getDisplayName() != renamedDisplayName && leftMeta.getDisplayName().startsWith(ChatColor.RESET + "")) { if (renamedDisplayName.startsWith("r")) renamedDisplayName = renamedDisplayName.replaceFirst("r", ""); resultMeta.setDisplayName(renamedDisplayName); } } /* * A fix for being able to put books of any enchantment, even if it's * forbidden */ if (!cItem.getForbidenEnchantments().isEmpty()) for (Enchantment ench : cItem.getForbidenEnchantments()) if (resultItem.containsEnchantment(ench)) event.setResult(new ItemStack(Material.AIR)); if (cItem.getDisplayName() != null) { String customName = cItem.getDisplayName(); /* * Fixes a bug that allowed you to rename the resultItem to it * original material name */ if (resultMeta.getDisplayName() == null) { resultMeta.setDisplayName(customName); } else { /* * TODO: A fix for the italic text even if you didn't change the * name */ } } resultItem.setItemMeta(resultMeta); /* * A fix for the fake lore not updating when adding Sharpness. */ cStack.updateLore(); }
Example 15
Source File: ItemData.java From Skript with GNU General Public License v3.0 | 4 votes |
/** * Compares {@link ItemMeta}s for {@link #matchAlias(ItemData)}. * Note that this does NOT compare everything; only the most * important bits. * @param first Meta of this item. * @param second Meta of given item. * @return Match quality of metas. * Lowest is {@link MatchQuality#SAME_MATERIAL}. */ private static MatchQuality compareItemMetas(ItemMeta first, ItemMeta second) { MatchQuality quality = MatchQuality.EXACT; // Lowered as we go on // Display name String ourName = first.hasDisplayName() ? first.getDisplayName() : null; String theirName = second.hasDisplayName() ? second.getDisplayName() : null; if (!Objects.equals(ourName, theirName)) { quality = ourName != null ? MatchQuality.SAME_MATERIAL : quality; } // Lore List<String> ourLore = first.hasLore() ? first.getLore() : null; List<String> theirLore = second.hasLore() ? second.getLore() : null; if (!Objects.equals(ourLore, theirLore)) { quality = ourLore != null ? MatchQuality.SAME_MATERIAL : quality; } // Enchantments Map<Enchantment, Integer> ourEnchants = first.getEnchants(); Map<Enchantment, Integer> theirEnchants = second.getEnchants(); if (!Objects.equals(ourEnchants, theirEnchants)) { quality = !ourEnchants.isEmpty() ? MatchQuality.SAME_MATERIAL : quality; } // Item flags Set<ItemFlag> ourFlags = first.getItemFlags(); Set<ItemFlag> theirFlags = second.getItemFlags(); if (!Objects.equals(ourFlags, theirFlags)) { quality = !ourFlags.isEmpty() ? MatchQuality.SAME_MATERIAL : quality; } // Potion data if (second instanceof PotionMeta) { if (!(first instanceof PotionMeta)) { return MatchQuality.DIFFERENT; // Second is a potion, first is clearly not } // Compare potion type, including extended and level 2 attributes PotionData ourPotion = ((PotionMeta) first).getBasePotionData(); PotionData theirPotion = ((PotionMeta) second).getBasePotionData(); return !Objects.equals(ourPotion, theirPotion) ? MatchQuality.SAME_MATERIAL : quality; } return quality; }
Example 16
Source File: ItemRenameListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onInventoryClick(InventoryClickEvent e) { // check if the event has been cancelled by another plugin if (!e.isCancelled()) { HumanEntity ent = e.getWhoClicked(); // not really necessary if (ent instanceof Player) { Player player = (Player) ent; Inventory inv = e.getInventory(); // see if the event is about an anvil if (inv instanceof AnvilInventory) { InventoryView view = e.getView(); int rawSlot = e.getRawSlot(); // compare the raw slot with the inventory view to make sure we are talking about the upper inventory if (rawSlot == view.convertSlot(rawSlot)) { /* slot 0 = left item slot slot 1 = right item slot slot 2 = result item slot see if the player clicked in the result item slot of the anvil inventory */ if (rawSlot == 2) { /* get the current item in the result slot I think inv.getItem(rawSlot) would be possible too */ ItemStack item = e.getCurrentItem(); // check if there is an item in the result slot if (item != null) { ItemMeta meta = item.getItemMeta(); // it is possible that the item does not have meta data if (meta != null) { // see whether the item is beeing renamed if (meta.hasDisplayName()) { String displayName = meta.getDisplayName(); ItemManager.setName(item, displayName); } } } } } } } } }
Example 17
Source File: InventorySerializer.java From civcraft with GNU General Public License v2.0 | 4 votes |
private static String getSerializedItemStack(ItemStack is) { String serializedItemStack = new String(); String isType = String.valueOf(ItemManager.getId(is.getType())); serializedItemStack += "t@" + isType; if (is.getDurability() != 0) { String isDurability = String.valueOf(is.getDurability()); serializedItemStack += "&d@" + isDurability; } if (is.getAmount() != 1) { String isAmount = String.valueOf(is.getAmount()); serializedItemStack += "&a@" + isAmount; } Map<Enchantment,Integer> isEnch = is.getEnchantments(); if (isEnch.size() > 0) { for (Entry<Enchantment,Integer> ench : isEnch.entrySet()) { serializedItemStack += "&e@" + ItemManager.getId(ench.getKey()) + "@" + ench.getValue(); } } ItemMeta meta = is.getItemMeta(); if (meta != null && meta.hasLore()) { for (String lore : meta.getLore()) { char[] encode = Base64Coder.encode(lore.getBytes()); String encodedString = new String(encode); serializedItemStack += "&l@" + encodedString; } } if (meta != null) { if (meta.getDisplayName() != null) { serializedItemStack += "&D@" + meta.getDisplayName(); } } LoreCraftableMaterial craftMat = LoreCraftableMaterial.getCraftMaterial(is); if (craftMat != null) { serializedItemStack += "&C@" + craftMat.getConfigId(); if (LoreCraftableMaterial.hasEnhancements(is)) { serializedItemStack += "&Enh@" + LoreCraftableMaterial.serializeEnhancements(is); } } AttributeUtil attrs = new AttributeUtil(is); if (attrs.hasColor()) { serializedItemStack += "&LC@" + attrs.getColor(); } return serializedItemStack; }