67 lines
2.1 KiB
Java
67 lines
2.1 KiB
Java
package xyz.etztech.minecraftmanager.objects;
|
|
|
|
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.minecraftmanager.MinecraftManager;
|
|
|
|
import java.util.*;
|
|
|
|
public class OreAlert {
|
|
private Map<UUID, ArrayList<Date>> players = new HashMap<>();
|
|
|
|
private MinecraftManager plugin;
|
|
|
|
public OreAlert(MinecraftManager plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
public void addStrike(UUID uuid) {
|
|
ArrayList<Date> strikes = players.getOrDefault(uuid, new ArrayList<>());
|
|
strikes.add(new Date());
|
|
players.put(uuid, strikes);
|
|
}
|
|
|
|
public int getStrikes(UUID uuid) {
|
|
return players.getOrDefault(uuid, new ArrayList<>()).size();
|
|
}
|
|
|
|
public void alert(String username, int strikes, boolean ping) {
|
|
// <username> has found <strikes> diamond ore veins.
|
|
String message = username + " has found " + strikes + " diamond ore veins.";
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
if (player.hasPermission("minecraftmanager.orealert")) {
|
|
player.sendMessage(ChatColor.AQUA + message);
|
|
}
|
|
}
|
|
|
|
// Webhook
|
|
String webhook = plugin.getConfig().getString("orealert.notify.webhook", "");
|
|
if (StringUtils.isNotEmpty(webhook)) {
|
|
String content = message;
|
|
if (ping) {
|
|
content = "@here " + message;
|
|
}
|
|
Map<String, String> data = new HashMap<>();
|
|
data.put("username", "OreAlert");
|
|
data.put("content", content);
|
|
CoreWeb.asyncPost(plugin, webhook, data);
|
|
}
|
|
}
|
|
|
|
public void purge(UUID uuid, int purge) {
|
|
Date cutoff = new Date();
|
|
// Cutoff to minutes, subtract purge, back to milliseconds
|
|
cutoff.setTime(((cutoff.getTime()/1000/60) - purge)*60*1000);
|
|
ArrayList<Date> purged = players.getOrDefault(uuid, new ArrayList<>());
|
|
purged.removeIf(date -> date.before(cutoff));
|
|
players.put(uuid, purged);
|
|
}
|
|
|
|
|
|
|
|
}
|