import * as mc from "@minecraft/server"

export class ActionManager {

    constructor() { this.entityActions = new Map() } // se der eu deixo em uma linha só
    
    register(entity, action) {

        const entityId = entity.id // se der eu tiro todos os ;
        if (!this.entityActions.has(entityId)) {

            this.entityActions.set(entityId, [])


        }
        this.entityActions.get(entityId).push(action)


    }
    stopAllActions(entity) {

        const entityId = entity.id
        const actions = this.entityActions.get(entityId)
        if (actions) {

            actions.forEach(action => mc.system.clearRun(action))
            this.entityActions.delete(entityId)


        }


    }
    createTimeout(entity, callback, delay) {

        const timeout = mc.system.runTimeout(callback, delay)
        this.register(entity, timeout)
        

    }
    createInterval(entity, callback, interval) {

        const intervalId = mc.system.runInterval(callback, interval)
        this.register(entity, intervalId)


    }


}