package p.thatalecs.tps;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class CheckTps extends JavaPlugin implements CommandExecutor {

private long[] ticks = new long[600];
private int tickIndex = 0;

@Override
public void onEnable() {
getCommand("tps").setExecutor(this);
System.out.println("[CheckTPS enabled]");

getServer().getScheduler().scheduleSyncRepeatingTask(this, this::calculateTps, 0, 1);
}

@Override
public void onDisable() {
System.out.println("[CheckTPS disabled]");
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("tps")) {
double tps = getServerTPS();
ChatColor tpsColor;

if (tps >= 18.0) {
tpsColor = ChatColor.DARK_GREEN;
} else if (tps >= 15.0) {
tpsColor = ChatColor.YELLOW;