StartupEvents.registry('palladium:abilities', (event) => {

    // ID of the ability will be: 'kubejs:radius/damage'
    event.create('heroes:aoe_damage_target')

        .icon(palladium.createItemIcon('palladium:vibranium_circuit'))

        .addProperty('radius', 'float', 10, 'Radius in which surrounding entities will be damaged')
        .addProperty('damage', 'float', 3.0, 'Damage the ability will deal')
		.addProperty('fire_seconds', 'float', 0.0, 'How many seconds the entity should be on fire')
		.addProperty('tag', 'string', 'tag', 'Tag that choses_target')
		.addProperty('damage_type', 'string', 'minecraft:player_attack', 'Type of damage.')
        .tick((entity, entry, holder, enabled) => {
            if (enabled) {
                const damage_type = entry.getPropertyByName('damage_type');
                const tag = entry.getPropertyByName('tag');
		const damage = entry.getPropertyByName('damage');
		const fire_seconds = entry.getPropertyByName('fire_seconds');

                const radius = entry.getPropertyByName('radius') * 2.0;

                const targets = entity.serverLevel().getEntities(entity, AABB.ofSize(entity.position(), 100, 100, 100)).toArray(); 

                for (let j = 0; j < targets.length; j++) {
                    let en = targets[j];
                    if (containsTag(en.getTags().toArray(), tag)) {
                        let box = AABB.ofSize(en.position(), radius, radius, radius);
                        let entities = en.getLevel().getEntities(en, box).toArray();
                        for (let i = 0; i < entities.length; i++) {
                            if (entities[i] !== entity && !containsTag(entities[i].getTags().toArray(), tag) && entities[i].type !== "minecraft:item" && entities[i].type !== "minecraft:item_frame" && entities[i].type !== "minecraft:glow_item_frame" && entities[i].type !== "minecraft:armor_stand" && entities[i].type !== "palladium:suit_stand") {
								entity.server.runCommandSilent("execute as " + entities[i].uuid + " at @s run damage @s " + damage + " " + damage_type + " by " + entity.uuid);
								entities[i].setSecondsOnFire(fire_seconds);
                            }
                        }
                    }
                }
            }
        })
});

function containsTag(tags, tag) {
    for (let i = 0; i < tags.length; i++) {
        if(tags[i].equals(tag)) {
            return true;
        }
    }
    return false;
}