Wietje/SkyWars — pull request #9 by andypandy89 (2013-12-29 16:22:16+00:00)
Title: Rewrite of parseItem

Rewrote parseItem() in ItemUtils. It works like this:
Format of args Name:Durability/Data Amount Enchantment1:Level,Enchantment2:Level
- First uses org.Bukkit.Material.matchMaterial() method. Matches Material if Material name is correct, also parses MaterialId.
- If not found and Essentials is present, look up String in Essentials ItemDb. ItemDb parses strings like "bluewool", which means that it can also match durability/data before the colon. New Essentials API (net.ess3.api.IEssentials) is used, which means it will break compability with previous versions of Essentials (pre 2.12) and produce a NoSuchMethodError. I've not been able to get around this, as the old API calls no longer work. The new API should be compatible with future versions of Essentials as the API is changed in preparation for Essentials 3.x. As getEssentials() in main class was no longer needed, it was removed. Also changed Essentials from dependency to soft-dependency, since even without Essentials, there will be two dependencies present capable of resolving items.
- If not found and WorldEdit is present, com.sk89q.worldedit.blocks.ItemType.getMaterial.lookup() is used. This will return an ItemType if found. In most cases the ItemType.toString() will be equal to Material.toString(), but since this is not always the case, IDs must be used even though Material.getMaterial(int) is deprecated.
- If not found and Vault is found, the method net.milbowl.vault.item.Items.itemByString() is used. The reason it has been placed last is because both Essentials and WorldEdit provides more reliable item-parsing. Vault is also able to resolve durability/datavalue in string before the colon.

If durability hasn't been found by Essentials or Vault, and it was specified with a colon, we'll try to parseShort and use that if it is a numeric value. Otherwise, if CommandBook is present, it'll try to use com.sk89q.commandbook.util.ItemUtil.matchItemData() to find the durability/data short value. This method utilizes several classes from both CommandBook and WorldEdit (WorldEdit is a dependency for CommandBook).

If amount was specified, it'll control that it can be parsed as an int and that the amount specified is not above the max. allowed size for the relevant ItemStack.

Enchantments will then be parsed if present (looping through enchantments separated in input by comma), It'll attempt to use com.earth2me.essentials.Enchantments.getByName() to resolve Enchantment if Essentials is present, otherwise it'll attempt to match Enchantment with a very simple regex (Neither CommandBook or WorldEdit provides any methods of resolving enchantments).
If Enchantment was found, it'll verify that the enchantment can be applied to the ItemStack and that the enchantment level is within the allowed value range for the specific Enchantment.

WhatIsIt.itemName() in KitController is replaced with ItemUtils.itemName() which again uses WhatIsIt if found (WhatIsIt has been changed from dependency to softdependency). If WhatIsIt is not present it'll attempt to get a friendly name from Essentials, Vault, WorldEdit and lastly just stack.toString(). Ordering is determined based of how nicely these plugins are able to give a proper friendly name. (WorldEdit does not specify potion-type if it's a potion for instance).

Added a warning log entry in KitController and ChestController if items could not be resolved by ItemUtils.parseItem() to notify the server admin.

Updated Essentials.jar in lib to 2.12.2.