import playerSystem from '../player/playerSystem.js';
import entitySystem from '../entity/entitySystem.js';
import Commands from '../commands/runCommand.js';
import eventManager from './eventManager.js';

export default class customEventManager extends eventManager {
    constructor() {
        super();
        this.players = new playerSystem();
        this.entities = new entitySystem();
        
        this.register("custom:playerJoin", def => {
            let check = "playerInitialize";
            this.listenForEvent("playerSpawn", e => {
                let { initialSpawn, player } = e;
                if (initialSpawn) {
                    player?.addTag(check);
                }
            })
            this.tick(() => {
                this.players.getPlayersFromQuery({tags:[check]}).forEach(player => {
                    let data = {};
                    data.player = player;
                    player?.removeTag(check);
                    return def(data);
                })
            },0)
        });
    }
        
}

