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

The following examples show how to use org.bukkit.inventory.meta.ItemMeta#setDisplayName() . 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: SkullItem.java    From CS-CoreLib with GNU General Public License v3.0 6 votes vote down vote up
@Deprecated
public SkullItem(String name, String owner, String... lore) {
	super(new ItemStack(MaterialHook.parse("PLAYER_HEAD", "SKULL_ITEM")));

	if (ReflectionUtils.isVersion("v1_10_", "v1_11_", "v1_12_")) {
		setDurability((short) 3);
	}
	
	ItemMeta im = getItemMeta();
	im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
	List<String> lines = new ArrayList<>();
	for (String line: lore) {
		lines.add(ChatColor.translateAlternateColorCodes('&', line));
	}
	im.setLore(lines);
	((SkullMeta) im).setOwner(owner);
	setItemMeta(im);
	this.owner = owner;
}
 
Example 2
Source File: ScenarioManager.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
public Inventory getScenarioMainInventory(boolean editItem){

        Inventory inv = Bukkit.createInventory(null,3*ROW, Lang.SCENARIO_GLOBAL_INVENTORY);

        for (Scenario scenario : getActiveScenarios()) {
            if (scenario.isCompatibleWithVersion()) {
                inv.addItem(scenario.getScenarioItem());
            }
        }

        if (editItem){
            // add edit item
            ItemStack edit = new ItemStack(Material.BARRIER);
            ItemMeta itemMeta = edit.getItemMeta();
            itemMeta.setDisplayName(Lang.SCENARIO_GLOBAL_ITEM_EDIT);
            edit.setItemMeta(itemMeta);

            inv.setItem(26,edit);
        }
        return inv;
    }
 
Example 3
Source File: ScenarioManager.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
public Inventory getScenarioEditInventory(){

        Inventory inv = Bukkit.createInventory(null,6*ROW, Lang.SCENARIO_GLOBAL_INVENTORY_EDIT);

        // add edit item
        ItemStack back = new ItemStack(Material.ARROW);
        ItemMeta itemMeta = back.getItemMeta();
        itemMeta.setDisplayName(Lang.SCENARIO_GLOBAL_ITEM_BACK);
        back.setItemMeta(itemMeta);
        inv.setItem(5*ROW+8,back);

        for (Scenario scenario : Scenario.values()){
            if (!scenario.isCompatibleWithVersion()){
                continue;
            }

            ItemStack scenarioItem = scenario.getScenarioItem();
            if (isActivated(scenario)){
                scenarioItem.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
                scenarioItem.setAmount(2);
            }
            inv.addItem(scenarioItem);
        }

        return inv;
    }
 
Example 4
Source File: ColorHandler.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
public static ItemStack colorItemWithPermissions(final ItemStack item, final Player p) {
    if (item.hasItemMeta()) {
        final ItemMeta itemMeta = item.getItemMeta();
        if (itemMeta.hasDisplayName()) {
            String coloredName = Util.toColor(itemMeta.getDisplayName());
            for (int i = 0; i < coloredName.length(); ++i) {
                if (coloredName.charAt(i) == '§') {
                    final char c = coloredName.charAt(i + 1);
                    if (ItemManager.getItemEnchantLevel(item) < 1) {
                        coloredName = coloredName.replaceAll("§" + c, "&" + c);
                    }
                }
            }
            itemMeta.setDisplayName(coloredName);
            item.setItemMeta(itemMeta);
        }
    }
    return item;
}
 
Example 5
Source File: ItemData.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Applies an item meta to this item. Currently, it copies the following,
 * provided that they exist in given meta:
 * <ul>
 * <li>Lore
 * <li>Display name
 * <li>Enchantments
 * <li>Item flags
 * </ul>
 * @param meta Item meta.
 */
public void applyMeta(ItemMeta meta) {
	ItemMeta our = getItemMeta();
	if (meta.hasLore())
		our.setLore(meta.getLore());
	if (meta.hasDisplayName())
		our.setDisplayName(meta.getDisplayName());
	if (meta.hasEnchants()) {
		for (Map.Entry<Enchantment, Integer> entry : meta.getEnchants().entrySet()) {
			our.addEnchant(entry.getKey(), entry.getValue(), true);
		}
	}
	for (ItemFlag flag : meta.getItemFlags()) {
		our.addItemFlags(flag);
	}
	setItemMeta(meta);
}
 
