import "./gojidraw_weapon_main.js";
import "./gojidraw_main.js";
import "./endless_stone.js";
import "./gojidraw_knockback_main.js";
import "./gojidraw_quest_main.js";
import "./kaiju_controller.js";
import "./gojidraw_ender_wing.js";
import { world, system } from "@minecraft/server";

const GIVEN_ITEM_1 = "gojidraw:kaiju_stats_book"; 
const GIVEN_ITEM_2 = "gojidraw:kaiju_quest_book"; 
const GIVEN_ITEM_3 = "gojidraw:knockback_setting"; // Add your third item here
const ITEM_AMOUNT = 1; 
const TAG = "has_kaiju_items"; // Tag to prevent multiple distributions

world.afterEvents.playerSpawn.subscribe((event) => {
    let player = event.player;

    // Prevent multiple item distributions
    if (player.hasTag(TAG)) return;

    system.run(() => {
        let overworld = world.getDimension("overworld");

        // Give the items to the player
        overworld.runCommandAsync(`give "${player.name}" ${GIVEN_ITEM_1} ${ITEM_AMOUNT}`);
        overworld.runCommandAsync(`give "${player.name}" ${GIVEN_ITEM_2} ${ITEM_AMOUNT}`);
        overworld.runCommandAsync(`give "${player.name}" ${GIVEN_ITEM_3} ${ITEM_AMOUNT}`);

        // Send a message and play a sound
        overworld.runCommandAsync(`tellraw @a {"rawtext":[{"text":"§f[§aWorld§f] §aYou Have Received Your Starting Items!"}]}`);
        overworld.runCommandAsync(`gamerule sendcommandfeedback false`);
    });

    // Add the tag to prevent giving items again
    player.addTag(TAG);
});