Entity Attribute API (1.9+)

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

sapphyrusxyz

Member
Mar 29, 2017
49
8
0
23
This is a new API that was added in Spigot 1.9 and can be used to change things like the attack speed of a player.

Java:
package net.md_5;

import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class AttributeDemo extends JavaPlugin implements Listener
{

    @Override
    public void onEnable()
    {
        getConfig().addDefault( Attribute.GENERIC_ATTACK_SPEED.name(), 16 );
        getConfig().options().copyDefaults( true );
        saveConfig();

        getServer().getPluginManager().registerEvents( this, this );
    }

    @EventHandler
    public void playerJoin(PlayerJoinEvent event)
    {
        for ( String key : getConfig().getKeys( false ) )
        {
            AttributeInstance instance = event.getPlayer().getAttribute( Attribute.valueOf( key ) );
            if ( instance != null )
            {
                instance.setBaseValue( getConfig().getDouble( key, instance.getBaseValue() ) );
            }
        }
    }
}

All possible attributes are listed here: http://minecraft.gamepedia.com/Attribute#Attributes_available_on_all_living_entities

This probably isn't enough stuff for a single addon but I think it would fit into Skellett or skUtilities. Maybe @tim740 or @LimeGlass could add this?
 
This is a new API that was added in Spigot 1.9 and can be used to change things like the attack speed of a player.

Java:
package net.md_5;

import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class AttributeDemo extends JavaPlugin implements Listener
{

    @Override
    public void onEnable()
    {
        getConfig().addDefault( Attribute.GENERIC_ATTACK_SPEED.name(), 16 );
        getConfig().options().copyDefaults( true );
        saveConfig();

        getServer().getPluginManager().registerEvents( this, this );
    }

    @EventHandler
    public void playerJoin(PlayerJoinEvent event)
    {
        for ( String key : getConfig().getKeys( false ) )
        {
            AttributeInstance instance = event.getPlayer().getAttribute( Attribute.valueOf( key ) );
            if ( instance != null )
            {
                instance.setBaseValue( getConfig().getDouble( key, instance.getBaseValue() ) );
            }
        }
    }
}

All possible attributes are listed here: http://minecraft.gamepedia.com/Attribute#Attributes_available_on_all_living_entities

This probably isn't enough stuff for a single addon but I think it would fit into Skellett or skUtilities. Maybe @tim740 or @LimeGlass could add this?
skUtilities only has non-minecraft related stuff, and as the above guy stated, you can use NBT for it (skStuff)