Merge branch 'phrasing' of birbmc.com:BirbMC/MinecraftManagerPlugin
# Conflicts: # pom.xmlmaster
commit
49577ecd85
|
@ -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.
|
2
pom.xml
2
pom.xml
|
@ -31,7 +31,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.3-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -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<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;
|
||||
|
||||
// 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<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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
|
|
@ -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<Block> getBlocks(Block start, int radius) {
|
||||
if (radius < 0) {
|
||||
return new ArrayList<Block>(0);
|
||||
}
|
||||
int iterations = (radius * 2) + 1;
|
||||
List<Block> blocks = new ArrayList<Block>(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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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<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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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...";
|
||||
|
|
|
@ -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: ''
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue