59 lines
1.7 KiB
Java
59 lines
1.7 KiB
Java
package xyz.etztech.qol.other;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.entity.Player;
|
|
import xyz.etztech.core.web.CoreWeb;
|
|
import xyz.etztech.qol.EtzTechUtil;
|
|
import xyz.etztech.qol.QoL;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class GriefAlert implements Runnable {
|
|
private Map<String, Integer> alerts;
|
|
|
|
private QoL plugin;
|
|
|
|
public GriefAlert(QoL plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void run() {
|
|
alerts = new HashMap<>();
|
|
}
|
|
|
|
public void addAlert(String alert) {
|
|
int num = alerts.getOrDefault(alert, 0);
|
|
alerts.put(alert, ++num);
|
|
int lines = plugin.getConfig().getInt("grief-alert.lines", 5);
|
|
if (num < lines) {
|
|
alert(alert);
|
|
} else if (num == lines) {
|
|
String extra = " Suppressing more alerts for a while";
|
|
String webhook = plugin.getConfig().getString("grief-alert.webhook", "");
|
|
String message = "@here " + alert;
|
|
if (StringUtils.isNotEmpty(webhook)) {
|
|
extra += " and pinging Discord";
|
|
Map<String, String> data = new HashMap<>();
|
|
data.put("username", "Grief Alert");
|
|
data.put("content", message);
|
|
CoreWeb.asyncPost(plugin, webhook, data);
|
|
}
|
|
extra += "...";
|
|
alert(alert + extra);
|
|
}
|
|
}
|
|
|
|
private void alert(String alert) {
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
if (player.hasPermission("qol.griefalert")) {
|
|
EtzTechUtil.sms(player, ChatColor.RED + alert);
|
|
}
|
|
}
|
|
}
|
|
}
|