Finishing native OreAlert
parent
2d0b768538
commit
597e9de953
|
@ -11,6 +11,7 @@ import xyz.etztech.minecraftmanager.listeners.BlockBreakListener;
|
||||||
import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener;
|
import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener;
|
||||||
import xyz.etztech.minecraftmanager.listeners.SessionListener;
|
import xyz.etztech.minecraftmanager.listeners.SessionListener;
|
||||||
import xyz.etztech.minecraftmanager.objects.Application;
|
import xyz.etztech.minecraftmanager.objects.Application;
|
||||||
|
import xyz.etztech.minecraftmanager.objects.OreAlert;
|
||||||
import xyz.etztech.minecraftmanager.objects.Question;
|
import xyz.etztech.minecraftmanager.objects.Question;
|
||||||
import xyz.etztech.minecraftmanager.objects.Rules;
|
import xyz.etztech.minecraftmanager.objects.Rules;
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
private static List<String> diamonds = new ArrayList<>();
|
private static List<String> diamonds = new ArrayList<>();
|
||||||
private static Rules rules;
|
private static Rules rules;
|
||||||
private static List<String> banOptions;
|
private static List<String> banOptions;
|
||||||
|
private static OreAlert oreAlert;
|
||||||
|
|
||||||
// API
|
// API
|
||||||
private static boolean logOverride = false;
|
private static boolean logOverride = false;
|
||||||
|
@ -87,6 +89,8 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
|
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
|
||||||
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
|
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
|
||||||
|
|
||||||
|
oreAlert = new OreAlert(this);
|
||||||
|
|
||||||
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
|
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,6 +194,10 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
return logOverride;
|
return logOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OreAlert getOreAlert() {
|
||||||
|
return oreAlert;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logOverride(boolean override) {
|
public void logOverride(boolean override) {
|
||||||
logOverride = override;
|
logOverride = override;
|
||||||
|
|
|
@ -18,11 +18,9 @@ import java.util.List;
|
||||||
public class BlockBreakListener implements Listener {
|
public class BlockBreakListener implements Listener {
|
||||||
|
|
||||||
private MinecraftManager plugin;
|
private MinecraftManager plugin;
|
||||||
private OreAlert oreAlert;
|
|
||||||
|
|
||||||
public BlockBreakListener(MinecraftManager minecraftManager) {
|
public BlockBreakListener(MinecraftManager minecraftManager) {
|
||||||
this.plugin = minecraftManager;
|
this.plugin = minecraftManager;
|
||||||
this.oreAlert = new OreAlert();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -34,21 +32,22 @@ public class BlockBreakListener implements Listener {
|
||||||
if (Material.DIAMOND_ORE == block.getType()) {
|
if (Material.DIAMOND_ORE == block.getType()) {
|
||||||
if (MinecraftManager.addDiamond(getLocationString(block))) {
|
if (MinecraftManager.addDiamond(getLocationString(block))) {
|
||||||
//plugin.log("[OreAlert]: " + event.getPlayer().getName());
|
//plugin.log("[OreAlert]: " + event.getPlayer().getName());
|
||||||
oreAlert.addStrike(player.getUniqueId());
|
plugin.getOreAlert().addStrike(player.getUniqueId());
|
||||||
oreAlert.purge(player.getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30));
|
plugin.getOreAlert().purge(player.getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30));
|
||||||
|
|
||||||
int alertable = oreAlert.getStrikes(player.getUniqueId());
|
int alertable = plugin.getOreAlert().getStrikes(player.getUniqueId());
|
||||||
|
|
||||||
|
double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5);
|
||||||
// Start
|
// Start
|
||||||
if (alertable / plugin.getConfig().getInt("orealert.notify.start", 5) == 1) {
|
if (start == 1) {
|
||||||
// TODO Ping
|
plugin.getOreAlert().alert(player.getName(), alertable, true);
|
||||||
} else {
|
} else if (start > 1) {
|
||||||
// Alert
|
|
||||||
if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) {
|
|
||||||
// TODO Alert
|
|
||||||
}
|
|
||||||
// Ping
|
// Ping
|
||||||
if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) {
|
if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) {
|
||||||
// TODO Ping
|
plugin.getOreAlert().alert(player.getName(), alertable, true);
|
||||||
|
// Alert
|
||||||
|
} else if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) {
|
||||||
|
plugin.getOreAlert().alert(player.getName(), alertable, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
package xyz.etztech.minecraftmanager.objects;
|
package xyz.etztech.minecraftmanager.objects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import java.util.Date;
|
import org.bukkit.Bukkit;
|
||||||
import java.util.HashMap;
|
import org.bukkit.ChatColor;
|
||||||
import java.util.UUID;
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.etztech.core.web.CoreWeb;
|
||||||
|
import xyz.etztech.minecraftmanager.MinecraftManager;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class OreAlert {
|
public class OreAlert {
|
||||||
private HashMap<UUID, ArrayList<Date>> players;
|
private Map<UUID, ArrayList<Date>> players = new HashMap<>();
|
||||||
|
|
||||||
public HashMap<UUID, ArrayList<Date>> getPlayers() {
|
private MinecraftManager plugin;
|
||||||
return players;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayers(HashMap<UUID, ArrayList<Date>> players) {
|
public OreAlert(MinecraftManager plugin) {
|
||||||
this.players = players;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addStrike(UUID uuid) {
|
public void addStrike(UUID uuid) {
|
||||||
|
@ -26,6 +28,30 @@ public class OreAlert {
|
||||||
return players.getOrDefault(uuid, new ArrayList<>()).size();
|
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) {
|
public void purge(UUID uuid, int purge) {
|
||||||
Date cutoff = new Date();
|
Date cutoff = new Date();
|
||||||
// Cutoff to minutes, subtract purge, back to milliseconds
|
// Cutoff to minutes, subtract purge, back to milliseconds
|
||||||
|
|
|
@ -85,3 +85,5 @@ orealert:
|
||||||
each: 1
|
each: 1
|
||||||
# After the initial alert, how many should be found in addition before more pings?
|
# After the initial alert, how many should be found in addition before more pings?
|
||||||
ping: 5
|
ping: 5
|
||||||
|
# Webhook to send to
|
||||||
|
webhook: ''
|
||||||
|
|
Loading…
Reference in New Issue