import { system, world } from "@minecraft/server";
export class Debugger {
    static instance;
    static intervalStarted = false;
    constructor() {
        if (!Debugger.intervalStarted) {
            system.runInterval(() => {
                world.setDynamicProperty('allanz:debuggerTime', world.getDynamicProperty('allanz:debuggerTime') ?? 0);
                let secund = world.getDynamicProperty('allanz:debuggerTime');
                world.setDynamicProperty('allanz:debuggerTime', secund + 1);
            }, 20);
            Debugger.intervalStarted = true;
        }
    }
    static getInstance() {
        if (!Debugger.instance) {
            Debugger.instance = new Debugger();
        }
        return Debugger.instance;
    }
    log(message, source) {
        const debuggerTime = world.getDynamicProperty('allanz:debuggerTime');
        if (message instanceof Object) {
            message = JSON.stringify(message, null, 4);
        }
        if (source && source.hasTag('debug')) {
            source.sendMessage(`§a[DEBUG] §f${message} - ${convertSecondsToHours(debuggerTime)}`);
        }
        else {
            const player = world.getAllPlayers()[0];
            if (!player.hasTag('debug'))
                return;
            player.sendMessage(`§a[DEBUG] §f${message} - ${convertSecondsToHours(debuggerTime)}`);
        }
    }
}
function convertSecondsToHours(totalSeconds) {
    const hours = Math.floor(totalSeconds / 3600);
    const minutes = Math.floor((totalSeconds % 3600) / 60);
    const seconds = totalSeconds % 60;
    return `${hours}:${minutes}:${seconds}`;
}
