(function () {
    let ClientboundSetEntityMotionPacket = Java.loadClass('net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket');


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

    event.create('heroes:infinity')

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

        .addProperty('radius', 'integer', 10, 'Radius in which surrounding entities will be damaged')
		.addProperty('tag_ex', 'string', 'exclusion_tag', 'Tag that exlcudes entities if desired')

        .tick((entity, entry, holder, enabled) => {
            if (enabled) {
				const tag_ex = entry.getPropertyByName('tag_ex');
				const reversal_state = entry.getPropertyByName('reversal_state');
                const radius = entry.getPropertyByName('radius') * 2.0;
                const targets = entity.serverLevel().getEntities(entity, AABB.ofSize(entity.position(), radius, radius, radius)).toArray();
				let current_x = entity.x
				let current_y = entity.y
				let current_z = entity.z
                for (let j = 0; j < targets.length; j++) {
                        let box = AABB.ofSize(entity.position(), radius, radius, radius);
                        let entities = entity.serverLevel().getEntities(entity, box).toArray();
                        for (let i = 0; i < entities.length; i++) {
                            if (entities[i] !== entity && !containsTag(entities[i].getTags().toArray(), tag_ex) && 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") {

                        entities[i].addMotion(((((radius / ((entities[i].x - current_x) + 0.00001))* (1 + 5)^2.4) / 1000)), ((((radius / ((entities[i].y - current_y) + 0.00001))* (1 + 5)^2.4) / 1000) * -1), ((((radius / ((entities[i].z - current_z) + 0.00001))* (1 + 5)^2.4) / 1000)));
								if (entities[i].isPlayer()) {
                        entities[i].connection.send(new ClientboundSetEntityMotionPacket(entities[i]));
                    }
                        }
                    }
                }
            }
        })
});
})();
