package com.loganmagnan.eventcore.runnables;

import com.loganmagnan.eventcore.EventCore;
import org.bukkit.entity.Player;

public class CooldownRunnable implements Runnable {

    private EventCore main = EventCore.getInstance();

    @Override
    public void run() {
        this.main.getCooldownManager().setChatCooldownCount(this.main.getCooldownManager().getChatCooldownCount() + 1);

        for (Player player : this.main.getServer().getOnlinePlayers()) {
            if (this.main.getCooldownManager().isOnChatCooldown(player.getUniqueId())) {
                int count = this.main.getCooldownManager().getChatCooldownTime(player.getUniqueId());
                count--;

                this.main.getCooldownManager().setChatCooldownTime(player.getUniqueId(), count);

                if (count == 0) {
                    this.main.getCooldownManager().getChatCooldown().remove(player.getUniqueId());
                    this.main.getCooldownManager().getChatCooldownTime().remove(player.getUniqueId());
                }
            }

            if (this.main.getCooldownManager().getChatCooldownCount() == this.main.getChatManager().getDelayAmount()) {
                this.main.getCooldownManager().setChatCooldownCount(0);
            }
        }
    }
}