Example 6
Source File: PickerMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack createClassButton(MatchPlayer viewer, PlayerClass cls) {
  ItemStack item = cls.getIcon().toItemStack(1);
  ItemMeta meta = item.getItemMeta();

  meta.setDisplayName(
      (cls.canUse(viewer.getBukkit()) ? ChatColor.GREEN : ChatColor.RED) + cls.getName());
  if (match.getModule(ClassMatchModule.class).getSelectedClass(viewer.getId()).equals(cls)) {
    meta.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
  }

  List<String> lore = Lists.newArrayList();
  if (cls.getLongDescription() != null) {
    LegacyFormatUtils.wordWrap(
        ChatColor.GOLD + cls.getLongDescription(), LORE_WIDTH_PIXELS, lore);
  } else if (cls.getDescription() != null) {
    lore.add(ChatColor.GOLD + cls.getDescription());
  }

  if (!cls.canUse(viewer.getBukkit())) {
    lore.add(
        ChatColor.RED
            + TextTranslations.translate("class.picker.restricted", viewer.getBukkit()));
  }

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

  return item;
}
 
Example 7
Source File: NineSlotsListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable(){
    fillItem = UniversalMaterial.LIGHT_GRAY_STAINED_GLASS_PANE.getStack();
    ItemMeta meta = fillItem.getItemMeta();
    meta.setDisplayName(ChatColor.RED.toString() + ChatColor.BOLD + "BLOCKED");
    fillItem.setItemMeta(meta);
}
 
Example 8
Source File: InventoryForVillagerOffers.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: EnchantManager.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static ItemStack getEnchantBook(CEnchantment ce, int level) {
    ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
    ItemMeta im = item.getItemMeta();
    im.setLore(Arrays.asList(new String[] { lorePrefix + ce.getDisplayName() + " " + intToLevel(level) }));
    im.setDisplayName(enchantBookName);
    item.setItemMeta(im);
    item.addUnsafeEnchantment(glowEnchantment, 0);
    return item;
}
 
Example 10
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 11
Source File: Gizmo.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public ItemStack getHotbarItemStack(Player player) {
    ItemStack itemStack = this.getItemStack(player);
    ItemMeta meta = itemStack.getItemMeta();

    meta.setDisplayName(LobbyTranslations.get().t("gizmo.current", player, meta.getDisplayName()));
    itemStack.setItemMeta(meta);

    return itemStack;
}
 
Example 12
Source File: ItemStackBuilder.java    From AstralEdit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the displayName of the itemStack
 *
 * @param name name
 * @return builder
 */
public ItemStackBuilder setDisplayName(String name) {
    final ItemMeta itemMeta = this.getItemMeta();
    itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
    this.setItemMeta(itemMeta);
    return this;
}
 
Example 13
Source File: Succubus.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@Override
protected void setUp()
{
	sucItem = KitUtils.addSoulbound(getIcon().clone());
	ItemMeta m = sucItem.getItemMeta();
	m.setDisplayName(sucItemName);
	sucItem.setItemMeta(m);
	Delays.getInstance().createNewDelay(getInternalName(), new StandardItemUpdater(sucItemName,sucItem.getType(),new Function<ItemStack,Boolean>(){
		@Override
		public Boolean apply(ItemStack stack)
		{
			return isSuccubusItem(stack);
		}}));
}
 
Example 14
Source File: AnvilGUI.java    From AnvilGUI with MIT License 5 votes vote down vote up
/**
 * Create an AnvilGUI and open it for the player.
 *
 * @param plugin A {@link org.bukkit.plugin.java.JavaPlugin} instance
 * @param player The {@link Player} to open the inventory for
 * @param inventoryTitle What to have the text already set to
 * @param itemText The name of the item in the first slot of the anvilGui
 * @param insert The material of the item in the first slot of the anvilGUI
 * @param preventClose Whether to prevent the inventory from closing
 * @param closeListener A {@link Consumer} when the inventory closes
 * @param completeFunction A {@link BiFunction} that is called when the player clicks the {@link Slot#OUTPUT} slot
 */
