AttributesAPI
This plugin currently works only with versions of Bukkit 1.7
Introduction
Using the AttributesAPI, it is possible to apply Attributes to items. This allows you to, for example, make shoes that make you run really quickly, or a sword that makes you resistive to knockbacks. Usage is really simple, you only need an item in your hand and run a command. There is also a simple API available for other plugin developers to use this and add attributes to their plugin items.
Usage for server admins
People with the permission attributes can hold an item in their hand and run the following command: /attribute <type> <operation> <value>
For type, the following options are available: attack_damage, follow_range, jump_strength (horses), knockback_resistance, max_health, movement_speed and spawn_reinforcements (zombies). Detailed information about every type can be found here.
For operation, the following options are available: add_number, add_percentage and multiply_percentage. They are quite self-explanatory, but you can find the exact usage here.
For value, you can input any number. If your operation asks for a percentage, you need to use a number where 0.0 = 0% and 1.0 = 100%.
Usage for plugin developers
After including this plugin's JAR file, you have access to the API. There are two classes and two enumerations that are important to use attributes: Attribute, Attributes AttributeType and Operation.
- An Attribute is one instance of a single attribute
- Attributes is a class containing static methods to apply attributes, or retrieve existing attributes from an ItemStack.
- An AttributeType is one of the types listed in the previous section
- An Operation is one of the operations listed in the previous section
You can simply make an Attribute:
Attribute a = new Attribute(AttributeType.MAX_HEALTH,Operation.ADD_NUMBER,20.0);
This will create an Attribute increasing your health by 10 hearts (20.0 life points). You can also use methods like setType and setAmount to edit your Attribute after constructing it.
Apply your attributes to an ItemStack:
Bukkit.getServer().getPlayer("Arfie99").getInventory().addItem( Attributes.apply(new ItemStack(Material.DIAMOND_SWORD),a,true));
The method apply accepts an ItemStack and a boolean argument. The ItemStack is a copy of the returned stack, without the attributes. The boolean will indicate if this Attribute should remove contingent other attributes that were already on the stack.
In short, everything is possible with this single line of code:
Bukkit.getServer().getPlayer("Arfie99").getInventory().addItem(Attributes.apply(new ItemStack(Material.DIAMOND_SWORD),new Attribute(AttributeType.MAX_HEALTH,Operation.ADD_NUMBER,20.0),true));
You can also add collections containing attributes:
List<Attribute> list = Arrays.asList(new Attribute{a1, a2, /*...*/}); ItemStack is = Attributes.apply(new ItemStack(Material.DIAMOND_SWORD),list,true);
Source code
Source code for this plugin is available on GitHub, containing javadocs for explaining the API. Feel free to use it in any way you want, or do pull requests if you have made another awesome feature. https://github.com/arfie/AttributesAPI
Please update, this would help so much! :D
Doesn't work for me in Spigot #1649
Is there any way to make the attributes stay on the items with craft book custom recipes and/or customvillager merchants?
@charchar64
I have not made any compatibility for existing plugins myself. If you want to use AttributesAPI with MythicDrops, I guess you should contact the creator of MythicDrops if he can add compatibility with this plugin.
Is there a way you could make this plugin work with MythicDrops? I use that plugin to make custom items. When I have finished making one and I add attributes, the attributes are not there when I spawn the items in with MythicDrops.
The command is /mythicdrops custom -c [item name]
@Noobsbeard
CombatNoCheat might help
Any possibility of making the plugin work nicely with NoCheat? The speed on weapons for example causes snapping.
@darkness1999
Not yet, but I have been thinking about it already. It will hopefully be in a future update.
Is there a way to get the attributes from an already existing itemstack?
@Arfie99
Yeah would be awesome! And it would also be the very first kit plugin to support attributes! I sent you a PM btw
@iTurquoise
Do you mean putting attributes on an item in a kit using Essentials or another kit plugin? That is unfortunately not possible. I could make a simple kit plugin for you which does make this possible if you want. PM me if you're interested.
Is there anyway to give players the item with the attributes? I have been looking for ways to give players items with attributes in kits but so far I haven't found anyway. So, the give command is my only help <3
@adam561
Of course I don't know what the variable e refers to in your case (I guess an event?), but if it was for example the item the player is holding in his hand, you could do
I recommend checking the GitHub repo I made for this project, because this file can be helpful if you want to use the API; it is the code for hte /attribute command.
By the way, a value of 5.0 is a lot for MOVEMENT_SPEED, the default is 0.7 so with ADD_NUMBER 5.0 you would go about 8 times as quick. Using MOVEMENT_SPEED I recommend the Operation ADD_PERCENTAGE.
@adam561
How can I do this?
new AttributeList(new Attribute(AttributeType.MOVEMENT_SPEED,Operation.ADD_NUMBER,5.0)).apply(e.getItem(),true);
Amazing API!!
This is super helpful but I have one Question:
How can I apply this directly to an ItemStack Without giving the player the item? (Basically Without the Bukkit.getServer().getPlayer("Arfie99").getInventory().addItem)
Can I do Itemstack.addAttribute(bla)?
@Bodyash
Thanks :)
@AcePlugins
I was scared of using this mechanic too in the beginning, but it turned out that if you know how to use NBT, it is really simple. And if you don't, there is this API now :)
:P looks hard to use
wow! plz, don`t stop! It`s very good API!