import {world,system,ItemStack} from '@minecraft/server';
import {classSelection} from '../utils.js';

world.afterEvents.playerSpawn.subscribe((e) => {
	const {initialSpawn,player} = e;
	const dpArray = ["excludePetFromSweep","enchantedHit","damageIndicator","criticalHit","sweep","critSound","bowHitSound"];
	if (initialSpawn && !player.hasTag('knw:tome')) {
		const tome = new ItemStack('knw:knowledge_tome');
		tome.keepOnDeath = true;
		player.dimension.spawnItem(tome, player.location);
		player.addTag('knw:tome');
		player.sendMessage({ translate:"sweepnslash.tipmessage" });
		for (const dp of dpArray) {
			if (player.getDynamicProperty(dp) == undefined) player.setDynamicProperty(dp, true);
		}
	}
	if (player.getDynamicProperty('Class') == undefined) {
		system.runTimeout(() => {
			classSelection(player);
		}, 60);
	}
});
