Java Code Examples for org.bukkit.inventory.meta.ItemMeta#setLore()

The following examples show how to use org.bukkit.inventory.meta.ItemMeta#setLore() . 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: ChallengeLogic.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public ItemStack getItemStack(PlayerInfo playerInfo, String challengeName) {
    Challenge challenge = getChallenge(challengeName);
    ChallengeCompletion completion = playerInfo.getChallenge(challengeName);
    ItemStack currentChallengeItem = challenge.getDisplayItem(completion, defaults.enableEconomyPlugin);
    ItemMeta meta = currentChallengeItem.getItemMeta();
    List<String> lores = meta.getLore();
    if (challenge.isRepeatable() || completion.getTimesCompleted() == 0) {
        lores.add(tr("\u00a7e\u00a7lClick to complete this challenge."));
    } else {
        lores.add(tr("\u00a74\u00a7lYou can't repeat this challenge."));
    }
    if (completion.getTimesCompleted() > 0) {
        meta.addEnchant(Enchantment.LOYALTY, 0, true);
    }
    meta.setLore(lores);
    currentChallengeItem.setItemMeta(meta);
    return currentChallengeItem;
}
 
Example 2
Source File: CVItem.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public ItemStack createItemStack() {
    if (mmoItemType != null && mmoItemName != null && Civs.mmoItems != null) {
        Type mmoType = Civs.mmoItems.getTypes().get(mmoItemType);
        MMOItem mmoItem = Civs.mmoItems.getItems().getMMOItem(mmoType, mmoItemName);
        ItemStack itemStack = mmoItem.newBuilder().build();
        if (displayName != null) {
            itemStack.getItemMeta().setDisplayName(displayName);
        }
        if (!lore.isEmpty()) {
            itemStack.getItemMeta().setLore(lore);
        }
        itemStack.setAmount(qty);
        return itemStack;
    }

    ItemStack is = new ItemStack(mat, qty);
    if (displayName != null || (lore != null && !lore.isEmpty())) {
        if (!is.hasItemMeta()) {
            is.setItemMeta(Bukkit.getItemFactory().getItemMeta(is.getType()));
        }
        ItemMeta im = is.getItemMeta();
        if (displayName != null) {
            im.setDisplayName(displayName);
        }
        if (lore == null) {
            lore = new ArrayList<>();
        } else if (!lore.isEmpty()) {
            im.setLore(lore);
        }
        im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
        is.setItemMeta(im);
    }
    return is;
}
 
Example 3
Source File: DisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new itemStack with protect flag.
 *
 * @param itemStack Old itemStack
 * @param shop      The shop
 * @return New itemStack with protect flag.
 */
@NotNull
public static ItemStack createGuardItemStack(@NotNull ItemStack itemStack, @NotNull Shop shop) {
    itemStack = itemStack.clone();
    //itemStack.setAmount(1);
    ItemMeta iMeta = itemStack.getItemMeta();
    if (QuickShop.instance.getConfig().getBoolean("shop.display-item-use-name")) {
        if (iMeta.hasDisplayName()) {
            iMeta.setDisplayName(iMeta.getDisplayName());
        } else {
            iMeta.setDisplayName(Util.getItemStackName(itemStack));
        }
    } else {
        iMeta.setDisplayName(null);
    }
    ShopProtectionFlag shopProtectionFlag = createShopProtectionFlag(itemStack, shop);
    String protectFlag = gson.toJson(shopProtectionFlag);
    iMeta.setLore(Lists.newArrayList(protectFlag));
    itemStack.setItemMeta(iMeta);
    return itemStack;
}
 
