import { system, world } from "@minecraft/server";
import { SuppTags } from "../reg/suppTags";
import { configs } from "../configs";
const threshold = 300;
const amountPerCandy = 80;
const interval = 20;
const playerTimer = new Map();
world.afterEvents.itemCompleteUse.subscribe(event => {
    if (event.itemStack.hasTag(SuppTags.Candy) && configs.nausea.getValue()) {
        let existing = (playerTimer.get(event.source) ?? 0).valueOf();
        const value = existing + amountPerCandy;
        playerTimer.set(event.source, value);
        if (value >= threshold) {
            event.source.addEffect("minecraft:nausea", 20 * 10);
        }
    }
});
system.runInterval(() => {
    for (const [p, am] of playerTimer.entries()) {
        const newAm = am.valueOf() - interval;
        if (newAm <= 0 || !p.isValid()) {
            playerTimer.delete(p);
        }
        else {
            playerTimer.set(p, newAm);
        }
    }
}, interval);
