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

The following examples show how to use org.bukkit.inventory.meta.ItemMeta#addItemFlags() . 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: 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 2
Source File: Reinforced.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) {
		meta.addEnchant(Enchantment.DURABILITY, modManager.getModLevel(tool, this), true);

		if (modManager.getModLevel(tool, this) == this.getMaxLvl() && this.applyUnbreakableOnMaxLevel) {
			meta.setUnbreakable(true);
			if (hideUnbreakableFlag) {
				meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
			}
		}

		tool.setItemMeta(meta);
	}

	return true;
}
 
Example 3
Source File: DefuseListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void giveKit(final ObserverKitApplyEvent event) {
    final MatchPlayer player = mm.getPlayer(event.getPlayer());
    if(player == null) return;
    if(!player.isObservingType()) return;
    if(!player.getBukkit().hasPermission("pgm.defuse")) return;

    ItemStack shears = new ItemStack(DEFUSE_ITEM);

    // TODO: Update information if locale changes
    ItemMeta meta = shears.getItemMeta();
    meta.addItemFlags(ItemFlag.values());
    meta.setDisplayName(PGMTranslations.t("defuse.displayName", player));
    meta.setLore(Lists.newArrayList(ChatColor.GRAY + PGMTranslations.t("defuse.tooltip", player)));
    shears.setItemMeta(meta);

    event.getPlayer().getInventory().setItem(DEFUSE_SLOT, shears);
}
 
Example 4
Source File: Category.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a new {@link Category} with the given {@link NamespacedKey} as an identifier
 * and the given {@link ItemStack} as its display item.
 * 
 * @param key
 *            The {@link NamespacedKey} that is used to identify this {@link Category}
 * @param item
 *            The {@link ItemStack} that is used to display this {@link Category}
 * @param tier
 *            The tier of this {@link Category}, higher tiers will make this {@link Category} appear further down in
 *            the {@link SlimefunGuide}
 */
public Category(NamespacedKey key, ItemStack item, int tier) {
    Validate.notNull(key, "A Category's NamespacedKey must not be null!");
    Validate.notNull(item, "A Category's ItemStack must not be null!");

    this.item = item;
    this.key = key;

    ItemMeta meta = item.getItemMeta();
    meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
    meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    this.item.setItemMeta(meta);
    this.tier = tier;
}
 
Example 5
Source File: IPItem.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
private void createToggleableItem(boolean flagValue, Material material, int durability, String name, UUID uuid) {
    this.flagValue = flagValue;
    this.slot = -1;
    this.name = name;
    this.type = Type.TOGGLE;
    description.clear();
    item = new ItemStack(material);
    item.setDurability((short)durability);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(ChatColor.WHITE + name);
    if (flagValue) {
        if (uuid == null)
            description.add(ChatColor.GREEN + ASkyBlock.getPlugin().myLocale().igsAllowed);
        else
            description.add(ChatColor.GREEN + ASkyBlock.getPlugin().myLocale(uuid).igsAllowed);
    } else {
        if (uuid == null)
            description.add(ChatColor.RED + ASkyBlock.getPlugin().myLocale().igsDisallowed);
        else
            description.add(ChatColor.RED + ASkyBlock.getPlugin().myLocale(uuid).igsDisallowed);
    }
    meta.setLore(description);
    // Remove extraneous info
    if (!Bukkit.getServer().getVersion().contains("1.7") && !Bukkit.getServer().getVersion().contains("1.8")) {
        meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
        meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
        meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
        meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    }
    item.setItemMeta(meta);
}
 
Example 6
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 7
Source File: ExprShinyItem.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public ItemStack convert(ItemStack itemStack) {
    if (itemStack.getType() == Material.BOW) {
        itemStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 1);
    } else {
        itemStack.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1);
    }
    ItemMeta meta = itemStack.getItemMeta();
    meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    itemStack.setItemMeta(meta);
    return itemStack;
}
 
Example 8
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 9
Source File: PickerMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack createAutoJoinButton(MatchPlayer viewer) {
    ItemStack autojoin = new ItemStack(Button.AUTO_JOIN.material);

    ItemMeta autojoinMeta = autojoin.getItemMeta();
    autojoinMeta.addItemFlags(ItemFlag.values());
    autojoinMeta.setDisplayName(ChatColor.GRAY.toString() + ChatColor.BOLD + PGMTranslations.t("teamSelection.picker.autoJoin.displayName", viewer));
    autojoinMeta.setLore(Lists.newArrayList(this.getTeamSizeDescription(viewer.getMatch().getParticipatingPlayers().size(),
                                                                        viewer.getMatch().getMaxPlayers()),
                                            ChatColor.AQUA + PGMTranslations.t("teamSelection.picker.autoJoin.tooltip", viewer)));
    autojoin.setItemMeta(autojoinMeta);

    return autojoin;
}
 
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: 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 12
Source File: ItemService.java    From Transport-Pipes with MIT License 5 votes vote down vote up
public ItemStack createGlowingItem(Material material) {
    ItemStack is = new ItemStack(material);
    ItemMeta im = is.getItemMeta();
    im.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
    im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    is.setItemMeta(im);
    return is;
}
 
