Java Code Examples for org.bukkit.inventory.ItemStack#setItemMeta()

The following examples show how to use org.bukkit.inventory.ItemStack#setItemMeta() . 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: Lore.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * removes the lore of an enhanced item.
 *
 * @param is
 * @param p
 */
public static void removeLore(ItemStack is, Player p) {
    ItemMeta im = is.getItemMeta();

    String x = Util.UNIQUEID + Util.toColor(
            SettingsManager.lang.getString("lore.tradeableLore"));
    String y = Util.UNIQUEID + Util.toColor(
            SettingsManager.lang.getString("lore.untradeableLore"));
    if ((is.hasItemMeta()) && (is.getItemMeta().hasLore())) {
        List<String> loreList = is.getItemMeta().getLore();
        if ((loreList.contains(x)) || (loreList.contains(y))) {
            loreList.remove(x);
            loreList.remove(y);
        }
        im.setLore(loreList);
        is.setItemMeta(im);
        Util.sendMessage(SettingsManager.lang.getString(
                "messages.madeunbound"), p);
        return;
    }
    Util.sendMessage(SettingsManager.lang.getString(
            "messages.alreadyunbound"), p);
}
 
Example 2
Source File: Insulating.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
	ItemMeta meta = tool.getItemMeta();

	if (meta != null) {
		if (ToolType.HELMET.contains(tool.getType()) || ToolType.CHESTPLATE.contains(tool.getType())
				|| ToolType.LEGGINGS.contains(tool.getType()) || ToolType.BOOTS.contains(tool.getType())) {

			meta.addEnchant(Enchantment.PROTECTION_FIRE, modManager.getModLevel(tool, this), true);
		}

		tool.setItemMeta(meta);
	}

	return true;
}
 
Example 3
Source File: PickerMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private ItemStack createJoinButton(final MatchPlayer player) {
    ItemStack stack = new ItemStack(Button.JOIN.material);

    ItemMeta meta = stack.getItemMeta();
    meta.addItemFlags(ItemFlag.values());

    String key;
    if(!canOpenWindow(player)) {
        key = "ffa.picker.displayName";
    } else if(hasTeams && hasClasses) {
        key = "teamClass.picker.displayName";
    } else if(hasTeams) {
        key = "teamSelection.picker.displayName";
    } else if(hasClasses) {
        key = "class.picker.displayName";
    } else {
        key = "ffa.picker.displayName";
    }

    meta.setDisplayName(OPEN_BUTTON_PREFIX + PGMTranslations.t(key, player));
    meta.setLore(Lists.newArrayList(ChatColor.DARK_PURPLE + PGMTranslations.t("teamSelection.picker.tooltip", player)));

    stack.setItemMeta(meta);
    ITEM_TAG.set(stack, "join");
    return stack;
}
 
Example 4
Source File: Challenge.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public List<ItemStack> getRequiredItems(int timesCompleted) {
    List<ItemStack> items = new ArrayList<>();
    for (String item : requiredItems) {
        if (item == null || item.trim().isEmpty()) {
            continue; // Just skip it
        }
        Matcher m = REQ_PATTERN.matcher(item);
        if (m.matches()) {
            int amount = Integer.parseInt(m.group("amount"), 10);
            char op = m.group("op") != null ? m.group("op").charAt(0) : 0;
            int inc = m.group("inc") != null ? Integer.parseInt(m.group("inc"), 10) : 0;
            amount = ChallengeLogic.calcAmount(amount, op, inc, timesCompleted);
            ItemStack mat = ItemStackUtil.createItemStack(m.group("itemstack"));
            ItemMeta meta = mat.getItemMeta();
            mat.setItemMeta(meta);
            mat = NBTUtil.addNBTTag(mat, m.group("meta"));
            mat.setAmount(amount);
            items.add(mat);
        } else if (!item.matches("[0-9]+") && type != Type.ISLAND_LEVEL) {
            uSkyBlock.getInstance().getLogger().log(Level.INFO, "Malformed challenge " + name + ", item: " + item + " is not a valid required item");
        }
    }
    return items;
}
 
Example 5
Source File: InventoryMenuItem.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
default ItemStack createItem(MatchPlayer player) {
  ItemStack stack = new ItemStack(getMaterial(player));
  ItemMeta meta = stack.getItemMeta();

  meta.setDisplayName(
      getColor()
          + ChatColor.BOLD.toString()
          + TextTranslations.translateLegacy(getName(), player.getBukkit()));
  meta.setLore(getLore(player));
  meta.addItemFlags(ItemFlag.values());

  stack.setItemMeta(meta);

  return stack;
}
 
Example 6
Source File: OLD_ItemFact.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
public static void removeOutOfAmmoToDisplayname(final Gun g, final Player player, ItemStack is, final int slot) {
	ItemStack temp = player.getInventory().getItem(slot);
	if (temp != null && temp.isSimilar(is)) {
		ItemMeta im = is.getItemMeta();
		im.setDisplayName(g.getDisplayName());
		is.setItemMeta(im);
		player.getInventory().setItem(slot, is);
	}
}
 
Example 7
Source File: SkullUtils.java    From XSeries with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Nonnull
public static ItemStack getSkull(@Nonnull UUID id) {
    ItemStack head = XMaterial.PLAYER_HEAD.parseItem();
    SkullMeta meta = (SkullMeta) head.getItemMeta();

    if (XMaterial.isNewVersion()) meta.setOwningPlayer(Bukkit.getOfflinePlayer(id));
    else meta.setOwner(id.toString());

    head.setItemMeta(meta);
    return head;
}
 
