Allow the blocks OreAlert tracks to be configured (#21)
Allow OreAlert tracked blocks to be configured + Each block is tracked separately + Set api-version to 1.16 to allow for new material support + Bumped spigot api version to 1.16 Co-authored-by: Joey Hines <joey@ahines.net> Reviewed-on: https://git.etztech.xyz/MMS/MinecraftManagerPlugin/pulls/21 Reviewed-by: Etzelia <etzelia@hotmail.com>up
parent
f5f69eb35a
commit
7a63f21c78
2
pom.xml
2
pom.xml
|
@ -31,7 +31,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package xyz.etztech.minecraftmanager;
|
package xyz.etztech.minecraftmanager;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
@ -16,10 +18,7 @@ import xyz.etztech.minecraftmanager.objects.Question;
|
||||||
import xyz.etztech.minecraftmanager.objects.Rules;
|
import xyz.etztech.minecraftmanager.objects.Rules;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
|
@ -31,7 +30,7 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
private static Map<String, Boolean> applyMode = new HashMap<>();
|
private static Map<String, Boolean> applyMode = new HashMap<>();
|
||||||
private static Map<String, Question> applyQuestion = new HashMap<>();
|
private static Map<String, Question> applyQuestion = new HashMap<>();
|
||||||
private static Map<String, Application> applications = new HashMap<>();
|
private static Map<String, Application> applications = new HashMap<>();
|
||||||
private static List<String> diamonds = new ArrayList<>();
|
private static Map<String, List<String>> oreStrikes = new HashMap<>();
|
||||||
private static Rules rules;
|
private static Rules rules;
|
||||||
private static List<String> banOptions;
|
private static List<String> banOptions;
|
||||||
private static OreAlert oreAlert;
|
private static OreAlert oreAlert;
|
||||||
|
@ -113,6 +112,11 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
}
|
}
|
||||||
rules = new Rules(config);
|
rules = new Rules(config);
|
||||||
banOptions = config.getStringList("ban.options");
|
banOptions = config.getStringList("ban.options");
|
||||||
|
oreStrikes.clear();
|
||||||
|
|
||||||
|
for (String block_type: config.getStringList("orealert.blocks")) {
|
||||||
|
oreStrikes.put(block_type, new LinkedList<>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,14 +162,26 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
applications.put(uuid, application);
|
applications.put(uuid, application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean addDiamond(String location) {
|
public static boolean addStrike(Material material, String location) {
|
||||||
if (diamonds.contains(location)) {
|
List<String> strikeList = oreStrikes.get(material.toString());
|
||||||
|
|
||||||
|
if (strikeList.contains(location)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
diamonds.add(location);
|
else {
|
||||||
return true;
|
strikeList.add(location);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isTracked(Material material) {
|
||||||
|
String blockType = material.toString();
|
||||||
|
List<String> strikeList = oreStrikes.get(blockType);
|
||||||
|
|
||||||
|
return strikeList != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Rules getRules() {
|
public static Rules getRules() {
|
||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package xyz.etztech.minecraftmanager.listeners;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -24,33 +25,35 @@ public class BlockBreakListener implements Listener {
|
||||||
|
|
||||||
if (plugin.getConfig().getBoolean("orealert.enabled", true)) {
|
if (plugin.getConfig().getBoolean("orealert.enabled", true)) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
|
Material blockMaterial = event.getBlock().getBlockData().getMaterial();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (Material.DIAMOND_ORE == block.getType()) {
|
|
||||||
if (MinecraftManager.addDiamond(getLocationString(block))) {
|
if (MinecraftManager.isTracked(blockMaterial)) {
|
||||||
|
if (MinecraftManager.addStrike(blockMaterial, getLocationString(block))) {
|
||||||
//plugin.log("[OreAlert]: " + event.getPlayer().getName());
|
//plugin.log("[OreAlert]: " + event.getPlayer().getName());
|
||||||
plugin.getOreAlert().addStrike(player.getUniqueId());
|
plugin.getOreAlert().addStrike(player.getUniqueId(), blockMaterial);
|
||||||
plugin.getOreAlert().purge(player.getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30));
|
plugin.getOreAlert().purge(player.getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30));
|
||||||
|
|
||||||
int alertable = plugin.getOreAlert().getStrikes(player.getUniqueId());
|
int alertable = plugin.getOreAlert().getStrikes(player.getUniqueId(), blockMaterial);
|
||||||
|
|
||||||
double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5);
|
double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5);
|
||||||
// Start
|
// Start
|
||||||
if (start == 1) {
|
if (start == 1) {
|
||||||
plugin.getOreAlert().alert(player.getName(), alertable, true);
|
plugin.getOreAlert().alert(player.getName(), blockMaterial, alertable, true);
|
||||||
} else if (start > 1) {
|
} else if (start > 1) {
|
||||||
// Ping
|
// Ping
|
||||||
if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) {
|
if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) {
|
||||||
plugin.getOreAlert().alert(player.getName(), alertable, true);
|
plugin.getOreAlert().alert(player.getName(), blockMaterial, alertable, true);
|
||||||
// Alert
|
// Alert
|
||||||
} else if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) {
|
} else if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) {
|
||||||
plugin.getOreAlert().alert(player.getName(), alertable, false);
|
plugin.getOreAlert().alert(player.getName(), blockMaterial, alertable, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
for (Block radiusBlock : getBlocks(block, 5)) {
|
for (Block radiusBlock : getBlocks(block, 5)) {
|
||||||
if (Material.DIAMOND_ORE == radiusBlock.getType()) {
|
if (MinecraftManager.isTracked(radiusBlock.getType())) {
|
||||||
MinecraftManager.addDiamond(getLocationString(radiusBlock));
|
MinecraftManager.addStrike(radiusBlock.getType(), getLocationString(radiusBlock));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package xyz.etztech.minecraftmanager.objects;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import xyz.etztech.core.web.CoreWeb;
|
import xyz.etztech.core.web.CoreWeb;
|
||||||
import xyz.etztech.minecraftmanager.MinecraftManager;
|
import xyz.etztech.minecraftmanager.MinecraftManager;
|
||||||
|
@ -10,7 +12,7 @@ import xyz.etztech.minecraftmanager.MinecraftManager;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class OreAlert {
|
public class OreAlert {
|
||||||
private Map<UUID, ArrayList<Date>> players = new HashMap<>();
|
private Map<UUID, PlayerOreStrikeList> players = new HashMap<>();
|
||||||
|
|
||||||
private MinecraftManager plugin;
|
private MinecraftManager plugin;
|
||||||
|
|
||||||
|
@ -18,19 +20,21 @@ public class OreAlert {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addStrike(UUID uuid) {
|
public void addStrike(UUID uuid, Material material) {
|
||||||
ArrayList<Date> strikes = players.getOrDefault(uuid, new ArrayList<>());
|
PlayerOreStrikeList playerStrikes = players.getOrDefault(uuid, new PlayerOreStrikeList());
|
||||||
strikes.add(new Date());
|
|
||||||
players.put(uuid, strikes);
|
playerStrikes.addStrike(material);
|
||||||
|
|
||||||
|
players.put(uuid, playerStrikes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStrikes(UUID uuid) {
|
public int getStrikes(UUID uuid, Material material) {
|
||||||
return players.getOrDefault(uuid, new ArrayList<>()).size();
|
return players.getOrDefault(uuid, new PlayerOreStrikeList()).strikeCount(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alert(String username, int strikes, boolean ping) {
|
public void alert(String username, Material material, int strikes, boolean ping) {
|
||||||
// <username> has found <strikes> diamond ore veins.
|
// <username> has found <strikes> diamond ore veins.
|
||||||
String message = username + " has found " + strikes + " diamond ore veins.";
|
String message = username + " has found " + strikes + " " + material.name() + " veins.";
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (player.hasPermission("minecraftmanager.orealert")) {
|
if (player.hasPermission("minecraftmanager.orealert")) {
|
||||||
|
@ -56,9 +60,8 @@ public class OreAlert {
|
||||||
Date cutoff = new Date();
|
Date cutoff = new Date();
|
||||||
// Cutoff to minutes, subtract purge, back to milliseconds
|
// Cutoff to minutes, subtract purge, back to milliseconds
|
||||||
cutoff.setTime(((cutoff.getTime()/1000/60) - purge)*60*1000);
|
cutoff.setTime(((cutoff.getTime()/1000/60) - purge)*60*1000);
|
||||||
ArrayList<Date> purged = players.getOrDefault(uuid, new ArrayList<>());
|
PlayerOreStrikeList strikeList = players.getOrDefault(uuid, new PlayerOreStrikeList());
|
||||||
purged.removeIf(date -> date.before(cutoff));
|
strikeList.purge(cutoff);
|
||||||
players.put(uuid, purged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package xyz.etztech.minecraftmanager.objects;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class PlayerOreStrikeList {
|
||||||
|
private Map<Material, ArrayList<Date>> strikes = new HashMap<>();
|
||||||
|
|
||||||
|
public PlayerOreStrikeList() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStrike(Material material) {
|
||||||
|
ArrayList<Date> oreStrikes = getStrikes(material);
|
||||||
|
oreStrikes.add(new Date());
|
||||||
|
strikes.put(material, oreStrikes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int strikeCount(Material material) {
|
||||||
|
return getStrikes(material).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Date> getStrikes(Material material) {
|
||||||
|
return strikes.getOrDefault(material, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void purge(Date cutoff) {
|
||||||
|
strikes.forEach((block, list) -> {
|
||||||
|
list.removeIf(date -> date.before(cutoff));
|
||||||
|
strikes.put(block, list);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -76,6 +76,9 @@ django:
|
||||||
# OreAlert, for pinging based on diamond ore strikes
|
# OreAlert, for pinging based on diamond ore strikes
|
||||||
orealert:
|
orealert:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
blocks:
|
||||||
|
- diamond_ore
|
||||||
|
- ancient_debris
|
||||||
# How long until we purge a node strike, in minutes
|
# How long until we purge a node strike, in minutes
|
||||||
purge: 30
|
purge: 30
|
||||||
notify:
|
notify:
|
||||||
|
|
|
@ -4,6 +4,8 @@ description: ${description}
|
||||||
author: ${author}
|
author: ${author}
|
||||||
website: ${url}
|
website: ${url}
|
||||||
main: ${mainClass}
|
main: ${mainClass}
|
||||||
|
api-version: 1.16
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
minecraftmanager:
|
minecraftmanager:
|
||||||
description: Base MCM command
|
description: Base MCM command
|
||||||
|
|
Loading…
Reference in New Issue