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>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package xyz.etztech.minecraftmanager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -16,10 +18,7 @@ import xyz.etztech.minecraftmanager.objects.Question;
|
|||
import xyz.etztech.minecraftmanager.objects.Rules;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
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, Question> applyQuestion = 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 List<String> banOptions;
|
||||
private static OreAlert oreAlert;
|
||||
|
@ -113,6 +112,11 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
|||
}
|
||||
rules = new Rules(config);
|
||||
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);
|
||||
}
|
||||
|
||||
public static boolean addDiamond(String location) {
|
||||
if (diamonds.contains(location)) {
|
||||
public static boolean addStrike(Material material, String location) {
|
||||
List<String> strikeList = oreStrikes.get(material.toString());
|
||||
|
||||
if (strikeList.contains(location)) {
|
||||
return false;
|
||||
}
|
||||
diamonds.add(location);
|
||||
return true;
|
||||
else {
|
||||
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() {
|
||||
return rules;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package xyz.etztech.minecraftmanager.listeners;
|
|||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -24,33 +25,35 @@ public class BlockBreakListener implements Listener {
|
|||
|
||||
if (plugin.getConfig().getBoolean("orealert.enabled", true)) {
|
||||
Block block = event.getBlock();
|
||||
Material blockMaterial = event.getBlock().getBlockData().getMaterial();
|
||||
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.getOreAlert().addStrike(player.getUniqueId());
|
||||
plugin.getOreAlert().addStrike(player.getUniqueId(), blockMaterial);
|
||||
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);
|
||||
// Start
|
||||
if (start == 1) {
|
||||
plugin.getOreAlert().alert(player.getName(), alertable, true);
|
||||
plugin.getOreAlert().alert(player.getName(), blockMaterial, alertable, true);
|
||||
} else if (start > 1) {
|
||||
// Ping
|
||||
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
|
||||
} 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)) {
|
||||
if (Material.DIAMOND_ORE == radiusBlock.getType()) {
|
||||
MinecraftManager.addDiamond(getLocationString(radiusBlock));
|
||||
if (MinecraftManager.isTracked(radiusBlock.getType())) {
|
||||
MinecraftManager.addStrike(radiusBlock.getType(), getLocationString(radiusBlock));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package xyz.etztech.minecraftmanager.objects;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.etztech.core.web.CoreWeb;
|
||||
import xyz.etztech.minecraftmanager.MinecraftManager;
|
||||
|
@ -10,7 +12,7 @@ import xyz.etztech.minecraftmanager.MinecraftManager;
|
|||
import java.util.*;
|
||||
|
||||
public class OreAlert {
|
||||
private Map<UUID, ArrayList<Date>> players = new HashMap<>();
|
||||
private Map<UUID, PlayerOreStrikeList> players = new HashMap<>();
|
||||
|
||||
private MinecraftManager plugin;
|
||||
|
||||
|
@ -18,19 +20,21 @@ public class OreAlert {
|
|||
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 void addStrike(UUID uuid, Material material) {
|
||||
PlayerOreStrikeList playerStrikes = players.getOrDefault(uuid, new PlayerOreStrikeList());
|
||||
|
||||
playerStrikes.addStrike(material);
|
||||
|
||||
players.put(uuid, playerStrikes);
|
||||
}
|
||||
|
||||
public int getStrikes(UUID uuid) {
|
||||
return players.getOrDefault(uuid, new ArrayList<>()).size();
|
||||
public int getStrikes(UUID uuid, Material material) {
|
||||
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.
|
||||
String message = username + " has found " + strikes + " diamond ore veins.";
|
||||
String message = username + " has found " + strikes + " " + material.name() + " veins.";
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.hasPermission("minecraftmanager.orealert")) {
|
||||
|
@ -56,9 +60,8 @@ public class OreAlert {
|
|||
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);
|
||||
PlayerOreStrikeList strikeList = players.getOrDefault(uuid, new PlayerOreStrikeList());
|
||||
strikeList.purge(cutoff);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
enabled: true
|
||||
blocks:
|
||||
- diamond_ore
|
||||
- ancient_debris
|
||||
# How long until we purge a node strike, in minutes
|
||||
purge: 30
|
||||
notify:
|
||||
|
|
|
@ -4,6 +4,8 @@ description: ${description}
|
|||
author: ${author}
|
||||
website: ${url}
|
||||
main: ${mainClass}
|
||||
api-version: 1.16
|
||||
|
||||
commands:
|
||||
minecraftmanager:
|
||||
description: Base MCM command
|
||||
|
|
Loading…
Reference in New Issue