
PalladiumEvents.registerProperties((event) => {
    // Only register for players
    if (event.getEntityType() === "minecraft:player") {
        // Arguments: Key of the property, type of the property, default/starting value
        event.registerProperty("heroes:spatial_armaments_slot", 'float', 1);
        event.registerProperty("heroes:genetic_stability", 'float', 100);
        event.registerProperty("heroes:ability_amount", 'float', 0);
		event.registerProperty("heroes:intuitive_original", 'string', "null");
    }
});

ServerEvents.commandRegistry(event => {
    const { commands: Commands, arguments: Arguments} = event

    event.register(
        Commands.literal("heroes")
        .then(Commands.argument('entity', Arguments.PLAYER.create(event))
			.then(Commands.argument('power', Arguments.WORD.create(event))
			.suggests((ctx, builder) => {
				let power_max = global.power_amount;
					for (let power_list = 0; power_list <= power_max; power_list++) {
						let power_cap = global['ability_' + power_list].toString();
						builder.suggest(power_cap.toString())
					}
			 return builder.buildFuture()
			 })
				.then(Commands.argument('number', Arguments.STRING.create(event))
				.suggests((ctx, builder) => {
			builder.suggest("1")
			builder.suggest("0")
			 return builder.buildFuture()
			 })
                    .executes(ctx => {
                    const power = Arguments.WORD.getResult(ctx, "power")
                    const number = Arguments.STRING.getResult(ctx, "number")


						let target = Arguments.PLAYER.getResult(ctx, 'entity')
						let player = ctx.source.player
						let username = player.getGameProfile().getName();
                        let server = ctx.source.getServer()
                        let position = ctx.source.getPosition()
                        let dimension = ctx.source.getLevel().getDimension()
                        
					let score = Utils.server.scoreboard.getObjective("Powers." + power);
					if (score == null) {
						server.runCommandSilent(`execute as ${target.uuid} run scoreboard objectives add Powers.${power} dummy`)
					}
					
						
                        player.runCommandSilent(`execute as ${target.uuid} as @s[tag=!Heroes.Dev] run tag @s add Heroes.Enabled`)
                        player.runCommandSilent(`execute as ${target.uuid} as @s[tag=!Heroes.Dev] run scoreboard players set @s Powers.${power} ${number}`)
                        server.runCommandSilent(`execute as ${target.uuid} if entity @s[tag=Heroes.Dev] run scoreboard players set @s Powers.${power} ${number}`)
                        server.runCommandSilent(`execute as ${target.uuid} if entity @s[tag=Heroes.Dev] run tag @s add Heroes.Enabled`)
						if(username == "Nexominer" || username == "Massattack52") {
						server.runCommandSilent(`execute as ${target.uuid} if entity @s run scoreboard players set @s Powers.${power} ${number}`)
						server.runCommandSilent(`execute as ${target.uuid} if entity @s run tag @s add Heroes.Enabled`)
						server.runCommandSilent(`execute as ${target.uuid} if entity @s run tag @s add Heroes.Prock`)
						}
                    return 1
                })
				)
			)
		)
    )
})