public boolean upgradePearl(Inventory inv, PrisonPearl pp) {
   final String prisoner = pp.getImprisonedName();
   ItemStack is = new ItemStack(Material.ENDER_PEARL, 1, pp.getID());
   int pearlslot = inv.first(is);
   if (pearlslot < 0) {
     // If the pearl has been converted, first won't return it here
     // as the metadata doesn't match.
     return false;
   }
   ItemStack existing_is = inv.getItem(pearlslot);
   if (existing_is != null) {
     ItemMeta existing_meta = existing_is.getItemMeta();
     if (existing_meta != null) {
       String existing_name = existing_meta.getDisplayName();
       if (existing_name != null && existing_name.compareTo(prisoner) == 0) {
         return true;
       }
     }
   }
   ItemMeta im = is.getItemMeta();
   // Rename pearl to that of imprisoned player
   im.setDisplayName(prisoner);
   List<String> lore = new ArrayList<String>();
   lore.add(prisoner + " is held within this pearl");
   // Given enchantment effect
   // Durability used because it doesn't affect pearl behaviour
   im.addEnchant(Enchantment.DURABILITY, 1, true);
   im.setLore(lore);
   is.setItemMeta(im);
   is.removeEnchantment(Enchantment.DURABILITY);
   inv.clear(pearlslot);
   inv.setItem(pearlslot, is);
   return true;
 }
  @Override
  public ItemStack disenchant(ItemStack stack) {
    if (stack == null) throw new IllegalArgumentException("stack cannot be NULL.");

    stack.removeEnchantment(enchantment);
    return stack;
  }
 /**
  * Enchant.
  *
  * @param item the item
  * @param enchants the enchants
  */
 public void enchant(ItemStack item, Map<Enchantment, Integer> enchants) {
   if (item == null) {
     return;
   }
   for (Enchantment ench : item.getEnchantments().keySet()) {
     item.removeEnchantment(ench);
   }
   item.addEnchantments(enchants);
 }
示例#4
0
 // Anti Looting X
 @EventHandler
 public void removeSword(PlayerItemHeldEvent e) {
   ItemStack i = e.getPlayer().getInventory().getItem(e.getNewSlot());
   if (i != null) {
     if (i.getType() != Material.AIR && i.containsEnchantment(Enchantment.LOOT_BONUS_MOBS)) {
       if (i.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS) >= 10) {
         i.removeEnchantment(Enchantment.LOOT_BONUS_MOBS);
       }
     }
   }
 }
示例#5
0
  ItemStack getWrittenCertificate(String forum, String content) {
    ItemStack is = new ItemStack(Material.WRITTEN_BOOK, 1);
    is.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10);
    BookMeta book = (BookMeta) is.getItemMeta();
    book.setAuthor("mcRSS");
    book.setTitle(ChatColor.RED + forum);

    List<String> pages = getBookPages(content);
    for (int i = 0; i < pages.size(); i++) {
      book.addPage(pages.get(i) + ChatColor.LIGHT_PURPLE);
    }
    is.removeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL);
    is.setItemMeta(book); // Save changes

    // Return the result
    return is;
  }
