forked from Minecraft/QoL
39 lines
1.2 KiB
Java
39 lines
1.2 KiB
Java
package xyz.etztech.qol.other;
|
|
|
|
import net.ess3.api.IEssentials;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import xyz.etztech.core.web.CoreWeb;
|
|
import xyz.etztech.qol.QoL;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class TPSRunnable implements Runnable {
|
|
private QoL plugin;
|
|
|
|
public TPSRunnable(QoL plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void run() {
|
|
IEssentials essentials = (IEssentials) plugin.getEssentials();
|
|
if (essentials != null) {
|
|
double tps = essentials.getTimer().getAverageTPS();
|
|
int threshold = plugin.getConfig().getInt("tps.threshold", 0);
|
|
String webhook = plugin.getConfig().getString("tps.webhook", "");
|
|
String message = "@here TPS has fallen below " + threshold + "!";
|
|
if (tps < threshold) {
|
|
plugin.log(message);
|
|
if (StringUtils.isNotEmpty(webhook)) {
|
|
Map<String, String> data = new HashMap<>();
|
|
data.put("username", "TPS Alert");
|
|
data.put("content", message);
|
|
CoreWeb.asyncPost(plugin, webhook, data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|