Example 4
Source File: MainGui.java    From WildernessTp with MIT License 6 votes vote down vote up
public static void OpenGUI(Player p) {
    ItemStack Close = new ItemStack(Material.REDSTONE_BLOCK, 1);
    ItemMeta meta = Close.getItemMeta();
    meta.setDisplayName("Close");
    ArrayList<String> lore = new ArrayList<String>();
    lore.add("Click to close the inventory and return to normal gameplay");
    meta.setLore(lore);
    Close.setItemMeta(meta);
    Inventory Wildtp = Bukkit.createInventory(p, 18, "WildTp");
    putEdit(p);
    p.openInventory(Wildtp);
    p.sendMessage(ChatColor.RED+"Please make sure to use the redstone block to close early or you wont be able to chat");
    Wildtp.setItem(17, Close);
    Wildtp.setItem(2, makeItem(Material.valueOf(getMaterials().get("Book")), "Messages", Collections.singletonList("Click to set the messages")));
    Wildtp.setItem(4, makeItem(Material.PAPER, "Set", Arrays.asList("Click me to set the values for x and z ","along with cooldown and cost")));
    Wildtp.setItem(6, makeItem(Material.BOOK,"Add a potion or world", Collections.singletonList("Click to add a potion or world")));
    Wildtp.setItem(0, makeItem(Material.JUKEBOX, "Sounds", Collections.singletonList("Click me to set the sound")));
    Wildtp.setItem(8, makeItem(Material.TRIPWIRE_HOOK,"Hooks", Collections.singletonList("Click me to enable or disable a hook")));
}
 
Example 5
Source File: ChestMenuUtils.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public static void updateProgressbar(ChestMenu menu, int slot, int timeLeft, int time, ItemStack indicator) {
    ItemStack item = indicator.clone();
    ItemMeta im = item.getItemMeta();
    im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);

    if (im instanceof Damageable) {
        ((Damageable) im).setDamage(getDurability(item, timeLeft, time));
    }

    im.setDisplayName(" ");
    im.setLore(Arrays.asList(getProgressBar(timeLeft, time), "", ChatColor.GRAY + NumberUtils.getTimeLeft(timeLeft / 2) + " left"));
    item.setItemMeta(im);

    menu.replaceExistingItem(slot, item);
}
 
Example 6
Source File: InventoryPreview.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a preview item GUI for a player.
 *
 * @param itemStack The item you want create.
 * @param player    Target player.
 * @param plugin    The plugin instance.
 */
public InventoryPreview(@NotNull QuickShop plugin, @NotNull ItemStack itemStack, @NotNull Player player) {
    this.plugin = plugin;
    this.itemStack = itemStack.clone();
    this.player = player;
    ItemMeta itemMeta = this.itemStack.getItemMeta();
    itemMeta.setLore(Lists.newArrayList(plugin.getPreviewProtectionLore()));
    this.itemStack.setItemMeta(itemMeta);
}
 
Example 7
Source File: GUIInventoryRequiredItems.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void generateContent() {
	for(ItemStack item : requiredItems) {
		int amountInventory = InventoryUtils.getTotalAmountOfItemStackInInventory(getViewer().getPlayer().getInventory(), item);
		int amountEnderChest = InventoryUtils.getTotalAmountOfItemStackInInventory(getViewer().getPlayer().getEnderChest(), item);
		int needMore = item.getAmount() - amountEnderChest - amountInventory;

		if(needMore < 0) {
			needMore = 0;
		}

		ItemMeta itemStackMeta = item.hasItemMeta()
				? item.getItemMeta()
				: Bukkit.getItemFactory().getItemMeta(item.getType());

		List<String> lore = new ArrayList<>();

		if(itemStackMeta.hasLore()) {
			lore.addAll(itemStackMeta.getLore());
		}

		lore.addAll(Message.INVENTORY_REQUIREDITEMS_LORE
				.clone()
				.setVar(VarKey.AMOUNT_AVAILABLE, amountInventory)
				.setVar(VarKey.AMOUNT_AVAILABLE2, amountEnderChest)
				.setVar(VarKey.AMOUNT_AVAILABLE3, amountInventory + amountEnderChest)
				.setVar(VarKey.AMOUNT, item.getAmount())
				.setVar(VarKey.NEEDMORE, needMore)
				.getList());

		itemStackMeta.setLore(lore);
		item.setItemMeta(itemStackMeta);

		registerAndAdd(new EmptyExecutor(item));
	}
}
 