示例#6
0
  public boolean removeEnchantmentsFromPlayerInventorySlot(
      String playerName, int slot, List<Object> enchantments) {
    try {
      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();
      ItemStack it;

      if (slot == inv.getHeldItemSlot()) it = inv.getHelmet();
      else if (slot == 102) it = inv.getChestplate();
      else if (slot == 101) it = inv.getLeggings();
      else if (slot == 100) it = inv.getBoots();
      else it = inv.getItem(slot);

      for (Object o : enchantments) {
        it.removeEnchantment(Enchantment.getById(Integer.valueOf(o.toString())));
      }

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
示例#7
0
	//TODO: Implement charge costs: final Trade charge = new Trade("enchant-" + enchantmentName, ess);
	@Override
	protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		final ItemStack stack = user.getPlayer().getItemInHand();
		if (stack == null)
		{
			throw new Exception(_("nothingInHand"));
		}
		if (args.length == 0)
		{
			final Set<String> enchantmentslist = new TreeSet<String>();
			for (Map.Entry<String, Enchantment> entry : Enchantments.entrySet())
			{
				final String enchantmentName = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
				if (enchantmentslist.contains(enchantmentName) || Permissions.ENCHANT.isAuthorized(user, enchantmentName))
				{
					enchantmentslist.add(entry.getKey());
					//enchantmentslist.add(enchantmentName);
				}
			}
			throw new NotEnoughArgumentsException(_("enchantments", Util.joinList(enchantmentslist.toArray())));
		}
		int level = -1;
		if (args.length > 1)
		{
			try
			{
				level = Integer.parseInt(args[1]);
			}
			catch (NumberFormatException ex)
			{
				level = -1;
			}
		}
		final boolean allowUnsafe = Permissions.ENCHANT_UNSAFE.isAuthorized(user);
		final Enchantment enchantment = getEnchantment(args[0], user);
		if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel()))
		{
			level = enchantment.getMaxLevel();
		}
		if (level == 0)
		{
			stack.removeEnchantment(enchantment);
		}
		else
		{
			if (allowUnsafe)
			{
				stack.addUnsafeEnchantment(enchantment, level);
			}
			else
			{
				stack.addEnchantment(enchantment, level);
			}
		}
		user.getPlayer().getInventory().setItemInHand(stack);
		user.getPlayer().updateInventory();
		final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
		if (level == 0)
		{
			user.sendMessage(_("enchantmentRemoved", enchantmentName.replace('_', ' ')));
		}
		else
		{
			user.sendMessage(_("enchantmentApplied", enchantmentName.replace('_', ' ')));
		}
	}
示例#8
0
 @Override
 public void run() {
   try {
     while (this.plugin.buffer.size() > 0) {
       final Item item = this.plugin.buffer.pollFirstEntry().getValue();
       if (item.isValid()) {
         final Location cauldronLoc = item.getLocation().getBlock().getLocation().clone();
         if (this.plugin.magicBenches.contains(cauldronLoc)) { // So now we act !
           final ItemStack itemStack = item.getItemStack();
           if (itemStack.getEnchantments().size() != 0) {
             final Result res =
                 this.plugin.randomizer.randomize(itemStack); // The itemStack/item is now modified
             byte data = 0; // Wool color
             float ratio = 1f; // Volume & pitch of thunder sound
             switch (res) {
               case CLEAN:
                 data = 15; // Black
                 ratio = 0.2f;
                 break;
               case LOSS:
                 data = 14; // Red
                 ratio = 0.4f;
                 break;
               case NONE:
                 data = 0; // White
                 ratio = 0.6f;
                 break;
               case BOOST:
                 data = 4; // Yellow
                 ratio = 0.8f;
                 break;
               case OVERBOOST:
                 data = 5; // Green
                 ratio = 1f;
                 break;
             }
             this.plugin.magicBenches.remove(cauldronLoc);
             cauldronLoc
                 .getWorld()
                 .playSound(cauldronLoc, Sound.AMBIENCE_THUNDER, ratio, ratio * 2f);
             cauldronLoc.subtract(0, 1, 0); // Is now Egg location
             cauldronLoc.getWorld().playEffect(item.getLocation(), Effect.ENDER_SIGNAL, 0);
             if (cauldronLoc.getBlock().getType() != Material.DRAGON_EGG) {
               // Prevent possible cheat : if the player remove the egg before this happen, we
               // remove every enchants
               // As the interact event is cancelled in ME_Listener, this should never happen.
               for (final Enchantment e : itemStack.getEnchantments().keySet()) {
                 itemStack.removeEnchantment(e);
               }
               cauldronLoc.getWorld().playSound(cauldronLoc, Sound.ENDERDRAGON_DEATH, 1.0f, 1.5f);
             }
             cauldronLoc.getBlock().setType(Material.AIR); // Delete the Egg
             this.plugin.fakeWool(
                 cauldronLoc,
                 data,
                 this.plugin.getNearbyPlayers(item, 10, 5, 10)); // Wool color effect
           }
         }
       }
       if (item.isValid()) {
         item.setPickupDelay(0);
       }
     }
   } catch (final Exception e) {
     e.printStackTrace();
   }
 }