diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..82b4eb1
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright 2020 Etzelia
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 4c63696..1cb6492 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
org.spigotmc
spigot-api
- 1.14.3-R0.1-SNAPSHOT
+ 1.16.1-R0.1-SNAPSHOT
provided
diff --git a/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java b/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java
index dea8c98..00d77c7 100644
--- a/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java
+++ b/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java
@@ -1,23 +1,22 @@
package xyz.etztech.minecraftmanager;
import org.bukkit.Bukkit;
+import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.minecraftmanager.command.*;
import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener;
-import xyz.etztech.minecraftmanager.listeners.BlockBreakListener;
import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener;
import xyz.etztech.minecraftmanager.listeners.SessionListener;
import xyz.etztech.minecraftmanager.objects.Application;
-import xyz.etztech.minecraftmanager.objects.OreAlert;
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.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@@ -31,10 +30,9 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
private static Map applyMode = new HashMap<>();
private static Map applyQuestion = new HashMap<>();
private static Map applications = new HashMap<>();
- private static List diamonds = new ArrayList<>();
+ private static Map> oreStrikes = new HashMap<>();
private static Rules rules;
private static List banOptions;
- private static OreAlert oreAlert;
// API
private static boolean logOverride = false;
@@ -84,13 +82,9 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
getServer().getPluginManager().registerEvents(chatListener, this);
SessionListener sessionListener = new SessionListener(this);
getServer().getPluginManager().registerEvents(sessionListener, this);
- BlockBreakListener blockBreakListener = new BlockBreakListener(this);
- getServer().getPluginManager().registerEvents(blockBreakListener, this);
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
- oreAlert = new OreAlert(this);
-
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
}
}
@@ -113,6 +107,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 +157,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 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 strikeList = oreStrikes.get(blockType);
+
+ return strikeList != null;
+ }
+
+
public static Rules getRules() {
return rules;
}
@@ -194,10 +205,6 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
return logOverride;
}
- public OreAlert getOreAlert() {
- return oreAlert;
- }
-
@Override
public void logOverride(boolean override) {
logOverride = override;
diff --git a/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java b/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java
deleted file mode 100644
index a82838c..0000000
--- a/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package xyz.etztech.minecraftmanager.listeners;
-
-import org.bukkit.Bukkit;
-import org.bukkit.Material;
-import org.bukkit.block.Block;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.BlockBreakEvent;
-import org.bukkit.event.player.PlayerLoginEvent;
-import xyz.etztech.minecraftmanager.MCMAPI;
-import xyz.etztech.minecraftmanager.MinecraftManager;
-import xyz.etztech.minecraftmanager.objects.OreAlert;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class BlockBreakListener implements Listener {
-
- private MinecraftManager plugin;
-
- public BlockBreakListener(MinecraftManager minecraftManager) {
- this.plugin = minecraftManager;
- }
-
- @EventHandler
- public void onBlockBreak(BlockBreakEvent event) {
-
- if (plugin.getConfig().getBoolean("orealert.enabled", true)) {
- Block block = event.getBlock();
- Player player = event.getPlayer();
- if (Material.DIAMOND_ORE == block.getType()) {
- if (MinecraftManager.addDiamond(getLocationString(block))) {
- //plugin.log("[OreAlert]: " + event.getPlayer().getName());
- plugin.getOreAlert().addStrike(player.getUniqueId());
- plugin.getOreAlert().purge(player.getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30));
-
- int alertable = plugin.getOreAlert().getStrikes(player.getUniqueId());
-
- double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5);
- // Start
- if (start == 1) {
- plugin.getOreAlert().alert(player.getName(), alertable, true);
- } else if (start > 1) {
- // Ping
- if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) {
- 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);
- }
- }
-
- }
-
- Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
- for (Block radiusBlock : getBlocks(block, 5)) {
- if (Material.DIAMOND_ORE == radiusBlock.getType()) {
- MinecraftManager.addDiamond(getLocationString(radiusBlock));
- }
- }
- });
-
- }
- }
- }
-
- private List getBlocks(Block start, int radius) {
- if (radius < 0) {
- return new ArrayList(0);
- }
- int iterations = (radius * 2) + 1;
- List blocks = new ArrayList(iterations * iterations * iterations);
- for (int x = -radius; x <= radius; x++) {
- for (int y = -radius; y <= radius; y++) {
- for (int z = -radius; z <= radius; z++) {
- blocks.add(start.getRelative(x, y, z));
- }
- }
- }
- return blocks;
- }
-
- private String getLocationString(Block block) {
- int X = block.getX();
- int Y = block.getY();
- int Z = block.getZ();
-
- String x = String.valueOf(X);
- String y = String.valueOf(Y);
- String z = String.valueOf(Z);
-
- return x + y + z;
- }
-
-
-}
diff --git a/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java b/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java
deleted file mode 100644
index 258ccb5..0000000
--- a/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java
+++ /dev/null
@@ -1,66 +0,0 @@
-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> players = new HashMap<>();
-
- private MinecraftManager plugin;
-
- public OreAlert(MinecraftManager plugin) {
- this.plugin = plugin;
- }
-
- public void addStrike(UUID uuid) {
- ArrayList 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) {
- // has found 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 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 purged = players.getOrDefault(uuid, new ArrayList<>());
- purged.removeIf(date -> date.before(cutoff));
- players.put(uuid, purged);
- }
-
-
-
-}
diff --git a/src/main/java/xyz/etztech/minecraftmanager/objects/PlayerOreStrikeList.java b/src/main/java/xyz/etztech/minecraftmanager/objects/PlayerOreStrikeList.java
new file mode 100644
index 0000000..f1b71e9
--- /dev/null
+++ b/src/main/java/xyz/etztech/minecraftmanager/objects/PlayerOreStrikeList.java
@@ -0,0 +1,33 @@
+package xyz.etztech.minecraftmanager.objects;
+
+import org.bukkit.Material;
+
+import java.util.*;
+
+public class PlayerOreStrikeList {
+ private Map> strikes = new HashMap<>();
+
+ public PlayerOreStrikeList() {
+ }
+
+ public void addStrike(Material material) {
+ ArrayList oreStrikes = getStrikes(material);
+ oreStrikes.add(new Date());
+ strikes.put(material, oreStrikes);
+ }
+
+ public int strikeCount(Material material) {
+ return getStrikes(material).size();
+ }
+
+ public ArrayList 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);
+ });
+ }
+}
diff --git a/src/main/java/xyz/etztech/minecraftmanager/objects/Question.java b/src/main/java/xyz/etztech/minecraftmanager/objects/Question.java
index 1419762..f550fdc 100644
--- a/src/main/java/xyz/etztech/minecraftmanager/objects/Question.java
+++ b/src/main/java/xyz/etztech/minecraftmanager/objects/Question.java
@@ -5,11 +5,11 @@ import org.apache.commons.lang.StringUtils;
public enum Question {
ONE("How old are you?", "Your answer must be numeric."),
- TWO("What type of player are you?", "Your answer must be under 300 characters long."),
+ TWO("How do you typically enjoy playing Minecraft?", "Your answer must be under 300 characters long."),
THREE1("Have you ever been banned? Please answer just 'yes' or 'no'.", "Your answer must be just 'yes' or 'no'."),
THREE2("Oof. That's okay, it's happened to plenty of people. Do you mind letting us know why?", "Your answer must be under 300 characters long."),
- FOUR("Were you referred to our server by someone?", "Your answer must be under 50 characters long."),
- FIVE("Have you read the rules thoroughly?", "Your answer must be under 10 characters long."),
+ FOUR("How did you find out about our server?", "Your answer must be under 50 characters long."),
+ FIVE("Last question! Have you read the rules thoroughly?", "Your answer must be under 10 characters long."),
COMPLETE("All done! Staff should be reviewing your application any second now!", "");
public static final String READ_RULES = "Are you sure? Maybe you should read them again...";
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index f496671..8501634 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -72,18 +72,3 @@ django:
url: "http://localhost:8000/api/"
# MCM API password - defined in your Django settings
api: "Testing1"
-
-# OreAlert, for pinging based on diamond ore strikes
-orealert:
- enabled: true
- # How long until we purge a node strike, in minutes
- purge: 30
- notify:
- # How many veins found within the above purge minutes to notify
- start: 5
- # After the initial alert, how many should be found in addition before more alerts?
- each: 1
- # After the initial alert, how many should be found in addition before more pings?
- ping: 5
- # Webhook to send to
- webhook: ''
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 3469daa..2b28469 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -4,6 +4,8 @@ description: ${description}
author: ${author}
website: ${url}
main: ${mainClass}
+api-version: 1.16
+
commands:
minecraftmanager:
description: Base MCM command
@@ -48,9 +50,6 @@ permissions:
minecraftmanager.staff:
description: Who should get staff messages
default: op
- minecraftmanager.orealert:
- description: Who should get OreAlert messages
- default: op
minecraftmanager.register:
description: Who is allowed to register for the MCM web application
default: op