Example 8
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public void playerJoinTeam(Player player, Team team) {
  if (team.getPlayers().size() >= team.getMaxPlayers()) {
    player.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamfull")));
    return;
  }

  if (team.addPlayer(player)) {
    this.nonFreePlayer(player);

    // Team color chestplate
    ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    LeatherArmorMeta meta = (LeatherArmorMeta) chestplate.getItemMeta();
    meta.setColor(team.getColor().getColor());
    meta.setDisplayName(team.getChatColor() + team.getDisplayName());
    chestplate.setItemMeta(meta);

    player.getInventory().setItem(7, chestplate);
    player.updateInventory();
  } else {
    player.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamfull")));
    return;
  }

  this.updateScoreboard();

  if (this.isStartable() && this.getLobbyCountdown() == null) {
    GameLobbyCountdown lobbyCountdown = new GameLobbyCountdown(this);
    lobbyCountdown.runTaskTimer(BedwarsRel.getInstance(), 20L, 20L);
    this.setLobbyCountdown(lobbyCountdown);
  }

  player
      .sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
          ._l(player, "lobby.teamjoined",
              ImmutableMap.of("team", team.getDisplayName() + ChatColor.GREEN))));
}
 
Example 9
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 10
Source File: UtilsMc.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
public static boolean offsetItemStackDamage(ItemStack item, int offset) {
	ItemMeta meta = item.getItemMeta();
	if (meta instanceof Damageable) {
		((Damageable) meta).setDamage(((Damageable) meta).getDamage() + offset);
		item.setItemMeta(meta);
		return true;
	}
	return false;
}
 
Example 11
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 12
Source File: SchematicUtil.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void setTag(ItemStack is, ItemTag itemtag) {
    List<Ench> enchants = itemtag.getEnchants();
    //Integer repaircost = itemtag.getRepairCost();
    List<String> pages = itemtag.getPages();
    String author = itemtag.getAuthor();
    String title = itemtag.getTitle();
    Display display = itemtag.getDisplay();

    ItemMeta itemmeta = is.getItemMeta();

    if (display != null) {
        List<String> lores = display.getLore();
        String name = display.getName();

        itemmeta.setLore(lores);
        itemmeta.setDisplayName(name);
    }

    if (itemmeta instanceof BookMeta) {
        BookMeta bookmeta = (BookMeta) itemmeta;
        bookmeta.setAuthor(author);
        bookmeta.setTitle(title);
        bookmeta.setPages(pages);
    }

    if (itemmeta instanceof EnchantmentStorageMeta) {
        EnchantmentStorageMeta enchantmentstoragemeta = (EnchantmentStorageMeta) itemmeta;

        for (Ench enchant : enchants) {
            enchantmentstoragemeta.addEnchant(Enchantment.getById(enchant.getId()), enchant.getLvl(), true);
        }
    }

    is.setItemMeta(itemmeta);
}
 
Example 13
Source File: SpidersBane.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
	ItemMeta meta = tool.getItemMeta();

	if (meta != null) {
		if (ToolType.AXE.contains(tool.getType()) || ToolType.SWORD.contains(tool.getType())) {
			meta.addEnchant(Enchantment.DAMAGE_ARTHROPODS, modManager.getModLevel(tool, this), true);
		}

		tool.setItemMeta(meta);
	} else return false;

	return true;
}
 
Example 14
Source File: PickerMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack createLeaveButton(final MatchPlayer player) {
    ItemStack stack = new ItemStack(Button.LEAVE.material);

    ItemMeta meta = stack.getItemMeta();
    meta.addItemFlags(ItemFlag.values());
    meta.setDisplayName(OPEN_BUTTON_PREFIX + PGMTranslations.t("leave.picker.displayName", player));
    meta.setLore(Lists.newArrayList(ChatColor.DARK_PURPLE + PGMTranslations.t("leave.picker.tooltip", player)));

    stack.setItemMeta(meta);
    ITEM_TAG.set(stack, "leave");
    return stack;
}
 
Example 15
Source File: AdventurersGuildGUI.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack skullItemInitializer(String mhfValue, String title, List<String> lore) {

        ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
        ItemMeta itemMeta = item.getItemMeta();
        SkullMeta skullMeta = (SkullMeta) itemMeta;
        skullMeta.setOwner(mhfValue);
        item.setItemMeta(skullMeta);
        itemMeta.setDisplayName(title);
        itemMeta.setLore(lore);
        item.setItemMeta(itemMeta);

        return item;

    }
 
Example 16
Source File: VersionUtils_1_8.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack createPlayerSkull(String name, UUID uuid) {
    ItemStack item = UniversalMaterial.PLAYER_HEAD.getStack();
    SkullMeta im = (SkullMeta) item.getItemMeta();
    im.setOwner(name);
    item.setItemMeta(im);
    return item;
}
 
Example 17
Source File: WarpPowder.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
private ItemStack getCancelItemStack() {
  ItemStack glowstone = new ItemStack(this.getActivatedMaterial(), 1);
  ItemMeta meta = glowstone.getItemMeta();
  meta.setDisplayName(BedwarsRel._l("ingame.specials.warp-powder.cancel"));
  glowstone.setItemMeta(meta);

  return glowstone;
}
 
Example 18
Source File: ProjectileCooldown.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public void resetItemName(ItemStack item) {
  ItemMeta itemMeta = item.getItemMeta();
  itemMeta.setDisplayName(ItemTags.ORIGINAL_NAME.get(item));
  item.setItemMeta(itemMeta);
}
 
Example 19
Source File: ItemStackFlag.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 20
Source File: LoreStoreage.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public static void setItemName(String name ,ItemStack stack) {
	ItemMeta meta = stack.getItemMeta();
	meta.setDisplayName(name);
	stack.setItemMeta(meta);
}