예제 #1
0
 private static boolean sameEnchants(ItemStack a, ItemStack b) {
   if (a.getEnchantments().size() == b.getEnchantments().size()) {
     for (Enchantment e : a.getEnchantments().keySet()) {
       if (!b.containsEnchantment(e) || b.getEnchantmentLevel(e) != a.getEnchantmentLevel(e)) {
         return false;
       }
     }
     return true;
   }
   return false;
 }
예제 #2
0
 ItemStack updateEnchants(ItemStack item) {
   ArrayList<String> enchants = new ArrayList<String>();
   for (Enchantment ench : item.getEnchantments().keySet()) {
     if (!isNatural(ench)) {
       enchants.add(
           ChatColor.GRAY + ench.getName() + " " + toRoman(item.getEnchantments().get(ench)));
     }
   }
   ItemMeta meta = item.getItemMeta();
   meta.setLore(enchants);
   item.setItemMeta(meta);
   return item;
 }
예제 #3
0
  @Command(
      command = "iteminfo",
      aliases = {"iinfo"},
      description = "Shows information about items",
      syntax =
          "/iteminfo §2(what's the item in hand?) \n"
              + "/iteminfo §712§f §2(what's the item with ID §712§2?) \n"
              + "/iteminfo §7log§f §2(what's the item ID of §7LOG§2?)")
  public static boolean itemInfo(CommandSender sender, String currentAlias, String[] args) {
    ItemStack item;

    if (args.length == 0) {
      if (!(sender instanceof Player)) {
        return false;
      }

      item = ((Player) sender).getItemInHand();
    } else {
      item = MaterialUtil.getItem(StringUtil.joinArray(args));
    }

    if (item == null || item.getType() == Material.AIR) {
      return false;
    }

    String durability =
        (item.getDurability() != 0 ? ChatColor.DARK_GREEN + ":" + item.getDurability() : "");

    String enchantmentString = MaterialUtil.Enchantments.encodeEnchantment(item.getEnchantments());
    String enchantment =
        (enchantmentString != null ? ChatColor.DARK_AQUA + "-" + enchantmentString : "");

    String itemName = MaterialUtil.getName(item);

    EventUtils.sendMessage(new MessageEvent("iteminfo"), sender);

    sender.sendMessage(
        ChatColor.GRAY
            + itemName
            + ChatColor.WHITE
            + "     "
            + item.getTypeId()
            + durability
            + enchantment);

    sendEnchantments(item.getEnchantments(), sender);

    return true;
  }
 @EventHandler
 public void HeMan(PlayerChatEvent e) {
   if (e.isCancelled()) return;
   if (!e.getMessage().matches("(?i)by the power of gr[a|e]yskull!?")) return;
   Player p = e.getPlayer();
   if (!plugin.isAuthorized(p, "rcmds.heman")) return;
   ItemStack is = p.getItemInHand();
   if (is.getType() != Material.DIAMOND_SWORD) return;
   if (is.getEnchantments().isEmpty()) return;
   e.setCancelled(true);
   p.getWorld().strikeLightningEffect(p.getLocation());
   Matcher m = Pattern.compile("(?i)by the power of gr[a|e]yskull!?").matcher(e.getMessage());
   StringBuilder sb = new StringBuilder();
   int last = 0;
   while (m.find()) {
     sb.append(e.getMessage().substring(last, m.start()));
     sb.append(m.group(0).toUpperCase());
     last = m.end();
   }
   sb.append(e.getMessage().substring(last));
   plugin
       .getServer()
       .broadcastMessage(
           e.getFormat().replaceAll("(?i)by the power of gr[a|e]yskull!?", sb.toString()));
   e.setFormat("");
   List<PotionEffect> effects = new ArrayList<PotionEffect>();
   effects.add(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.REGENERATION, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.SPEED, 1200, 2));
   p.addPotionEffects(effects);
 }
예제 #5
0
 public String getEnchantmentTypeName(ItemStack itemStack) {
   Enchantment enchantment = null;
   Integer level = 0;
   for (Map.Entry<Enchantment, Integer> e : itemStack.getEnchantments().entrySet()) {
     if (e.getValue() > level) {
       enchantment = e.getKey();
       level = e.getValue();
     }
   }
   if (enchantment == null) {
     return getPlugin()
         .getConfigurationManager()
         .getConfiguration(MythicConfigurationFile.LANGUAGE)
         .getString("Ordinary");
   }
   String ench =
       getPlugin()
           .getConfigurationManager()
           .getConfiguration(MythicConfigurationFile.LANGUAGE)
           .getString(enchantment.getName());
   if (ench != null) {
     return ench;
   }
   return "Ordinary";
 }
예제 #6
0
  /**
   * Converts specified inventory into inventory string and stores it. Previous inventory string
   * will be deleted.
   *
   * @param playerinv inventory that will be stored
   */
  public void storeInventory(PlayerInventory playerinv) {
    String inv = "";
    for (int i = 0; i < 40; i++) {
      ItemStack item = playerinv.getItem(i);
      if (item == null || item.getType() == Material.AIR) continue;

      String enchantString = "";
      for (Entry<Enchantment, Integer> e : item.getEnchantments().entrySet())
        enchantString +=
            String.valueOf(e.getKey().getId()) + ":" + String.valueOf(e.getValue()) + "*";
      if (enchantString.length() > 1)
        enchantString = enchantString.substring(0, enchantString.length() - 1);

      inv +=
          String.valueOf(item.getTypeId())
              + ","
              + String.valueOf(item.getAmount())
              + ","
              + String.valueOf(item.getDurability())
              + ","
              + enchantString
              + ";";
    }
    inventory = inv;
    InputOutput.UpdatePrisoner(this);
  }
  public static String InventoryToString(Inventory invInventory) {
    String serialization = invInventory.getSize() + ";";
    for (int i = 0; i < invInventory.getSize(); i++) {
      ItemStack is = invInventory.getItem(i);
      if (is != null) {
        String serializedItemStack = new String();

        String isType = String.valueOf(is.getType().getId());
        serializedItemStack += "t@" + isType;

        if (is.getDurability() != 0) {
          String isDurability = String.valueOf(is.getDurability());
          serializedItemStack += ":d@" + isDurability;
        }

        if (is.getAmount() != 1) {
          String isAmount = String.valueOf(is.getAmount());
          serializedItemStack += ":a@" + isAmount;
        }

        Map<Enchantment, Integer> isEnch = is.getEnchantments();
        if (isEnch.size() > 0) {
          for (Entry<Enchantment, Integer> ench : isEnch.entrySet()) {
            serializedItemStack += ":e@" + ench.getKey().getId() + "@" + ench.getValue();
          }
        }

        serialization += i + "#" + serializedItemStack + ";";
      }
    }
    return serialization;
  }
예제 #8
0
 /**
  * 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);
 }
예제 #9
0
 private void writeItemStack(final Object data) {
   final ItemStack itemStack = (ItemStack) data;
   writeMaterialData(itemStack.getData());
   writer.print(' ');
   writer.print(itemStack.getAmount());
   for (Entry<Enchantment, Integer> entry : itemStack.getEnchantments().entrySet()) {
     writer.print(' ');
     writeEnchantmentLevel(entry);
   }
 }
 public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
   if (cmd.getName().equalsIgnoreCase("deldrop")) {
     Player player = (Player) sender;
     if (!player.hasPermission("kits.admin")) {
       plugin.send(player, "no-permission");
       return true;
     } else {
       ItemStack i = player.getItemInHand();
       if (i != null && !i.getType().equals(Material.AIR)) {
         FileConfiguration fc = plugin.customFile("drops");
         if (fc.getConfigurationSection("drops") == null) {
           plugin.send(player, "not-a-blocked-drop");
           return true;
         } else {
           for (String v : fc.getConfigurationSection("drops").getKeys(false)) {
             ItemStack ni = fc.getItemStack("drops." + v);
             if (ni.getType().equals(i.getType())) {
               if (ni.getData().getData() == i.getData().getData()) {
                 if (ni.getItemMeta().equals(i.getItemMeta())) {
                   if (ni.getEnchantments().equals(i.getEnchantments())) {
                     fc.set("drops." + v, null);
                     plugin.send(player, "deleted-drop");
                     try {
                       fc.save(plugin.customData("drops"));
                     } catch (IOException e) {
                       e.printStackTrace();
                     }
                     return true;
                   }
                 }
               }
             }
           }
           plugin.send(player, "not-a-blocked-drop");
         }
       } else {
         plugin.send(player, "hold-item");
       }
     }
   }
   return true;
 }
예제 #11
0
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent e) {
    List<ItemStack> drops = new ArrayList<ItemStack>();
    SlimefunItem sfItem = BlockStorage.check(e.getBlock());
    ItemStack item = e.getPlayer().getItemInHand();
    int fortune = 1;
    if (sfItem != null && !(sfItem instanceof HandledBlock))
      drops.add(BlockStorage.retrieve(e.getBlock()));
    else if (item != null) {
      if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS)
          && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
        fortune = main.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
        if (fortune <= 0) fortune = 1;
        fortune =
            (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + main.randomize(5) : 1)
                * (fortune + 1);
      }

      for (ItemHandler handler : SlimefunItem.getHandlers("BlockBreakHandler")) {
        if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break;
      }
    }

    if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)
        && e.getBlock().getType().toString().endsWith("_ORE")) {
      if (Talisman.checkFor(e, SlimefunItem.getByName("MINER_TALISMAN"))) {
        if (drops.isEmpty()) drops = (List<ItemStack>) e.getBlock().getDrops();
        for (ItemStack drop : new ArrayList<ItemStack>(drops)) {
          if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
        }
      }
    }

    if (!drops.isEmpty()) {
      e.getBlock().setType(Material.AIR);
      for (ItemStack drop : drops) {
        e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop);
      }
    }
  }
예제 #12
0
  @EventHandler
  public static void addEnchantment(ItemInfoEvent event) {
    ItemStack item = event.getItem();
    CommandSender sender = event.getSender();

    Map<Enchantment, Integer> enchantments = item.getEnchantments();

    for (Map.Entry<Enchantment, Integer> enchantment : enchantments.entrySet()) {
      sender.sendMessage(
          ChatColor.DARK_GRAY
              + capitalizeFirstLetter(enchantment.getKey().getName(), '_')
              + ' '
              + toRoman(enchantment.getValue()));
    }
  }
예제 #13
0
파일: Fishing.java 프로젝트: bigggan/mcMMO
  /**
   * Process results from Fishing.
   *
   * @param event The event to modify
   */
  public static void processResults(PlayerFishEvent event) {
    Player player = event.getPlayer();
    PlayerProfile PP = Users.getProfile(player);

    getFishingResults(player, event);
    Item theCatch = (Item) event.getCaught();

    if (theCatch.getItemStack().getType() != Material.RAW_FISH) {
      final int ENCHANTMENT_CHANCE = 10;
      boolean enchanted = false;
      ItemStack fishingResults = theCatch.getItemStack();

      player.sendMessage(mcLocale.getString("Fishing.ItemFound"));
      if (ItemChecks.isArmor(fishingResults) || ItemChecks.isTool(fishingResults)) {
        if (random.nextInt(100) <= ENCHANTMENT_CHANCE) {
          for (Enchantment newEnchant : Enchantment.values()) {
            if (newEnchant.canEnchantItem(fishingResults)) {
              Map<Enchantment, Integer> resultEnchantments = fishingResults.getEnchantments();

              for (Enchantment oldEnchant : resultEnchantments.keySet()) {
                if (oldEnchant.conflictsWith(newEnchant)) {
                  return;
                }
              }

              /* Actual chance to have an enchantment is related to your fishing skill */
              if (random.nextInt(15) < Fishing.getFishingLootTier(PP)) {
                enchanted = true;
                int randomEnchantLevel = random.nextInt(newEnchant.getMaxLevel()) + 1;

                if (randomEnchantLevel < newEnchant.getStartLevel()) {
                  randomEnchantLevel = newEnchant.getStartLevel();
                }

                fishingResults.addEnchantment(newEnchant, randomEnchantLevel);
              }
            }
          }
        }
      }

      if (enchanted) {
        player.sendMessage(mcLocale.getString("Fishing.MagicFound"));
      }
    }
  }
예제 #14
0
 public void setProperty(final String path, final ItemStack stack) {
   final Map<String, Object> map = new HashMap<String, Object>();
   map.put("type", stack.getType().toString());
   map.put("amount", stack.getAmount());
   map.put("damage", stack.getDurability());
   Map<Enchantment, Integer> enchantments = stack.getEnchantments();
   if (!enchantments.isEmpty()) {
     Map<String, Integer> enchant = new HashMap<String, Integer>();
     for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
       enchant.put(entry.getKey().getName().toLowerCase(Locale.ENGLISH), entry.getValue());
     }
     map.put("enchant", enchant);
   }
   // getData().getData() is broken
   // map.put("data", stack.getDurability());
   set(path, map);
 }
예제 #15
0
 public static void updateItem(
     ItemStack item, String locale, RPGMetadata rpgMeta, boolean updateDurability) {
   RPGItem rItem = ItemManager.toRPGItem(item);
   if (rItem == null) return;
   item.setType(rItem.item.getType());
   ItemMeta meta = rItem.getLocaleMeta(locale);
   if (!(meta instanceof LeatherArmorMeta) && updateDurability) {
     item.setDurability(rItem.item.getDurability());
   }
   List<String> lore = meta.getLore();
   rItem.addExtra(rpgMeta, item, lore);
   lore.set(0, meta.getLore().get(0) + rpgMeta.toMCString());
   meta.setLore(lore);
   Map<Enchantment, Integer> enchantments = null;
   if (enchantmentSupport) enchantments = item.getEnchantments();
   item.setItemMeta(meta);
   if (enchantmentSupport) item.addEnchantments(enchantments);
 }
예제 #16
0
	private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired)
	{
		for (ItemStack item : items)
		{
			if (item == null)
			{
				continue;
			}
			final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
			final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), "repair-item", ess);
			try
			{
				charge.isAffordableFor(user);
			}
			catch (ChargeException ex)
			{
				user.sendMessage(ex.getMessage());
				continue;
			}
			if (!item.getEnchantments().isEmpty()
				&& !Permissions.REPAIR_ENCHANTED.isAuthorized(user))
			{
				continue;
			}

			try
			{
				repairItem(item);
			}
			catch (Exception e)
			{
				continue;
			}
			try
			{
				charge.charge(user);
			}
			catch (ChargeException ex)
			{
				user.sendMessage(ex.getMessage());
			}
			repaired.add(itemName.replace('_', ' '));
		}
	}
예제 #17
0
 /**
  * add an ItemStack to an array
  *
  * @param items
  * @param toAdd
  * @param extraStack whether to allow some nonstackable items to stack
  * @return
  */
 public static ItemStack add(ItemStack[] items, ItemStack toAdd, boolean extraStack) {
   ItemStack ret = toAdd.clone();
   int mx = !extraStack || noStack.contains(toAdd.getTypeId()) ? JItems.getMaxStack(toAdd) : 64;
   boolean firstRun = true;
   for (int i = 0; i < items.length; ++i) {
     if (!firstRun && (items[i] == null || items[i].getAmount() == 0)) {
       if (items[i] == null) {
         items[i] = toAdd;
       } else {
         items[i].setTypeId(toAdd.getTypeId());
         items[i].setDurability(toAdd.getDurability());
         items[i].addEnchantments(toAdd.getEnchantments());
       }
       items[i].setAmount(ret.getAmount());
       ret.setAmount(0);
       return ret;
     } else if (items[i] != null
         && items[i].getTypeId() == toAdd.getTypeId()
         && items[i].getDurability()
             == toAdd
                 .getDurability() // (!JItems.hasData(toAdd.getTypeId()) ||
                                  // items[i].getData().getData() == toAdd.getData().getData())
         && sameEnchants(items[i], toAdd)
         && items[i].getAmount() < mx) {
       // on first run, look for other stacks in array that could be incremented instead
       if (items[i].getAmount() + ret.getAmount() <= mx) {
         items[i].setAmount(items[i].getAmount() + ret.getAmount());
         ret.setAmount(0);
         return ret;
       } else {
         ret.setAmount(ret.getAmount() - (mx - items[i].getAmount()));
         items[i].setAmount(mx);
       }
     } else if (firstRun && i + 1 >= items.length) {
       firstRun = false;
       i = -1; // negative, because gets incremented again
     }
   }
   return ret;
 }