private AnvilGUI(
		Plugin plugin,
		Player player,
		String inventoryTitle,
		String itemText,
		ItemStack insert,
		boolean preventClose,
		Consumer<Player> closeListener,
		BiFunction<Player, String, Response> completeFunction
) {
	this.plugin = plugin;
	this.player = player;
	this.inventoryTitle = inventoryTitle;
	this.insert = insert;
	this.preventClose = preventClose;
	this.closeListener = closeListener;
	this.completeFunction = completeFunction;

	if(itemText != null) {
		if(insert == null) {
			this.insert = new ItemStack(Material.PAPER);
		}

		ItemMeta paperMeta = this.insert.getItemMeta();
		paperMeta.setDisplayName(itemText);
		this.insert.setItemMeta(paperMeta);
	}

	openInventory();
}
 
Example 15
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);
       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 16
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_POTION_EFFECTS);
       addItemMeta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
       addItemMeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
       addItemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
       addItem.setItemMeta(addItemMeta);
       return addItem;
}
 
Example 17
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 18
Source File: ItemStackBuilder.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
public ItemStackBuilder withName(String name) {
    final ItemMeta meta = ITEM_STACK.getItemMeta();
    meta.setDisplayName(Utils.color(name));
    ITEM_STACK.setItemMeta(meta);
    return this;
}
 
Example 19
Source File: PlayerStorage.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
public void openTeamSelection(Game game) {
  BedwarsOpenTeamSelectionEvent openEvent = new BedwarsOpenTeamSelectionEvent(game, this.player);
  BedwarsRel.getInstance().getServer().getPluginManager().callEvent(openEvent);

  if (openEvent.isCancelled()) {
    return;
  }

  HashMap<String, Team> teams = game.getTeams();

  int nom = (teams.size() % 9 == 0) ? 9 : (teams.size() % 9);
  Inventory inv =
      Bukkit.createInventory(this.player, teams.size() + (9 - nom),
          BedwarsRel._l(this.player, "lobby.chooseteam"));
  for (Team team : teams.values()) {
    List<Player> players = team.getPlayers();
    if (players.size() >= team.getMaxPlayers()) {
      continue;
    }
    Wool wool = new Wool(team.getColor().getDyeColor());
    ItemStack is = wool.toItemStack(1);
    ItemMeta im = is.getItemMeta();

    im.setDisplayName(team.getChatColor() + team.getName());
    ArrayList<String> teamplayers = new ArrayList<>();

    int teamPlayerSize = team.getPlayers().size();
    int maxPlayers = team.getMaxPlayers();

    String current = "0";
    if (teamPlayerSize >= maxPlayers) {
      current = ChatColor.RED + String.valueOf(teamPlayerSize);
    } else {
      current = ChatColor.YELLOW + String.valueOf(teamPlayerSize);
    }

    teamplayers.add(ChatColor.GRAY + "(" + current + ChatColor.GRAY + "/" + ChatColor.YELLOW
        + String.valueOf(maxPlayers) + ChatColor.GRAY + ")");
    teamplayers.add(ChatColor.WHITE + "---------");

    for (Player teamPlayer : players) {
      teamplayers.add(team.getChatColor() + ChatColor.stripColor(teamPlayer.getDisplayName()));
    }

    im.setLore(teamplayers);
    is.setItemMeta(im);
    inv.addItem(is);
  }

  this.player.openInventory(inv);
}
 
Example 20
Source File: MenuItem.java    From AnnihilationPro with MIT License 3 votes vote down vote up
/**
 * Sets the display name and lore of an ItemStack.
 *
 * @param itemStack
 *            The ItemStack.
 * @param displayName
 *            The display name.
 * @param lore
 *            The lore.
 * @return The ItemStack.
 */
public static ItemStack setNameAndLore(ItemStack itemStack,
		String displayName, List<String> lore)
{
	ItemMeta meta = itemStack.getItemMeta();
	meta.setDisplayName(displayName);
	meta.setLore(lore);
	itemStack.setItemMeta(meta);
	return itemStack;
}