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

    StartupEvents.registry('palladium:abilities', (event) => {
        event.create('heroes:stockpile')
            .icon(palladium.createItemIcon('palladium:vibranium_circuit'))
            .addProperty("energy_max", "string", "1000000", "Determins max energy for the power and what the math will be based on")
            .addProperty("base_energy_score", "string", "Stockpile.Score", "Ability Stockpile Scoreboard")
            .addProperty("body_hold_score", "string", "Stockpile.Score", "Ability Stockpile Scoreboard")
            .addProperty("arm_hold_score", "string", "Stockpile.Score", "Ability Stockpile Scoreboard")
            .addProperty("fingers_hold_score", "string", "Stockpile.Score", "Ability Stockpile Scoreboard")
            .addProperty("leg_hold_score", "string", "Stockpile.Score", "Ability Stockpile Scoreboard")
            .addProperty("body_limiter_score", "string", "Body.Limiter", "Body Limiter Scoreboard")
            .addProperty("arm_limiter_score", "string", "Arms.Limiter", "Arm Limiter Scoreboard")
            .addProperty("finger_limiter_score", "string", "Fingers.Limiter", "Finger Limiter Scoreboard")
            .addProperty("leg_limiter_score", "string", "Legs.Limiter", "Leg Limiter Scoreboard")
            .addProperty("stockpile_cost_score", "string", "Legs.Limiter", "Leg Limiter Scoreboard")
			.addProperty("UUID", "string", "cc154bdc-21f8-11ee-be56-0242ac120002", "The UUID used for the attributes")
			.addProperty("Attribute_Id", "string", "Stockpile.Stats", "Id for attribute NBT not important tbh")

            .tick((entity, entry, holder, enabled) => {
                if (enabled) {
					const uuid = entry.getPropertyByName('UUID');
					const energy = entry.getPropertyByName('energy_max');
					const scoreboard_0_name = entry.getPropertyByName('body_hold_score');
					const scoreboard_1_name = entry.getPropertyByName('arm_hold_score');
					const scoreboard_2_name = entry.getPropertyByName('fingers_hold_score');
					const scoreboard_3_name = entry.getPropertyByName('leg_hold_score');
					const scoreboard_4_name = entry.getPropertyByName('base_energy_score');
					const scoreboard_5_name = entry.getPropertyByName('stockpile_cost_score');
					const attributeid = entry.getPropertyByName('Attribute_Id');
                    let username = entity.getGameProfile().getName();
					let username_true = username.toLowerCase();
                    let scoreboard = Utils.server.scoreboard;
					
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players operation @s " + scoreboard_0_name + " = @s " + scoreboard_4_name + "");
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players operation @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_1_name + " = @s " + scoreboard_4_name + "");
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players operation @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_2_name + " = @s " + scoreboard_4_name + "");
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players operation @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_3_name + " = @s " + scoreboard_4_name + "");
					
					entity.server.runCommandSilent("execute as " + username + " at @s[scores={" +scoreboard_0_name + "=" + energy + "..}] run scoreboard players set @s " + scoreboard_0_name + " " + energy + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[scores={" +scoreboard_0_name + "=" + energy + "..}] run scoreboard players set @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_1_name + " " + energy + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[scores={" +scoreboard_0_name + "=" + energy + "..}] run scoreboard players set @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_2_name + " " + energy + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[scores={" +scoreboard_0_name + "=" + energy + "..}] run scoreboard players set @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_3_name + " " + energy + "");
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Refresh] run tag @s remove Heroes.Stockpile.Refresh");
                    let scoreboard_obj_a4 = scoreboard.getObjective(entry.getPropertyByName("base_energy_score"));
                    let scoreboard_obj_a3 = scoreboard.getObjective(entry.getPropertyByName("leg_hold_score"));
                    let scoreboard_obj_a2 = scoreboard.getObjective(entry.getPropertyByName("fingers_hold_score"));
                    let scoreboard_obj_a1 = scoreboard.getObjective(entry.getPropertyByName("arm_hold_score"));
                    let scoreboard_obj_0 = scoreboard.getObjective(entry.getPropertyByName("body_hold_score"));
                    let scoreboard_obj_1 = scoreboard.getObjective(entry.getPropertyByName("body_limiter_score"));
                    let scoreboard_obj_2 = scoreboard.getObjective(entry.getPropertyByName("arm_limiter_score"));
                    let scoreboard_obj_3 = scoreboard.getObjective(entry.getPropertyByName("finger_limiter_score"));
                    let scoreboard_obj_4 = scoreboard.getObjective(entry.getPropertyByName("leg_limiter_score"));
                    let score_a4 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_a4);
                    let score_a3 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_a3);
                    let score_a2 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_a2);
                    let score_a1 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_a1);
                    let score_0 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_0);
                    let score_1 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_1);
                    let score_2 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_2);
                    let score_3 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_3);
                    let score_4 = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_4);
                    let value_4a = score_a4.getScore();
                    let value_3a = score_a3.getScore();
                    let value_2a = score_a2.getScore();
                    let value_1a = score_a1.getScore();
                    let value_0 = score_0.getScore();
                    let value_1 = score_1.getScore();
                    let value_2 = score_2.getScore();
                    let value_3 = score_3.getScore();
                    let value_4 = score_4.getScore();
					
					
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump] run scoreboard players add @s " + scoreboard_5_name + " " + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 200))) + "");
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Enable] run scoreboard players add @s " + scoreboard_5_name + " " + (JavaMath.ceil((JavaMath.ceil(value_1a * (value_2 / 100))) / (energy / 5000))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Flick,tag=!Heroes.Stockpile.Enable] run scoreboard players add @s " + scoreboard_5_name + " " + (JavaMath.ceil((JavaMath.ceil(value_2a * (value_3 / 100))) / (energy / 1250))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Enable] run scoreboard players add @s " + scoreboard_5_name + " " + (JavaMath.ceil((JavaMath.ceil(value_3a * (value_4 / 100))) / (energy / 1750))) + "");
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Smash,tag=Heroes.Stockpile.Enable] run scoreboard players add @s " + scoreboard_5_name + " " + (JavaMath.ceil((JavaMath.ceil(value_1a * (value_1 / 100))) / (energy / 5000))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Flick,tag=Heroes.Stockpile.Enable] run scoreboard players add @s " + scoreboard_5_name + " " + (JavaMath.ceil((JavaMath.ceil(value_2a * (value_1 / 100))) / (energy / 1250))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Jump,tag=Heroes.Stockpile.Enable] run scoreboard players add @s " + scoreboard_5_name + " " + (JavaMath.ceil((JavaMath.ceil(value_3a * (value_1 / 100))) / (energy / 1750))) + "");
					
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Body=" + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Body " + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 20))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Body=" + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Arms " + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 20))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Body=" + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Fingers " + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 20))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Body=" + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Legs " + (JavaMath.ceil((JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 20))) + "");
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Smash,tag=Heroes.Stockpile.Enable] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Arms=" + (JavaMath.ceil((JavaMath.ceil(value_1a * (value_1 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Arms " + (JavaMath.ceil((JavaMath.ceil(value_1a * (value_1 / 100))) / (energy / 250))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Flick,tag=Heroes.Stockpile.Enable] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Fingers=" + (JavaMath.ceil((JavaMath.ceil(value_2a * (value_1 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Fingers " + (JavaMath.ceil((JavaMath.ceil(value_2a * (value_1 / 100))) / (energy / 15.625))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Jump,tag=Heroes.Stockpile.Enable] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Legs=" + (JavaMath.ceil((JavaMath.ceil(value_3a * (value_1 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Legs " + (JavaMath.ceil((JavaMath.ceil(value_3a * (value_1 / 100))) / (energy / 62.5))) + "");
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Enable] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Arms=" + (JavaMath.ceil((JavaMath.ceil(value_1a * (value_2 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Arms " + (JavaMath.ceil((JavaMath.ceil(value_1a * (value_2 / 100))) / (energy / 250))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Flick,tag=!Heroes.Stockpile.Enable] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Fingers=" + (JavaMath.ceil((JavaMath.ceil(value_2a * (value_3 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Fingers " + (JavaMath.ceil((JavaMath.ceil(value_2a * (value_3 / 100))) / (energy / 15.625))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Enable] run scoreboard players add @s[scores={Heroes.Stockpile.Tolerance.Legs=" + (JavaMath.ceil((JavaMath.ceil(value_3a * (value_4 / 100))))) + "..}] Heroes.Stockpile.Tolerance.Legs " + (JavaMath.ceil((JavaMath.ceil(value_3a * (value_4 / 100))) / (energy / 62.5))) + "");
					
					
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run attribute @s minecraft:generic.armor modifier remove " + uuid + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run attribute @s minecraft:generic.armor_toughness modifier remove " + uuid + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Jump] run attribute @s minecraft:generic.attack_damage modifier remove " + uuid + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run attribute @s palladium:destroy_speed modifier remove " + uuid + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run attribute @s minecraft:generic.movement_speed modifier remove " + uuid + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run attribute @s palladium:jump_power modifier remove " + uuid + "");
					entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable,tag=!Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Jump,tag=!Heroes.Stockpile.Flick] run attribute @s palladium:fall_resistance modifier remove " + uuid + "");
					
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable] run attribute @s minecraft:generic.armor modifier add " + uuid + " " + attributeid + " " + (4 + (JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 150)) + " add");
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable] run attribute @s minecraft:generic.armor_toughness modifier add " + uuid + " " + attributeid + " " + (0 + (JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 62.5)) + " add");
					

			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Flick,tag=!Heroes.Stockpile.Enable] run attribute @s minecraft:generic.attack_damage modifier add " + uuid + " " + attributeid + " " + (2 + (JavaMath.ceil(value_2a * (value_3 / 100))) / (energy / 62.5)) + " add");
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Smash,tag=!Heroes.Stockpile.Enable] run attribute @s minecraft:generic.attack_damage modifier add " + uuid + " " + attributeid + " " + (2 + (JavaMath.ceil(value_1a * (value_2 / 100))) / (energy / 62.5)) + " add");
					
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable] run attribute @s minecraft:generic.attack_damage modifier add " + uuid + " " + attributeid + " " + (2 + (JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 62.5)) + " add");
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable] run attribute @s palladium:destroy_speed modifier add " + uuid + " " + attributeid + " " + ((JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 2)) + " add");
					
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable] run attribute @s minecraft:generic.movement_speed modifier add " + uuid + " " + attributeid + " " + (0.075 + (JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 1.5)) + " add");
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable] run attribute @s palladium:jump_power modifier add " + uuid + " " + attributeid + " " + (0.2 + (JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 4)) + " add");
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Enable] run attribute @s palladium:fall_resistance modifier add " + uuid + " " + attributeid + " " + (0.2 + (JavaMath.ceil(value_0 * (value_1 / 100))) / (energy / 4)) + " add");
					
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Smash] run tag @s remove Heroes.Stockpile.Smash");
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Flick] run tag @s remove Heroes.Stockpile.Flick");
			        entity.server.runCommandSilent("execute as " + username + " at @s[tag=Heroes.Stockpile.Jump] run tag @s remove Heroes.Stockpile.Jump");
					
				
					
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players set @s " + scoreboard_0_name + " " + (JavaMath.ceil(value_0 * (value_1 / 100))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players set @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_1_name + " " + (JavaMath.ceil(value_0 * (value_2 / 100))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players set @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_2_name + " " + (JavaMath.ceil(value_0 * (value_3 / 100))) + "");
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players set @s[tag=!Heroes.Stockpile.Enable] " + scoreboard_3_name + " " + (JavaMath.ceil(value_0 * (value_4 / 100))) + "");
					
					
					
                }
            });
    });
})();