import { world } from '@minecraft/server';
import { PLAYER_SETTINGS } from '../settings/settings.js';
import { ADDON_ID } from '../constants.js';

world.afterEvents.playerSpawn.subscribe((data) => {
    const player = data.player;
    if (data.initialSpawn && !player.hasTag("ftb_sieves_joined")) {
        player.sendMessage({
            translate: "ftb_sieves.messages.addon_loaded",
        });
        player.sendMessage({
            translate: "ftb_sieves.messages.crucible.book_dropped",
        });
        player.runCommand('loot spawn ^ ^ ^1 loot "ftb_sieves/book"');
        player.runCommand("gamerule recipesunlock false");
        player.addTag("ftb_sieves_joined");
        for (let playersetting of PLAYER_SETTINGS) {
            playersetting.initDefault(player);
        }
        const dynamicProperty = world.getDynamicProperty("admin_given") || false;
        if (!dynamicProperty) {
            player.addTag(ADDON_ID + "_admin");
            world.setDynamicProperty("admin_given", true);
        }
    }
});
