Sueta
IT

ItemEditorAPI

1.0

An Easier Item Editor API

·Plugin

ItemEditor

an Easier Item Edit API

Zero:what is it:

  • It is an easier item edit API,it allows developer edit tag or other Item things with a easier way.
  • it use ASM,According to your server to create ASMTool.jar to operate NMS directly.it has faster efficiency than reflexes.
  • with it,when u want to edit nbt,you didn't need to use reflect,only some easy method,u can realize it.

How to use:
These two steps are necessary:

  • First: u need download the plugin,and add it as external jars. like u deal with Server Core jar.
  • Second: Determine whether ItemEditorAPI is installed
    add
    depend: [ItemEditorAPI]
    to your plugin.yml to make sure your plugin will enable after ItemEditorAPI.

Model Instduce:
chenji.itemeditor.util.NMSItem:

  • It seems like a bridge of ItemStack to NMSItemStack,it allow u to set the NBTTagCompound.you can use
    NMSItem nmsitem = NMSItem.getItem(item);
    to get the instance of NMSItem.
    nmsitem.getBukkitItem();
    to get the instance of Bukkit ItemStack.
    nmsitem.setTag(tag);
    to set the NBTTagCompound instance to item.
    NOTICE it is chenji.itemeditor.nbt.base.NBTTagCompound! NOT NMS's NBTTagCompound. chenji.itemeditor.nbt.base.NBTTagCompound will be Instduced following....

chenji.itemeditor.nbt.base:

  • it is a nbt system,u can use it as same as NMS's NBT system.
  • this is a simplely write example:
    Create a NBTTagCompound instance:
    NBTTagCompound tag = new NBTTagCompound();
    put an int :key:testint value:233
    put a String :testString value:test
    tag.setInt("testint", 233);
            tag.setString("testString", "test");
    set the NBTTagCompound instance to item.
    nmsitem.setTag(tag);
    now get your item,u can find it was saved in your item,Is it very simple?if u want to read,please look following...
  • use
    NBTTagCompound tag = nmsitem.getTag();
    to get NBTTagCompound instance from nmsitem.
    use
    NBTBase base = tag.get(key);
    to get the value.
    use
    base.getType();
    to get Type of Value;
    if you know the type,u can cast the base to child.such as It is a String, cast it to NBTTagString and use getValue(); to get String result;
    ((NBTTagString)base).getValue();
    If you know exactly the type of the key,u can use exactly method such as getString(key);
    so the above code can be simplified to:
    NBTTagCompound tag = nmsitem.getTag();
    String result = tag.getString(key);
    or even:
    String result = nmsitem.getTag().getString(key);

ItemEditor Instduce:

  • this API has a ItemEditor,it prefabricated some method.you can use these methods edit item quickly.Here are some demo:
  • use
    new ItemEditor(item);
    to create instance.after edit,you need use
    editor.getItem();
    to get back Bukkit item.
  • There are some demo to operate the ItemEditor;
/**
     * this demo tell u some common operation to operate the item with ItemEditor.
     *
     * @param editor
     *            the ItemEditor what u want to set
     */
    public void setSomethings(ItemEditor editor) {
        // Set the amount of item: 10
        editor.setAmount(10);
        // add an Attribute to item: Health up:10
        editor.addAttrbute(new Attribute().setAttributeType(AttributeType.MAX_HEALTH).setAmount(10));
        // add an lore line:testlore
        editor.addLoreLine("testlore");
        // set the display name: testdisplayname
        editor.setDisplayName("testdisplayname");
        // set the color with rgb if the type allowed:255 255 255
        editor.setColor(255, 255, 255);
        // add an enchantment :PROTECTION_FALL level:10
        editor.addEnchantment(Enchantment.PROTECTION_FALL, 10);
    }

    /**
     * this exam tell u some common operation to read the item with ItemEditor.
     *
     * @param editor
     *            the ItemEditor what u want to read
     */
    @SuppressWarnings("unused")
    public void readSomethings(ItemEditor editor) {
        List<Attribute> attrs = editor.getAttirbutes();
        List<String> lores = editor.getLore();

    }

Finally:
The project is open source here: https://gitee.com/ChenJi158/ItemEditorAPI
my mother language is not English....
forgive my poor English... if this page have some syntax error.welcome u to send email to ( [email protected]) to report,thanks

Similar projects

Plugin →