Example 13
Source File: MapRatingsMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack getOpenButton(MatchPlayer player) {
    ItemStack stack = new ItemStack(Material.HOPPER);
    ItemMeta meta = stack.getItemMeta();
    meta.addItemFlags(ItemFlag.values());
    meta.setDisplayName(BUTTON_PREFIX + ChatColor.BLUE.toString() + ChatColor.BOLD + PGMTranslations.t("rating.rateThisMap", player));
    stack.setItemMeta(meta);
    return stack;
}
 
Example 14
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 15
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 16
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 17
Source File: FreezeMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack getFreezeTool(CommandSender viewer) {
  ItemStack stack = new ItemStack(TOOL_MATERIAL);
  ItemMeta meta = stack.getItemMeta();
  meta.setDisplayName(
      ChatColor.WHITE
          + ChatColor.BOLD.toString()
          + TextTranslations.translate("moderation.freeze.itemName", viewer));
  meta.addItemFlags(ItemFlag.values());
  meta.setLore(
      Collections.singletonList(
          ChatColor.GRAY
              + TextTranslations.translate("moderation.freeze.itemDescription", viewer)));
  stack.setItemMeta(meta);
  return stack;
}
 
Example 18
Source File: Parser.java    From CardinalPGM with MIT License 4 votes vote down vote up
private static void setItemFlag(ItemMeta meta, ItemFlag flag, Element element, String attribute) {
    if (element.getAttributeValue(attribute) == null) return;
    if (Numbers.parseBoolean(element.getAttributeValue(attribute), true)) meta.removeItemFlags(flag);
    else meta.addItemFlags(flag);
}
 
Example 19
Source File: ItemConstructor.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
public static ItemStack constructItem(String rawName, Material material, HashMap<Enchantment,
        Integer> enchantments, HashMap<String, Integer> customEnchantments, List<String> potionEffects,
                                      List<String> lore, String dropType, String scalabilityType) {

    ItemStack itemStack;
    ItemMeta itemMeta;

    /*
    Generate material
     */
    Material itemMaterial = MaterialGenerator.generateMaterial(material);

    /*
    Construct initial item
     */
    itemStack = ItemStackGenerator.generateItemStack(material);
    itemMeta = itemStack.getItemMeta();

    /*
    Generate item enchantments
    Note: This only applies enchantments up to a certain level, above that threshold item enchantments only exist
    in the item lore and get interpreted by the combat system
     */
    if (!enchantments.isEmpty())
        itemMeta = EnchantmentGenerator.generateEnchantments(itemMeta, enchantments);

    /*
    Generate item lore
     */
    itemMeta = LoreGenerator.generateLore(itemMeta, itemMaterial, enchantments, customEnchantments, potionEffects, lore);

    /*
    Remove vanilla enchantments
     */
    if (ConfigValues.itemsDropSettingsConfig.getBoolean(ItemsDropSettingsConfig.ENABLE_CUSTOM_ENCHANTMENT_SYSTEM))
        itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);

    /*
    Generate item name last as it relies on material type and quality
     */
    itemMeta.setDisplayName(NameGenerator.generateName(rawName));

    /*
    Colorize with MMO colors
     */
    itemStack.setItemMeta(itemMeta);
    ItemQualityColorizer.dropQualityColorizer(itemStack);

    /*
    Add item to relevant loot lists
     */
    DropWeightHandler.process(dropType, itemStack);

    /*
    Handle item scalability
     */
    ScalabilityAssigner.assign(itemStack, rawName, material, enchantments, customEnchantments, potionEffects, lore,
            dropType, scalabilityType);

    return itemStack;

}
 
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 AttachmentBase)
			lore.addAll(Gun.getGunLore(((AttachmentBase) base).getBaseGun(), null, ((AttachmentBase) 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 {
					im.spigot().setUnbreakable(true);
				} catch (Error | Exception e344) {
				}*/
				//TODO: Readd Unbreakable support for 1.9
			}
		}
		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;
}