Example 8
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: GizmoUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void openShop(Player player, Gizmo gizmo) {
    Inventory inventory = Bukkit.createInventory(player, 54, StringUtils.truncate(ChatColor.GOLD + LobbyTranslations.get().t("gizmos.shopFor", player, gizmo.getColoredName(player)), 32));

    inventory.setItem(4, Utils.getGhastTear(player, RaindropsListener.raindrops.get(player)));
    inventory.setItem(22, gizmo.getItemStack(player));

    ItemStack accept = new ItemStack(Material.DIAMOND);
    ItemMeta acceptMeta = accept.getItemMeta();
    acceptMeta.setDisplayName(ChatColor.GREEN + LobbyTranslations.get().t("purchase.purchase", player, gizmo.getColoredName(player)));
    acceptMeta.setLore(Lists.newArrayList(gizmo.getCostText(player)));
    accept.setItemMeta(acceptMeta);

    ItemStack exit = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta exitMeta = exit.getItemMeta();
    exitMeta.setDisplayName(ChatColor.RED + LobbyTranslations.get().t("purchase.cancel", player));
    exit.setItemMeta(exitMeta);

    for(int i = 3; i < 6; i++) {
        for(int x = 0; x < 3; x++) {
            inventory.setItem(i * 9 + x, accept);
        }

        for(int y = 6; y < 9; y++) {
            inventory.setItem(i * 9 + y, exit);
        }
    }

    player.openInventory(inventory);
}
 
Example 10
Source File: CustomItem.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public CustomItem(Material type, String name, int durability, int amount, List<String> lore) {
	super(new ItemStack(type, amount));
	ItemMeta im = getItemMeta();
	im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
	im.setLore(lore);
	setItemMeta(im);
	setDurability((short) durability);
}
 
Example 11
Source File: TutorialPlayerFacet.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack createItem(CommandSender viewer) {
    final ItemStack item = new ItemStack(TUTORIAL_ITEM);
    final ItemMeta meta = item.getItemMeta();
    meta.addItemFlags(ItemFlag.values());
    meta.setDisplayName(renderer.renderLegacy(new Component(new TranslatableComponent("tutorial.displayName"), ChatColor.GOLD, ChatColor.BOLD), viewer));
    meta.setLore(ImmutableList.of(renderer.renderLegacy(new Component(new TranslatableComponent("tutorial.tooltip", mapInfo.getColoredName()), ChatColor.WHITE), viewer)));
    item.setItemMeta(meta);
    return item;
}
 
Example 12
Source File: ObserverToolsMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack createToolItem(MatchPlayer player) {
  ItemStack tool = new ItemStack(TOOL_MATERIAL);
  ItemMeta meta = tool.getItemMeta();
  Component displayName =
      TranslatableComponent.of("setting.displayName", TextColor.AQUA, TextDecoration.BOLD);
  Component lore = TranslatableComponent.of("setting.lore", TextColor.GRAY);
  meta.setDisplayName(TextTranslations.translateLegacy(displayName, player.getBukkit()));
  meta.setLore(Lists.newArrayList(TextTranslations.translateLegacy(lore, player.getBukkit())));
  meta.addItemFlags(ItemFlag.values());
  tool.setItemMeta(meta);
  return tool;
}
 
Example 13
Source File: Key.java    From CratesPlus with GNU General Public License v3.0 5 votes vote down vote up
public ItemStack getKeyItem(Integer amount) {
    ItemStack keyItem = new ItemStack(getMaterial(), amount, getData());
    if (isEnchanted())
        keyItem.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
    ItemMeta keyItemMeta = keyItem.getItemMeta();
    String title = getName().replaceAll("%type%", getCrate().getName(true));
    keyItemMeta.setDisplayName(title);
    keyItemMeta.setLore(getLore());
    ArrayList<String> flags = new ArrayList<>();
    flags.add("HIDE_ENCHANTS");
    keyItemMeta = cratesPlus.getVersion_util().handleItemFlags(keyItemMeta, flags);
    keyItem.setItemMeta(keyItemMeta);
    return keyItem;
}
 
Example 14
Source File: Items.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
public ItemStackBuilder setLore(List<String> lore)
{
	ItemMeta itemMeta = itemStack.getItemMeta();
	itemMeta.setLore(Strings.format(lore));
	itemStack.setItemMeta(itemMeta);
	return this;
}
 
Example 15
Source File: CPItem.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A Control Panel item
 * @param material
 * @param name
 * @param command
 * @param nextSection
 */
public CPItem(Material material, String name, String command, String nextSection) {
    this.command = command;
    this.nextSection = nextSection;
    item = new ItemStack(material);
    ItemMeta meta = item.getItemMeta();
    // Handle multi line names (split by |)
    List<String> desc = new ArrayList<String>(Arrays.asList(name.split("\\|")));
    meta.setDisplayName(ChatColor.WHITE + desc.get(0));
    if (desc.size() > 1) {
        desc.remove(0); // Remove the name
        meta.setLore(desc);
    }
    item.setItemMeta(meta);
}
 
