import { ItemStack, system, world } from "@minecraft/server";
import ScriptingModule from "./scriptingModule";
import { namespace, startItems, startSound } from "../config/_config";
import { addItemToInventory } from "./utils";
export default class PlayerJoinModule extends ScriptingModule {
    constructor() {
        super("PlayerJoinModule");
    }
    onInitialize() {
        world.afterEvents.playerSpawn.subscribe(() => {
            const players = world.getPlayers();
            players.forEach((player) => {
                if (player.hasTag(`${namespace}:has_joined`))
                    return;
                system.runTimeout(() => {
                    player.sendMessage({ translate: `${namespace}.joined.first_time` });
                    player.playSound(`${startSound}`);
                }, 100);
                startItems.forEach((item) => {
                    if (item === null)
                        return;
                    const itemStack = new ItemStack(item);
                    addItemToInventory(player, itemStack);
                });
                player.addTag(`${namespace}:has_joined`);
            });
        });
    }
}