예제 #18
0
	private Trade rechargeSign(final ISign sign, final IEssentials ess, final IUser player) throws SignException, ChargeException
	{
		final Trade trade = getTrade(sign, 2, false, false, ess);
		ItemStack itemInHand = player.getPlayer().getItemInHand();
		if (trade.getItemStack() != null && itemInHand != null
			&& trade.getItemStack().getTypeId() == itemInHand.getTypeId()
			&& trade.getItemStack().getDurability() == itemInHand.getDurability()
			&& trade.getItemStack().getEnchantments().equals(itemInHand.getEnchantments()))
		{
			int amount = itemInHand.getAmount();
			amount -= amount % trade.getItemStack().getAmount();
			if (amount > 0)
			{
				final ItemStack stack = itemInHand.clone();
				stack.setAmount(amount);
				final Trade store = new Trade(stack, ess);
				addAmount(sign, 2, store, ess);
				store.charge(player);
				return store;
			}
		}
		return null;
	}
  /**
   * Checks if the item can have this enchant and whether it is upgradable via this object
   *
   * @param stack the stack to check
   * @return true if it is enchantable and upgradable
   */
  public boolean canEnchant(ItemStack stack) {
    if (stack == null) return false;

    if (!enchantment.canEnchantItem(stack)) return false;

    // check each enchant on the item
    Map<Enchantment, Integer> current = stack.getEnchantments();
    for (Map.Entry<Enchantment, Integer> e : current.entrySet()) {

      // if it's the same enchantment
      if (e.getKey().equals(enchantment)) {
        // check if we can up a level
        return canEnchantAtLevel(e.getValue() + 1);
      }

      // check for conflicts with existing enchant
      if (e.getKey().conflictsWith(enchantment)) {
        return false;
      }
    }

    return true;
  }
예제 #20
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();
   }
 }
예제 #21
0
 public BukkitItemStack(ItemStack item) {
   this(item.getType(), item.getAmount(), item.getDurability());
   addUnsafeEnchantments(item.getEnchantments());
 }
예제 #22
0
 public static void saveEnchantments(
     final ConfigurationSection config, final String path, final ItemStack item) {
   saveEnchantments(config, path, item.getEnchantments());
 }
예제 #23
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}

		if (args[0].equalsIgnoreCase("hand"))
		{
			final ItemStack item = user.getPlayer().getItemInHand();
			if (item == null)
			{
				throw new Exception(_("repairInvalidType"));
			}

			if (!item.getEnchantments().isEmpty()
				&& !Permissions.REPAIR_ENCHANTED.isAuthorized(user))
			{
				throw new Exception(_("repairEnchanted"));
			}

			final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
			final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);

			charge.isAffordableFor(user);

			repairItem(item);

			charge.charge(user);

			user.sendMessage(_("repair", itemName.replace('_', ' ')));
		}
		else if (args[0].equalsIgnoreCase("all"))
		{
			final Trade charge = new Trade("repair-all", ess);
			charge.isAffordableFor(user);
			final List<String> repaired = new ArrayList<String>();
			repairItems(user.getPlayer().getInventory().getContents(), user, repaired);

			if (Permissions.REPAIR_ARMOR.isAuthorized(user))
			{
				repairItems(user.getPlayer().getInventory().getArmorContents(), user, repaired);
			}

			if (repaired.isEmpty())
			{
				throw new Exception(_("repairNone"));
			}
			else
			{
				user.sendMessage(_("repair", Util.joinList(repaired)));
			}
			charge.charge(user);

		}
		else
		{
			throw new NotEnoughArgumentsException();
		}
	}