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

    StartupEvents.registry('palladium:abilities', (event) => {
        event.create('heroes:base_power_con_max')
            .icon(palladium.createItemIcon('palladium:vibranium_circuit'))

            .tick((entity, entry, holder, enabled) => {
                if (enabled) {
                    let username = entity.getGameProfile().getName();
					let username_true = username.toLowerCase();
                    let scoreboard = Utils.server.scoreboard;
					
					let scoreboard_conmax = scoreboard.getObjective('Heroes.Concentration.Max.Base');
                    let score_conmax = scoreboard.getOrCreatePlayerScore(username, scoreboard_conmax);
                    let value_conmax = score_conmax.getScore();
					
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players set @s Heroes.Concentration.Potential 2");
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players add @s[tag=Powers.Body.Awakened] Heroes.Concentration.Potential 2");
					
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players set @s Heroes.Concentration.Max " + value_conmax + "");
					
					let parallel_processing = entity.server.runCommandSilent("execute as " + username + " if entity @s[palladium.power=heroes:parallel_processing]");
					let intuitive_aptitude = entity.server.runCommandSilent("execute as " + username + " if entity @s[palladium.power=heroes:intuitive_aptitude]");
					let empathic_mimicry = entity.server.runCommandSilent("execute as " + username + " if entity @s[palladium.power=heroes:empathic_mimicry]");
					let interplay = entity.server.runCommandSilent("execute as " + username + " if entity @s[scores={Powers.Interplay=1..}]");
					let absorption = entity.server.runCommandSilent("execute as " + username + " if entity @s[scores={Powers.Absorption=1..}]");
					if (empathic_mimicry >= 1 || interplay >= 1 || absorption >= 1) {
						if (intuitive_aptitude == 0) {
						entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players add @s Heroes.Concentration.Max 1");
						}
					}	
					if (intuitive_aptitude >= 1) {
						entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players add @s Heroes.Concentration.Max 2");
					}
					if (parallel_processing >= 1) {
						entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players add @s Heroes.Concentration.Max 2");
					}
					
				}
            });
    });
})();