Java Code Examples for org.bukkit.inventory.meta.ItemMeta#addEnchant()
The following examples show how to use
org.bukkit.inventory.meta.ItemMeta#addEnchant() .
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: Haste.java From MineTinker with GNU General Public License v3.0 | 6 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { if (ToolType.FISHINGROD.contains(tool.getType())) { meta.addEnchant(Enchantment.LURE, modManager.getModLevel(tool, this), true); } else if (ToolType.CROSSBOW.contains(tool.getType())) { meta.addEnchant(Enchantment.QUICK_CHARGE, modManager.getModLevel(tool, this), true); } else { meta.addEnchant(Enchantment.DIG_SPEED, modManager.getModLevel(tool, this), true); } tool.setItemMeta(meta); } return true; }
Example 2
Source File: Aquaphilic.java From MineTinker with GNU General Public License v3.0 | 6 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { if (ToolType.BOOTS.contains(tool.getType())) { meta.addEnchant(Enchantment.DEPTH_STRIDER, modManager.getModLevel(tool, this), true); } else if (ToolType.HELMET.contains(tool.getType())) { meta.addEnchant(Enchantment.OXYGEN, modManager.getModLevel(tool, this), true); meta.addEnchant(Enchantment.WATER_WORKER, modManager.getModLevel(tool, this), true); } tool.setItemMeta(meta); } return true; }
Example 3
Source File: Knockback.java From MineTinker with GNU General Public License v3.0 | 6 votes |
@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()) || ToolType.TRIDENT.contains(tool.getType())) { meta.addEnchant(Enchantment.KNOCKBACK, modManager.getModLevel(tool, this), true); } else if (ToolType.BOW.contains(tool.getType()) || ToolType.CROSSBOW.contains(tool.getType())) { meta.addEnchant(Enchantment.ARROW_KNOCKBACK, modManager.getModLevel(tool, this), true); } //Shields do not get the enchant tool.setItemMeta(meta); } return true; }
Example 4
Source File: ChallengeLogic.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
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 5
Source File: Sharpness.java From MineTinker with GNU General Public License v3.0 | 6 votes |
@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_ALL, modManager.getModLevel(tool, this), true); } else if (ToolType.BOW.contains(tool.getType()) || ToolType.CROSSBOW.contains(tool.getType())) { meta.addEnchant(Enchantment.ARROW_DAMAGE, modManager.getModLevel(tool, this), true); } else if (ToolType.TRIDENT.contains(tool.getType())) { meta.addEnchant(Enchantment.DAMAGE_ALL, modManager.getModLevel(tool, this), true); meta.addEnchant(Enchantment.IMPALING, modManager.getModLevel(tool, this), true); } tool.setItemMeta(meta); } return true; }
Example 6
Source File: SelfRepair.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { if (useMending) { meta.addEnchant(Enchantment.MENDING, modManager.getModLevel(tool, this), true); } else { meta.removeEnchant(Enchantment.MENDING); } } tool.setItemMeta(meta); return true; }
Example 7
Source File: Protecting.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, modManager.getModLevel(tool, this), true); tool.setItemMeta(meta); } return true; }
Example 8
Source File: ItemService.java From Transport-Pipes with MIT License | 5 votes |
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 9
Source File: SoulSpeed.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { meta.addEnchant(Enchantment.SOUL_SPEED, modManager.getModLevel(tool, this), true); tool.setItemMeta(meta); } return true; }
Example 10
Source File: CustomItem.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
protected final void addEnchantment(Enchantment enchantment, int level) { if (_owner == null) { ItemMeta meta = _item.getItemMeta(); meta.addEnchant(enchantment, level, true); _item.setItemMeta(meta); } }
Example 11
Source File: LightWeight.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { meta.addEnchant(Enchantment.PROTECTION_FALL, modManager.getModLevel(tool, this), true); tool.setItemMeta(meta); } return true; }
Example 12
Source File: EnchantmentGenerator.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
public static ItemMeta generateEnchantments(ItemMeta itemMeta, HashMap<Enchantment, Integer> enchantmentMap) { for (Enchantment enchantment : enchantmentMap.keySet()) if (enchantmentMap.get(enchantment) > 5 && ConfigValues.itemsDropSettingsConfig.getBoolean(ItemsDropSettingsConfig.ENABLE_CUSTOM_ENCHANTMENT_SYSTEM)) itemMeta.addEnchant(enchantment, 5, true); else itemMeta.addEnchant(enchantment, enchantmentMap.get(enchantment), true); return itemMeta; }
Example 13
Source File: Infinity.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { if (ToolType.BOW.contains(tool.getType()) || ToolType.CROSSBOW.contains(tool.getType())) { meta.addEnchant(Enchantment.ARROW_INFINITE, modManager.getModLevel(tool, this), true); } else if (ToolType.TRIDENT.contains(tool.getType())) { meta.addEnchant(Enchantment.LOYALTY, modManager.getModLevel(tool, this), true); } tool.setItemMeta(meta); } return true; }
Example 14
Source File: Piercing.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@Override public boolean applyMod(Player player, ItemStack tool, boolean isCommand) { ItemMeta meta = tool.getItemMeta(); if (meta != null) { if (ToolType.CROSSBOW.contains(tool.getType())) { meta.addEnchant(Enchantment.PIERCING, modManager.getModLevel(tool, this), true); } tool.setItemMeta(meta); } return true; }
Example 15
Source File: ItemUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static void addEnchantments(ItemMeta meta, Map<Enchantment, Integer> enchantments) { for(Map.Entry<Enchantment, Integer> enchantment : enchantments.entrySet()) { if(meta.getEnchantLevel(enchantment.getKey()) < enchantment.getValue()) { meta.addEnchant(enchantment.getKey(), enchantment.getValue(), true); } } }
Example 16
Source File: TextUtil.java From Holograms with MIT License | 4 votes |
/** * Parses an ItemStack from a string of text. * * @param text the text * @return the item * @throws NumberFormatException when an invalid amount or durability are provided * @throws IllegalArgumentException when an invalid material or enchantment is provided */ public static ItemStack parseItem(String text) { String[] split = text.split(" "); short durability = -1; String data = split[0]; if (data.contains(":")) { String[] datasplit = data.split(":"); data = datasplit[0]; durability = Short.parseShort(datasplit[1]); } Material material = data.matches("[0-9]+") ? Material.getMaterial(Integer.parseInt(data)) : Material.getMaterial(data.toUpperCase()); // Throw exception if the material provided was wrong if (material == null) { throw new IllegalArgumentException("Invalid material " + data); } int amount; try { amount = split.length == 1 ? 1 : Integer.parseInt(split[1]); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Invalid amount \"" + split[1] + "\"", ex); } ItemStack item = new ItemStack(material, amount, (short) Math.max(0, durability)); ItemMeta meta = item.getItemMeta(); // No meta data was provided, we can return here if (split.length < 3) { return item; } // Go through all the item meta specified for (int i = 2 ; i < split.length ; i++) { String[] information = split[i].split(":"); // Data, name, or lore has been specified switch (information[0].toLowerCase()) { case "name": // Replace '_' with spaces String name = information[1].replace(' ', ' '); meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); break; case "lore": // If lore was specified 2x for some reason, don't overwrite List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>(); String[] loreLines = information[1].split("\\|"); // Format all the lines and add them as lore for (String line : loreLines) { line = line.replace('_', ' '); // Replace '_' with space lore.add(ChatColor.translateAlternateColorCodes('&', line)); } meta.setLore(lore); break; case "data": short dataValue = Short.parseShort(information[1]); item.setDurability(dataValue); default: // Try parsing enchantment if it was nothing else Enchantment ench = Enchantment.getByName(information[0].toUpperCase()); int level = Integer.parseInt(information[1]); if (ench != null) { meta.addEnchant(ench, level, true); } else { throw new IllegalArgumentException("Invalid enchantment " + information[0]); } break; } } // Set the meta and return created item line item.setItemMeta(meta); return item; }
Example 17
Source File: CustomItemStack.java From AdditionsAPI with MIT License | 4 votes |
@SuppressWarnings("deprecation") private static ItemStack getItemStack(CustomItem cItem, short durability) { if (AdditionsAPI.getAllCustomItemStacks() != null) for (CustomItemStack cStack : AdditionsAPI.getAllCustomItemStacks()) if (cStack.getCustomItem().getIdName().equalsIgnoreCase(cItem.getIdName())) return cStack.getItemStack(); // Material, amount and durability ItemStack item = NbtFactory .getCraftItemStack(new ItemStack(cItem.getMaterial(), cItem.getAmount(), durability)); // Store data in the nbt data of the ItemStack about the CustomItem's ID NbtCompound nbt = NbtFactory.fromItemTag(item); nbt.put("CustomItem.IdName", cItem.getIdName()); ItemMeta meta = item.getItemMeta(); // Unbreakable meta.setUnbreakable(cItem.isUnbreakable()); // Display Name meta.setDisplayName(cItem.getDisplayName()); // Enchantments for (Enchantment e : cItem.getEnchantmnets().keySet()) meta.addEnchant(e, cItem.getEnchantmnets().get(e), true); // Lore meta.setLore(cItem.getFullLore(cItem.getEnchantmnets(), cItem.getFakeDurability(), null)); // ItemFlags for (ItemFlag flag : cItem.getItemFlags()) meta.addItemFlags(flag); // Set the lore and return the item item.setItemMeta(meta); // Add Attributes for (Attributes.Attribute attribute : cItem.getAttributes()) { Attributes attributes = new Attributes(item); attributes.add(attribute); item = attributes.getStack(); } // Leather Armor stuff if (cItem instanceof CustomLeatherArmor) { LeatherArmorMeta leatherMeta = (LeatherArmorMeta) item.getItemMeta(); leatherMeta.setColor(((CustomLeatherArmor) cItem).getColor()); item.setItemMeta(leatherMeta); } return item; }
Example 18
Source File: FlagGui.java From RedProtect with GNU General Public License v3.0 | 4 votes |
public FlagGui(String name, Player player, Region region, boolean editable, int maxSlots) { this.editable = editable; this.name = name; this.player = player; this.region = region; if (maxSlots <= 9) { this.size = 9; } else if (maxSlots <= 18) { this.size = 18; } else if (maxSlots <= 27) { this.size = 27; } else if (maxSlots <= 36) { this.size = 36; } else if (maxSlots <= 45) { this.size = 45; } else if (maxSlots <= 54) { this.size = 54; } else { throw new IllegalArgumentException("Parameter size is exceeding size limit (54)"); } this.guiItems = new ItemStack[this.size]; allowEnchant = RedProtect.get().bukkitVersion >= 181; for (String flag : RedProtect.get().config.getDefFlags()) { try { if (!RedProtect.get().config.guiRoot().gui_flags.containsKey(flag)) { continue; } if (RedProtect.get().ph.hasFlagPerm(player, flag) && (RedProtect.get().config.configRoot().flags.containsKey(flag) || RedProtect.get().config.AdminFlags.contains(flag))) { if (flag.equals("pvp") && !RedProtect.get().config.configRoot().flags.containsKey("pvp")) { continue; } int i = RedProtect.get().config.getGuiSlot(flag); Object flagValue = region.getFlags().get(flag); String flagString; if (flagValue instanceof Boolean) { flagString = RedProtect.get().guiLang.getFlagString(flagValue.toString()); } else { flagString = RedProtect.get().guiLang.getFlagString("list"); } if (flag.equalsIgnoreCase("clan")) { if (flagValue.toString().equals("")) { flagString = RedProtect.get().guiLang.getFlagString("false"); } else { flagString = RedProtect.get().guiLang.getFlagString("true"); } } this.guiItems[i] = new ItemStack(Material.getMaterial(RedProtect.get().config.guiRoot().gui_flags.get(flag).material)); ItemMeta guiMeta = this.guiItems[i].getItemMeta(); guiMeta.setDisplayName(translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagName(flag))); List<String> lore = new ArrayList<>(Arrays.asList( translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + flagString), "ยง0" + flag)); lore.addAll(RedProtect.get().guiLang.getFlagDescription(flag)); guiMeta.setLore(lore); if (allowEnchant) { if (flagValue.toString().equalsIgnoreCase("true")) { guiMeta.addEnchant(Enchantment.DURABILITY, 0, true); } else { guiMeta.removeEnchant(Enchantment.DURABILITY); } guiMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } else { if (flagValue.toString().equalsIgnoreCase("true")) { this.guiItems[i].setAmount(2); } else { this.guiItems[i].setAmount(1); } } this.guiItems[i].setType(Material.getMaterial(RedProtect.get().config.guiRoot().gui_flags.get(flag).material)); this.guiItems[i].setItemMeta(guiMeta); } } catch (Exception e) { this.player.sendMessage(ChatColor.RED + "Seems RedProtect have a wrong Item Gui or a problem on guiconfig for flag " + flag); } } for (int slotc = 0; slotc < this.size; slotc++) { if (this.guiItems[slotc] == null) { this.guiItems[slotc] = RedProtect.get().config.getGuiSeparator(); } } }
Example 19
Source File: ItemLine.java From Holograms with MIT License | 4 votes |
private static ItemStack parseItem(String text) { Matcher matcher = linePattern.matcher(text); if (matcher.find()) { text = matcher.group(3); } String[] split = text.split(" "); short durability = -1; String data = split[0]; if (data.contains(":")) { String[] datasplit = data.split(":"); data = datasplit[0]; durability = Short.parseShort(datasplit[1]); } Material material = data.matches("[0-9]+") ? Material.getMaterial(Integer.parseInt(data)) : Material.getMaterial(data.toUpperCase()); // Throw exception if the material provided was wrong if (material == null) { throw new IllegalArgumentException("Invalid material " + data); } int amount; try { amount = split.length == 1 ? 1 : Integer.parseInt(split[1]); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Invalid amount \"" + split[1] + "\"", ex); } ItemStack item = new ItemStack(material, amount, (short) Math.max(0, durability)); ItemMeta meta = item.getItemMeta(); // No meta data was provided, we can return here if (split.length < 3) { return item; } // Go through all the item meta specified for (int i = 2 ; i < split.length ; i++) { String[] information = split[i].split(":"); // Data, name, or lore has been specified switch (information[0].toLowerCase()) { case "name": // Replace '_' with spaces String name = information[1].replace(' ', ' '); meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); break; case "lore": // If lore was specified 2x for some reason, don't overwrite List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>(); String[] loreLines = information[1].split("\\|"); // Format all the lines and add them as lore for (String line : loreLines) { line = line.replace('_', ' '); // Replace '_' with space lore.add(ChatColor.translateAlternateColorCodes('&', line)); } meta.setLore(lore); break; case "data": short dataValue = Short.parseShort(information[1]); item.setDurability(dataValue); default: // Try parsing enchantment if it was nothing else Enchantment ench = Enchantment.getByName(information[0].toUpperCase()); int level = Integer.parseInt(information[1]); if (ench != null) { meta.addEnchant(ench, level, true); } else { throw new IllegalArgumentException("Invalid enchantment " + information[0]); } break; } } item.setItemMeta(meta); return item; }
Example 20
Source File: TierSetSpawner.java From EliteMobs with GNU General Public License v3.0 | 3 votes |
private static void applyEnchantment(ItemStack itemStack, Enchantment enchantment, int tierLevel) { ItemMeta newItemMeta = itemStack.getItemMeta(); newItemMeta.addEnchant(enchantment, tierLevel - 1, true); itemStack.setItemMeta(newItemMeta); }