Example 16
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getItemStack(ItemStack item, List<String> lore, String message) {
	ItemStack addItem = item.clone();
       ItemMeta addItemMeta = addItem.getItemMeta();
       addItemMeta.setDisplayName(message);
       addItemMeta.setLore(lore);
       addItem.setItemMeta(addItemMeta);
       return addItem;
}
 
Example 17
Source File: EnchantManager.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static ItemStack addEnchantments(ItemStack item, HashMap<CEnchantment, Integer> list) {
    ItemMeta im = item.getItemMeta();
    List<String> lore = new ArrayList<String>();
    if (im.hasLore()) {
        lore = im.getLore();
        if (maxEnchants < enchantments.size()) {
            int counter = maxEnchants - list.size();
            for (String s : lore)
                if (containsEnchantment(s)) {
                    counter--;
                    if (counter <= 0) {
                        return item;
                    }
                }
        }
    }
    for (CEnchantment ce : list.keySet()) {
        int level = list.get(ce);
        if (level > ce.getEnchantmentMaxLevel())
            level = ce.getEnchantmentMaxLevel();
        lore.add(ce.getDisplayName() + " " + intToLevel(level));
    }
    im.setLore(lore);
    item.setItemMeta(im);
    item.addUnsafeEnchantment(glowEnchantment, 0);
    return item;
}
 
Example 18
Source File: Items.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
public ItemStackBuilder addLore(List<String> lore)
{
	ItemMeta itemMeta = itemStack.getItemMeta();
	List<String> original = itemMeta.getLore();
	if(original == null) original = new ArrayList<String>();
	original.addAll(Strings.format(lore));
	itemMeta.setLore(original);
	itemStack.setItemMeta(itemMeta);
	return this;
}
 
Example 19
Source File: StormStaff.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack getCraftedOutput() {
    ItemStack item = SlimefunItems.STAFF_STORM.clone();
    ItemMeta im = item.getItemMeta();
    List<String> lore = im.getLore();

    lore.set(4, ChatColors.color("&e" + MAX_USES + " Uses &7left"));

    im.setLore(lore);
    item.setItemMeta(im);
    return item;
}
 
Example 20
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack getItem(MaterialStorage ms) {
	CustomBaseObject base = QualityArmory.getCustomItem(ms);
	if(base==null)
		return null;
	String displayname = base.getDisplayName();
	if (ms == null || ms.getMat() == null)
		return new ItemStack(Material.AIR);

	ItemStack is = new ItemStack(ms.getMat(),1,(short)ms.getData());
	if (ms.getData() < 0)
		is.setDurability((short) 0);
	ItemMeta im = is.getItemMeta();
	if (im == null)
		im = Bukkit.getServer().getItemFactory().getItemMeta(ms.getMat());
	if (im != null) {
		im.setDisplayName(displayname);
		List<String> lore = base.getCustomLore()!=null?new ArrayList<>(base.getCustomLore()):new ArrayList<>();

		if(base instanceof Gun)
			lore.addAll(Gun.getGunLore((Gun) base, null, ((Gun) base).getMaxBullets()));
		if (base instanceof ArmorObject)
			lore.addAll(OLD_ItemFact.getArmorLore((ArmorObject) base));

		OLD_ItemFact.addVariantData(im,lore,base);
		im.setLore(lore);
		if (QAMain.ITEM_enableUnbreakable) {
			try {
				im.setUnbreakable(true);
			} catch (Error | Exception e34) {
			}
		}
		try {
			if (QAMain.ITEM_enableUnbreakable) {
				im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_UNBREAKABLE);
			}
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES);
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_DESTROYS);
		} catch (Error e) {

		}
		if(ms.getVariant()!=0) {
			OLD_ItemFact.addVariantData(im, im.getLore(), ms.getVariant());
		}
		is.setItemMeta(im);
	} else {
		// Item meta is still null. Catch and report.
		QAMain.getInstance().getLogger()
				.warning(QAMain.prefix + " ItemMeta is null for " + base.getName() + ". I have");
	}
	is.setAmount(1);
	return is;

}