API ItemAPI - easy item modification and custom enchants

Discussion in 'Resources' started by nj2miami, Apr 17, 2015.

?

Did you find this API useful?

  1. Yes

  2. No

Results are only viewable after voting.
Thread Status:
Not open for further replies.
  1. Offline

    nj2miami

    Download ItemAPI here: http://dev.bukkit.org/bukkit-plugins/itemlib/

    Hey guys. I am sharing my API I created to help facilitate modifying items a bit simpler for those who are developing. The short version is it simply allows you to change/remove damage value from weapons/tools, add "fake glow" to an item (so it looks enchanted) but most importantly, has an entire system of custom enchantments.

    Custom enchantments are a class named CustomEnchantment which extends Enchantment

    Implementation

    Add ItemAPI.jar to your project and make sure it is on the server you intend. It requires ProtocolLib so make sure you have the appropriate version as well installed on the target server.

    You can then call any of the many static methods available to you. I will outline them below with their return values.
    • ItemAPI.getLoadedEnchants() - this returns a Set<String> of the short names of all loaded custom enchants
    • ItemAPI.getCustomEnch(String c) - returns a CustomEnchantment which matches the String
    • ItemAPI.removeDamageFromItem(ItemStack item) - returns the modified ItemStack
    • ItemAPI.setDamageOnWeapon(ItemStack item, Integer damage) - returns the modified ItemStack
    • ItemAPI.setHealthOnItem(ItemStack item, Integer health) - returns the modified
    • ItemAPI.getHealthOnItem(ItemStack item) - returns the +health on the ItemStack
    • ItemAPI.addGlow(ItemStack item) - adds a "fake enchant" to let the Item show as it was enchanted
    • ItemAPI.removeGlow(ItemStack item) - removed the "fake enchant" to "unglow" an item
    • ItemAPI.addEnchantment(ItemStack i, String e) - adds or increments an existing CustomEnchantment (matches the provided String)
    • ItemAPI.addEnchantment(ItemStack i, String e, int l) - same as above except it forces a specific enchant level 'int l'

    Examples
    You want to add a +2 Health bonus (1 Heart) to a Diamond Sword in a players hand. You will receive the modified ItemStack back.

    Player p;
    p.setItemInHand(ItemAPI.setHealthOnItem(p.getItemInHand(), 2));


    Add a new CustomEnchantment called "Tiger's Blood". Edit the config.yml and add the following:
    tiger:
    id: 180
    display: Tiger's Blood
    enable: true
    handle: false
    maxlevel: 5
    cooldown: 0

    So to breakdown the above:
    'tiger' is the short name to assign to the CustomEnchantment and will be used when attempting to add to an Item.
    'id' is the unique ID to use, I suggest staying in sequence and not changing once you add it. Simply set 'enable' to false to disable CustomEnchantments. Do not change this file once you add new enchants to it. Reusing IDs will very likely cause issues.
    'display' is the name that will display on the item 'ie: Tiger's Blood I, etc'
    'enable' determines if this CustomEnchantment is active or not
    'handle' should be FALSE for all non-included Custom's
    'maxlevel' will be used to determine how high a CustomEnchantment can go
    'cooldown' is currently unsupported for added Custom's and used on for included Custom's

    To add/increment this Custom to an Item:
    ItemAPI.addEnchantment(SomeItemStack, "tiger");
     
    bronzzze likes this.
  2. Offline

    bronzzze

    You can enchant it in enchanting table? And can you enchant items like slimeball or something like this.
     
  3. Offline

    nj2miami

    Yes and yes.
     
  4. Offline

    CheesyFreezy

Thread Status:
Not open for further replies.

Share This Page