Updated to latest changes from private repo

master
Etzelia 2018-09-12 11:03:59 -05:00 committed by John Olheiser
parent e59f8f4d67
commit 0a7c12536a
24 changed files with 865 additions and 214 deletions

13
pom.xml
View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>MinecraftManager</artifactId> <artifactId>MinecraftManager</artifactId>
<!-- Version is used in plugin.yml --> <!-- Version is used in plugin.yml -->
<version>1.1</version> <version>1.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- Plugin Information --> <!-- Plugin Information -->
@ -56,13 +56,18 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.13-pre7-R0.1-SNAPSHOT</version> <version>1.13.1-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
<version>2.6</version> <version>2.6</version>
</dependency> </dependency>
<dependency>
<groupId>xyz.etztech</groupId>
<artifactId>EtzCore</artifactId>
<version>1.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
@ -81,6 +86,10 @@
<id>mvn-repo</id> <id>mvn-repo</id>
<url>https://mvnrepository.com/artifact/</url> <url>https://mvnrepository.com/artifact/</url>
</repository> </repository>
<repository>
<id>etztech-repo</id>
<url>http://repo.etztech.xyz</url>
</repository>
<repository> <!-- This repo fixes issues with transitive dependencies --> <repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id> <id>jcenter</id>
<url>http://jcenter.bintray.com</url> <url>http://jcenter.bintray.com</url>

View File

@ -1,7 +1,6 @@
package xyz.etztech.minecraftmanager; package xyz.etztech.minecraftmanager;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -15,11 +14,11 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import xyz.etztech.minecraftmanager.objects.Application;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -40,6 +39,7 @@ public class MCMAPI {
} }
public static JsonArray queryModel(String model, Map<String, String> filters) { public static JsonArray queryModel(String model, Map<String, String> filters) {
// Querying a model // Querying a model
String djangoUrl = getDjangoUrl(); String djangoUrl = getDjangoUrl();
@ -55,6 +55,8 @@ public class MCMAPI {
return new JsonArray(); return new JsonArray();
} }
public static JsonObject postApplication(Application application) { public static JsonObject postApplication(Application application) {
String djangoUrl = getDjangoUrl() + "plugin/application/"; String djangoUrl = getDjangoUrl() + "plugin/application/";
String post = POST(djangoUrl, application.getForm()); String post = POST(djangoUrl, application.getForm());
@ -107,6 +109,18 @@ public class MCMAPI {
return (JsonObject) jsonParser.parse(post); return (JsonObject) jsonParser.parse(post);
} }
public static JsonObject postWarning(String player, String staff, String severity, String message) {
String djangoUrl = getDjangoUrl() + "plugin/warning/";
Map<String, String> data = new HashMap<>();
data.put("player", player);
data.put("staff", staff);
data.put("severity", severity);
data.put("message", message);
String post = POST(djangoUrl, data);
JsonParser jsonParser = new JsonParser();
return (JsonObject) jsonParser.parse(post);
}
public static JsonObject getPassword(String uuid) { public static JsonObject getPassword(String uuid) {
String djangoUrl = getDjangoUrl() + "plugin/register/"; String djangoUrl = getDjangoUrl() + "plugin/register/";
Map<String, String> data = new HashMap<>(); Map<String, String> data = new HashMap<>();
@ -124,9 +138,16 @@ public class MCMAPI {
} }
} }
private static String GET(String url) { public static Map<String, String> setup() {
return GET(url, new HashMap<String, String>()); Map<String, String> data = new HashMap<>();
if (StringUtils.isNotEmpty(MCMAPI.api)) {
data.put("api", MCMAPI.api);
} else {
data.put("api", MinecraftManager.config.getString("django.api"));
} }
return data;
}
private static String GET(String url, Map<String, String> data) { private static String GET(String url, Map<String, String> data) {
if (StringUtils.isNotEmpty(MCMAPI.api)) { if (StringUtils.isNotEmpty(MCMAPI.api)) {
@ -160,10 +181,6 @@ public class MCMAPI {
return result.toString(); return result.toString();
} }
private static String POST(String url) {
return POST(url, new HashMap<String, String>());
}
private static String POST(String url, Map<String, String> data) { private static String POST(String url, Map<String, String> data) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
if (StringUtils.isNotEmpty(MCMAPI.api)) { if (StringUtils.isNotEmpty(MCMAPI.api)) {
@ -199,7 +216,7 @@ public class MCMAPI {
/** /**
* @return The Django API URL ending with a slash * @return The Django API URL ending with a slash
*/ */
private static String getDjangoUrl() { public static String getDjangoUrl() {
if (StringUtils.isNotEmpty(MCMAPI.url)) { if (StringUtils.isNotEmpty(MCMAPI.url)) {
return MCMAPI.url; return MCMAPI.url;
} else { } else {
@ -207,4 +224,8 @@ public class MCMAPI {
return configUrl.endsWith("/") ? configUrl : configUrl + "/"; return configUrl.endsWith("/") ? configUrl : configUrl + "/";
} }
} }
public static String getModelUrl(String model) {
return getDjangoUrl() + "model/" + model + "/";
}
} }

View File

@ -1,58 +0,0 @@
package xyz.etztech.minecraftmanager;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.bukkit.ChatColor;
public class MCMResponse {
private Boolean status;
private String message;
private JsonElement extra;
public MCMResponse(JsonArray httpResponse) {
JsonObject json = httpResponse.get(0).getAsJsonObject();
setStatus(json.get("status").getAsBoolean());
setMessage(json.get("message").getAsString());
setExtra(json.get("extra"));
}
public MCMResponse(JsonObject httpResponse) {
setStatus(httpResponse.get("status").getAsBoolean());
setMessage(httpResponse.get("message").getAsString());
setExtra(httpResponse.get("extra"));
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public JsonElement getExtra() {
return extra;
}
public void setExtra(JsonElement extra) {
this.extra = extra;
}
public String getMCMessage() {
if (status) {
return ChatColor.GREEN + message;
} else {
return ChatColor.RED + message;
}
}
}

View File

@ -1,5 +1,6 @@
package xyz.etztech.minecraftmanager; package xyz.etztech.minecraftmanager;
import com.google.gson.JsonArray;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
@ -13,6 +14,8 @@ import java.io.FileWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class MCMUtil { public class MCMUtil {
private static FileWriter globalFile; private static FileWriter globalFile;
@ -45,19 +48,20 @@ public class MCMUtil {
staffMessage(message, null); staffMessage(message, null);
} }
public static void staffMessage(String message, String command) { public static void staffMessage(String message, String hoverCommand) {
log(staffLog, message); log(staffLog, message);
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create()); HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create());
TextComponent text = new TextComponent(message); TextComponent text = new TextComponent(message);
text.setHoverEvent(hover); text.setHoverEvent(hover);
if (StringUtils.isNotEmpty(command)) { if (StringUtils.isNotEmpty(hoverCommand)) {
text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, hoverCommand));
} }
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("minecraftmanager.staff")) { if (player.hasPermission("minecraftmanager.staff")) {
player.spigot().sendMessage(text); player.spigot().sendMessage(text);
} }
} }
Bukkit.getConsoleSender().sendMessage(message);
} }
public static void globalMessage(String message) { public static void globalMessage(String message) {
@ -67,6 +71,21 @@ public class MCMUtil {
} }
} }
public static String getUUID(String playerName) {
String uuid = null;
try {
uuid = Bukkit.getPlayer(playerName).getUniqueId().toString();
} catch(Exception ex) {
Map<String, String> filters = new HashMap<>();
filters.put("username__iexact", playerName);
JsonArray players = MCMAPI.queryModel("player", filters);
if (players.size() == 1) {
uuid = players.get(0).getAsJsonObject().get("uuid").getAsString();
}
}
return uuid;
}
public static void log(PrintWriter logger, String message) { public static void log(PrintWriter logger, String message) {
try { try {
//[4/21/17 7:12 PM] //[4/21/17 7:12 PM]

View File

@ -2,11 +2,17 @@ package xyz.etztech.minecraftmanager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.minecraftmanager.command.*; import xyz.etztech.minecraftmanager.command.*;
import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener; import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener;
import xyz.etztech.minecraftmanager.listeners.BlockBreakListener; import xyz.etztech.minecraftmanager.listeners.BlockBreakListener;
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.Question;
import xyz.etztech.minecraftmanager.objects.Rules;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -15,7 +21,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
public class MinecraftManager extends JavaPlugin { public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
public static MinecraftManager instance; public static MinecraftManager instance;
@ -25,6 +31,15 @@ public class MinecraftManager extends JavaPlugin {
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 List<String> diamonds = new ArrayList<>();
private static Rules rules;
private static List<String> banOptions;
// API
private static boolean logOverride = false;
// Report
private static boolean reportRunning = false;
private static boolean reportStop = false;
// Objects that can be reloaded // Objects that can be reloaded
AsyncPlayerChatListener chatListener; AsyncPlayerChatListener chatListener;
@ -37,7 +52,7 @@ public class MinecraftManager extends JavaPlugin {
instance = this; instance = this;
saveDefaultConfig(); saveDefaultConfig();
loadConfig(); reloadConfig();
// Create log directory if it doesn't exist // Create log directory if it doesn't exist
new File(getDataFolder().getAbsolutePath() + "/logs/").mkdir(); new File(getDataFolder().getAbsolutePath() + "/logs/").mkdir();
@ -54,6 +69,8 @@ public class MinecraftManager extends JavaPlugin {
this.getCommand("apply").setExecutor(cmdApply); this.getCommand("apply").setExecutor(cmdApply);
CommandTicket cmdTicket = new CommandTicket(this); CommandTicket cmdTicket = new CommandTicket(this);
this.getCommand("ticket").setExecutor(cmdTicket); this.getCommand("ticket").setExecutor(cmdTicket);
CommandWarning cmdWarning = new CommandWarning(this);
this.getCommand("warn").setExecutor(cmdWarning);
// Rules is optional // Rules is optional
if (getConfig().getBoolean("rules.enabled")) { if (getConfig().getBoolean("rules.enabled")) {
@ -68,6 +85,8 @@ public class MinecraftManager extends JavaPlugin {
getServer().getPluginManager().registerEvents(sessionListener, this); getServer().getPluginManager().registerEvents(sessionListener, this);
BlockBreakListener blockBreakListener = new BlockBreakListener(this); BlockBreakListener blockBreakListener = new BlockBreakListener(this);
getServer().getPluginManager().registerEvents(blockBreakListener, this); getServer().getPluginManager().registerEvents(blockBreakListener, this);
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully."); Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
} }
@ -89,9 +108,8 @@ public class MinecraftManager extends JavaPlugin {
if (chatListener != null) { if (chatListener != null) {
chatListener.reload(); chatListener.reload();
} }
if (cmdRules != null) { rules = new Rules(config);
cmdRules.reload(); banOptions = config.getStringList("ban.options");
}
} }
@ -144,5 +162,44 @@ public class MinecraftManager extends JavaPlugin {
diamonds.add(location); diamonds.add(location);
return true; return true;
} }
public static Rules getRules() {
return rules;
}
public static List<String> getBanOptions() {
return banOptions;
}
public static boolean getReportRunning() {
return reportRunning;
}
public static void setReportRunning(boolean reportRunning) {
MinecraftManager.reportRunning = reportRunning;
}
public static boolean getReportStop() {
return reportStop;
}
public static void setReportStop(boolean reportStop) {
MinecraftManager.reportStop = reportStop;
}
public static boolean getLogOverride() {
return logOverride;
}
@Override
public void logOverride(boolean override) {
logOverride = override;
}
@Override
public void globalLog(Player player, String message) {
MCMUtil.log(MCMUtil.globalLog, player.getName() + " > " + message);
}
} }

View File

@ -13,16 +13,15 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import xyz.etztech.minecraftmanager.MCMAPI; import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.minecraftmanager.MCMResponse; import xyz.etztech.core.web.ICallback;
import xyz.etztech.minecraftmanager.MinecraftManager; import xyz.etztech.minecraftmanager.*;
import xyz.etztech.minecraftmanager.MinecraftManagerThread; import xyz.etztech.minecraftmanager.objects.MCMResponse;
import xyz.etztech.minecraftmanager.objects.ModelResponse;
import javax.xml.soap.Text;
import java.awt.*;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class CommandApplication implements CommandExecutor { public class CommandApplication implements CommandExecutor {
MinecraftManager plugin; MinecraftManager plugin;
@ -64,11 +63,17 @@ public class CommandApplication implements CommandExecutor {
return true; return true;
} }
private void search(CommandSender sender, String name) { private class SearchCallback implements ICallback {
if (sender.hasPermission("minecraftmanager.application.search")) { private CommandSender commandSender;
Map<String, String> filter = new HashMap<>();
filter.put("username__icontains", name); SearchCallback(CommandSender commandSender) {
JsonArray results = MCMAPI.queryModel("application", filter); this.commandSender = commandSender;
}
@Override
public void invoke(String s) {
ModelResponse modelResponse = new ModelResponse(s);
JsonArray results = modelResponse.getResults();
StringBuffer response = new StringBuffer(); StringBuffer response = new StringBuffer();
if (results.size() > 0) { if (results.size() > 0) {
response.append(ChatColor.GOLD).append("===== Results ====="); response.append(ChatColor.GOLD).append("===== Results =====");
@ -86,7 +91,15 @@ public class CommandApplication implements CommandExecutor {
response.append(ChatColor.YELLOW).append("No results found..."); response.append(ChatColor.YELLOW).append("No results found...");
} }
sender.sendMessage(response.toString()); commandSender.sendMessage(response.toString());
}
}
private void search(CommandSender sender, String name) {
if (sender.hasPermission("minecraftmanager.application.search")) {
Map<String, String> filter = MCMAPI.setup();
filter.put("username__icontains", name);
CoreWeb.asyncGetCallback(plugin, MCMAPI.getModelUrl("application"), filter, new SearchCallback(sender));
} else { } else {
sender.sendMessage(ChatColor.RED + "You do not have permission to search applications."); sender.sendMessage(ChatColor.RED + "You do not have permission to search applications.");
} }
@ -100,16 +113,18 @@ public class CommandApplication implements CommandExecutor {
} }
} }
private void info(CommandSender sender, String key) { private class InfoCallback implements ICallback {
if (sender.hasPermission("minecraftmanager.application.search")) { private CommandSender commandSender;
Map<String, String> filter = new HashMap<>();
if (StringUtils.isNumeric(key)) { InfoCallback(CommandSender commandSender) {
filter.put("id__exact", key); this.commandSender = commandSender;
} else {
filter.put("username__iexact", key);
} }
JsonArray results = MCMAPI.queryModel("application", filter);
StringBuffer response = new StringBuffer(); @Override
public void invoke(String s) {
ModelResponse modelResponse = new ModelResponse(s);
JsonArray results = modelResponse.getResults();
StringBuilder response = new StringBuilder();
TextComponent text = new TextComponent(); TextComponent text = new TextComponent();
if (results.size() == 1) { if (results.size() == 1) {
JsonObject result = results.get(0).getAsJsonObject(); JsonObject result = results.get(0).getAsJsonObject();
@ -156,12 +171,37 @@ public class CommandApplication implements CommandExecutor {
text.setText(response.toString()); text.setText(response.toString());
} }
sender.spigot().sendMessage(text); commandSender.spigot().sendMessage(text);
}
}
private void info(CommandSender sender, String key) {
if (sender.hasPermission("minecraftmanager.application.search")) {
Map<String, String> filter = MCMAPI.setup();
if (StringUtils.isNumeric(key)) {
filter.put("id__exact", key);
} else {
filter.put("username__iexact", key);
}
CoreWeb.asyncGetCallback(plugin, MCMAPI.getModelUrl("application"), filter, new InfoCallback(sender));
} else { } else {
sender.sendMessage(ChatColor.RED + "You do not have permission to search applications."); sender.sendMessage(ChatColor.RED + "You do not have permission to search applications.");
} }
} }
private class ActionCallback implements ICallback {
private CommandSender commandSender;
ActionCallback(CommandSender commandSender) {
this.commandSender = commandSender;
}
@Override
public void invoke(String s) {
MCMResponse response = new MCMResponse(s);
commandSender.sendMessage(response.getMCMessage());
}
}
private void action(CommandSender sender, String id, boolean accepted) { private void action(CommandSender sender, String id, boolean accepted) {
if (sender.hasPermission("minecraftmanager.application.action")) { if (sender.hasPermission("minecraftmanager.application.action")) {
@ -172,8 +212,12 @@ public class CommandApplication implements CommandExecutor {
username = "Console"; username = "Console";
} }
if (StringUtils.isNumeric(id)) { if (StringUtils.isNumeric(id)) {
MCMResponse response = new MCMResponse(MCMAPI.postApplicationAction(id, accepted, username)); String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/application_action/";
sender.sendMessage(response.getMCMessage()); Map<String, String> data = MCMAPI.setup();
data.put("application_id", id);
data.put("action", accepted ? "True" : "False");
data.put("username", username);
CoreWeb.asyncPostCallback(plugin, djangoUrl, data, new ActionCallback(sender));
} else { } else {
sender.sendMessage(ChatColor.RED + "You must use an application ID to ensure accuracy."); sender.sendMessage(ChatColor.RED + "You must use an application ID to ensure accuracy.");
} }
@ -182,11 +226,27 @@ public class CommandApplication implements CommandExecutor {
} }
} }
private class ClearCallback implements ICallback {
private CommandSender commandSender;
ClearCallback(CommandSender commandSender) {
this.commandSender = commandSender;
}
@Override
public void invoke(String s) {
MCMResponse response = new MCMResponse(s);
commandSender.sendMessage(response.getMCMessage());
}
}
private void clear(CommandSender sender, String id) { private void clear(CommandSender sender, String id) {
if (sender.hasPermission("minecraftmanager.application.action")) { if (sender.hasPermission("minecraftmanager.application.action")) {
if (StringUtils.isNumeric(id)) { if (StringUtils.isNumeric(id)) {
MCMResponse response = new MCMResponse(MCMAPI.postApplicationClear(id)); String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/application_clear/";
sender.sendMessage(ChatColor.GREEN + response.getMCMessage()); Map<String, String> data = MCMAPI.setup();
data.put("application_id", id);
CoreWeb.asyncPostCallback(plugin, djangoUrl, data, new ClearCallback(sender));
} else { } else {
sender.sendMessage(ChatColor.RED + "You must use an application ID to ensure accuracy."); sender.sendMessage(ChatColor.RED + "You must use an application ID to ensure accuracy.");
} }

View File

@ -1,17 +1,11 @@
package xyz.etztech.minecraftmanager.command; package xyz.etztech.minecraftmanager.command;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import xyz.etztech.minecraftmanager.MinecraftManager; import xyz.etztech.minecraftmanager.MinecraftManager;
import xyz.etztech.minecraftmanager.MinecraftManagerThread;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class CommandApply implements CommandExecutor { public class CommandApply implements CommandExecutor {

View File

@ -8,15 +8,18 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.core.web.ICallback;
import xyz.etztech.minecraftmanager.MCMAPI; import xyz.etztech.minecraftmanager.MCMAPI;
import xyz.etztech.minecraftmanager.MCMResponse; import xyz.etztech.minecraftmanager.objects.MCMResponse;
import xyz.etztech.minecraftmanager.MinecraftManager; import xyz.etztech.minecraftmanager.MinecraftManager;
import xyz.etztech.minecraftmanager.MinecraftManagerThread; import xyz.etztech.minecraftmanager.objects.MinecraftManagerThread;
import xyz.etztech.minecraftmanager.tasks.ReportRunnable;
import javax.xml.soap.Text;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.util.Map;
public class CommandMain implements CommandExecutor { public class CommandMain implements CommandExecutor {
@ -53,6 +56,9 @@ public class CommandMain implements CommandExecutor {
case "register": case "register":
register(sender); register(sender);
break; break;
case "report":
report(sender);
break;
default: default:
other(sender); other(sender);
} }
@ -94,6 +100,30 @@ public class CommandMain implements CommandExecutor {
} }
} }
private class RegisterCallback implements ICallback {
private Player player;
RegisterCallback(Player player) {
this.player = player;
}
@Override
public void invoke(String s) {
MCMResponse response = new MCMResponse(s);
if (response.getStatus()) {
TextComponent password = new TextComponent(ChatColor.YELLOW + response.getMessage());
password.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, response.getMessage()));
TextComponent message = new TextComponent(ChatColor.GREEN + "Your password is ");
message.addExtra(password);
message.addExtra(new TextComponent(ChatColor.GREEN + "."));
player.spigot().sendMessage(message);
player.sendMessage(ChatColor.GREEN + "This password is not shown in Console, however you should consider changing it immediately from the web application.");
player.sendMessage(ChatColor.GREEN + "You can click the password to bring it into your chat for easy copying.");
} else {
player.sendMessage(ChatColor.RED + response.getMessage());
}
}
}
private void register(CommandSender sender) { private void register(CommandSender sender) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Console cannot register for the web application."); sender.sendMessage(ChatColor.RED + "Console cannot register for the web application.");
@ -106,18 +136,26 @@ public class CommandMain implements CommandExecutor {
} }
Player player = (Player) sender; Player player = (Player) sender;
MCMResponse response = new MCMResponse(MCMAPI.getPassword(player.getUniqueId().toString())); String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/register/";
if (response.getStatus()) { Map<String, String> data = MCMAPI.setup();
TextComponent password = new TextComponent(ChatColor.YELLOW + response.getMessage()); data.put("uuid", player.getUniqueId().toString());
password.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, response.getMessage()));
TextComponent message = new TextComponent(ChatColor.GREEN + "Your password is "); CoreWeb.asyncPostCallback(plugin, djangoUrl, data, new RegisterCallback(player));
message.addExtra(password);
message.addExtra(new TextComponent(ChatColor.GREEN + "."));
player.spigot().sendMessage(message);
player.sendMessage(ChatColor.GREEN + "This password is not shown in Console, however you should consider changing it immediately from the web application."); }
player.sendMessage(ChatColor.GREEN + "You can click the password to bring it into your chat for easy copying.");
private void report(CommandSender sender) {
String name = sender instanceof Player ? sender.getName() : "Console";
if (sender.hasPermission("minecraftmanager.report")) {
if (MinecraftManager.getReportRunning()) {
MinecraftManager.setReportStop(true);
sender.sendMessage(ChatColor.GREEN + "Stopping report generation.");
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, new ReportRunnable(name));
} else { } else {
player.sendMessage(ChatColor.RED + response.getMessage()); sender.sendMessage(ChatColor.RED + "You do not have permission to generate a report.");
} }
} }

View File

@ -1,48 +1,25 @@
package xyz.etztech.minecraftmanager.command; package xyz.etztech.minecraftmanager.command;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import xyz.etztech.minecraftmanager.MinecraftManager; import xyz.etztech.minecraftmanager.MinecraftManager;
import xyz.etztech.minecraftmanager.MinecraftManagerThread;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.List;
public class CommandRules implements CommandExecutor { public class CommandRules implements CommandExecutor {
MinecraftManager plugin; MinecraftManager plugin;
String rules;
public CommandRules(MinecraftManager plugin) { public CommandRules(MinecraftManager plugin) {
this.plugin = plugin; this.plugin = plugin;
reload();
} }
public void reload() {
List<String> rules = this.plugin.getConfig().getStringList("rules.rules");
if (this.plugin.getConfig().getBoolean("rules.application.validate")) {
String finalAnswer = this.plugin.getConfig().getString("rules.application.answer");
rules.add("The answer for the final question is \"" + finalAnswer + "\"");
}
StringBuilder rulesMessage = new StringBuilder(ChatColor.GOLD + "===== Rules =====");
for (int i = 0; i < rules.size(); i++) {
rulesMessage.append("\n" + ChatColor.YELLOW + (i + 1) + ". " + rules.get(i));
}
this.rules = rulesMessage.toString();
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) { public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
sender.sendMessage(this.rules); sender.sendMessage(MinecraftManager.getRules().minecraft());
return true; return true;
} }

View File

@ -8,10 +8,14 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.core.web.ICallback;
import xyz.etztech.minecraftmanager.MCMAPI; import xyz.etztech.minecraftmanager.MCMAPI;
import xyz.etztech.minecraftmanager.MCMResponse; import xyz.etztech.minecraftmanager.objects.MCMResponse;
import xyz.etztech.minecraftmanager.MinecraftManager; import xyz.etztech.minecraftmanager.MinecraftManager;
import java.util.Map;
public class CommandTicket implements CommandExecutor { public class CommandTicket implements CommandExecutor {
MinecraftManager plugin; MinecraftManager plugin;
@ -20,6 +24,20 @@ public class CommandTicket implements CommandExecutor {
this.plugin = plugin; this.plugin = plugin;
} }
private class TicketCallback implements ICallback {
private Player player;
TicketCallback(Player player) {
this.player = player;
}
@Override
public void invoke(String s) {
MCMResponse response = new MCMResponse(s);
player.sendMessage(response.getMCMessage());
}
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) { public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
@ -45,12 +63,19 @@ public class CommandTicket implements CommandExecutor {
} else if (World.Environment.THE_END == env) { } else if (World.Environment.THE_END == env) {
world = "E"; world = "E";
} }
MCMResponse response = new MCMResponse(MCMAPI.postTicket(player.getUniqueId().toString(), String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/ticket/";
StringUtils.join(args, " "), x, y, z, world)); Map<String, String> data = MCMAPI.setup();
sender.sendMessage(response.getMCMessage()); data.put("uuid", player.getUniqueId().toString());
data.put("message", StringUtils.join(args, " "));
data.put("x", x);
data.put("y", y);
data.put("z", z);
data.put("world", world);
CoreWeb.asyncPostCallback(plugin, djangoUrl, data, new TicketCallback(player));
} else { } else {
sender.sendMessage(ChatColor.RED + "You do not have permission to submit a ticket."); sender.sendMessage(ChatColor.RED + "You do not have permission to submit a ticket.");
sender.sendMessage(ChatColor.RED + "If you were submitting a ticket about not being able to submit a ticket, that is known as irony."); sender.sendMessage(ChatColor.RED + "If you were submitting a ticket about not being able to submit a ticket, that's called irony.");
} }
return true; return true;

View File

@ -0,0 +1,86 @@
package xyz.etztech.minecraftmanager.command;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.core.web.ICallback;
import xyz.etztech.minecraftmanager.MCMAPI;
import xyz.etztech.minecraftmanager.objects.MCMResponse;
import xyz.etztech.minecraftmanager.MCMUtil;
import xyz.etztech.minecraftmanager.MinecraftManager;
import java.util.Arrays;
import java.util.Map;
public class CommandWarning implements CommandExecutor {
MinecraftManager plugin;
public CommandWarning(MinecraftManager plugin) {
this.plugin = plugin;
}
private class WarningCallback implements ICallback {
private Player player;
WarningCallback(Player player) {
this.player = player;
}
@Override
public void invoke(String s) {
MCMResponse response = new MCMResponse(s);
player.sendMessage(response.getMCMessage());
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "The console cannot issue warnings.");
return true;
}
Player staff = (Player) sender;
if (sender.hasPermission("minecraftmanager.warning")) {
if (args.length < 3) {
sender.sendMessage(ChatColor.RED + "/warning <player> <severity> <message>");
return true;
}
String uuid = MCMUtil.getUUID(args[0]);
if (uuid == null) {
sender.sendMessage(ChatColor.RED + "Could not issue warning, no player found.");
return false;
}
String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/warning/";
Map<String, String> data = MCMAPI.setup();
data.put("player", uuid);
data.put("staff", staff.getUniqueId().toString());
data.put("severity", getSeverity(args[1]));
data.put("message", StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "));
CoreWeb.asyncPostCallback(plugin, djangoUrl, data, new WarningCallback(staff));
} else {
sender.sendMessage(ChatColor.RED + "You do not have permission to issue a warning.");
}
return true;
}
private String getSeverity(String severity) {
if (severity.equalsIgnoreCase("H") || severity.equalsIgnoreCase("HIGH")) {
return "H";
} else if (severity.equalsIgnoreCase("M") || severity.equalsIgnoreCase("MEDIUM")) {
return "M";
} else {
return "L";
}
}
}

View File

@ -6,20 +6,20 @@ import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.core.web.ICallback;
import xyz.etztech.minecraftmanager.*; import xyz.etztech.minecraftmanager.*;
import xyz.etztech.minecraftmanager.objects.Application;
import xyz.etztech.minecraftmanager.objects.MCMResponse;
import xyz.etztech.minecraftmanager.objects.Question;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class AsyncPlayerChatListener implements Listener { public class AsyncPlayerChatListener implements Listener {
@ -38,17 +38,28 @@ public class AsyncPlayerChatListener implements Listener {
this.staffPrefixes.addAll(trimmed(this.plugin.getConfig().getStringList("staff-chat.prefix"))); this.staffPrefixes.addAll(trimmed(this.plugin.getConfig().getStringList("staff-chat.prefix")));
} }
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) @EventHandler
public void onChat(AsyncPlayerChatEvent event) { public void onChat(AsyncPlayerChatEvent event) {
Player sender = event.getPlayer(); Player sender = event.getPlayer();
String chat = event.getMessage(); String chat = event.getMessage();
boolean staffChat = isStaffChat(sender, chat);
boolean applyChat = MinecraftManager.inApplyMode(sender.getUniqueId().toString()); boolean applyChat = MinecraftManager.inApplyMode(sender.getUniqueId().toString());
TextComponent pre = new TextComponent(ChatColor.GOLD + sender.getName() + " > "); TextComponent pre = new TextComponent(ChatColor.GOLD + sender.getName() + " > ");
if (!applyChat) { if (!applyChat) {
if (staffChat) { boolean hasPermission = sender.hasPermission("minecraftmanager.staff");
boolean singlePrefix = false;
for (String prefix : this.staffPrefixes) {
if (chat.startsWith(prefix)) {
chat = chat.substring(1);
singlePrefix = true;
if (chat.startsWith(prefix)) {
singlePrefix = false;
event.setMessage(chat);
}
}
}
if (hasPermission && singlePrefix) {
event.setCancelled(true); event.setCancelled(true);
for (String prefix : this.staffPrefixes) { for (String prefix : this.staffPrefixes) {
chat = chat.replaceFirst(Pattern.quote(prefix), ""); chat = chat.replaceFirst(Pattern.quote(prefix), "");
@ -65,8 +76,10 @@ public class AsyncPlayerChatListener implements Listener {
MCMUtil.log(MCMUtil.staffLog, componentText(pre, message)); MCMUtil.log(MCMUtil.staffLog, componentText(pre, message));
} else { } else {
TextComponent message = generateMessage(chat); TextComponent message = generateMessage(chat);
if (!MinecraftManager.getLogOverride()) {
MCMUtil.log(MCMUtil.globalLog, componentText(pre, message)); MCMUtil.log(MCMUtil.globalLog, componentText(pre, message));
} }
}
} else { } else {
// Applying // Applying
event.setCancelled(true); event.setCancelled(true);
@ -89,8 +102,10 @@ public class AsyncPlayerChatListener implements Listener {
// Answering question // Answering question
boolean valid = Question.validate(applyQuestion, chat); boolean valid = Question.validate(applyQuestion, chat);
boolean rules = this.plugin.getConfig().getBoolean("rules.application.validate"); boolean rules = this.plugin.getConfig().getBoolean("rules.application.validate");
if (Question.FIVE == applyQuestion && !rules) { String answer = this.plugin.getConfig().getString("rules.application.answer");
valid = true; if (Question.FIVE == applyQuestion && rules && !chat.equalsIgnoreCase(answer)) {
sender.sendMessage(ChatColor.RED + Question.READ_RULES);
return;
} }
if (!valid) { if (!valid) {
sender.sendMessage(ChatColor.RED + applyQuestion.getError()); sender.sendMessage(ChatColor.RED + applyQuestion.getError());
@ -106,13 +121,11 @@ public class AsyncPlayerChatListener implements Listener {
if (Question.COMPLETE == nextQuestion) { if (Question.COMPLETE == nextQuestion) {
MinecraftManager.setApplyMode(sender.getUniqueId().toString(), false); MinecraftManager.setApplyMode(sender.getUniqueId().toString(), false);
Bukkit.getConsoleSender().sendMessage(app.getFormatted()); Bukkit.getConsoleSender().sendMessage(app.getFormatted());
MCMResponse response = new MCMResponse(MCMAPI.postApplication(app)); String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/application/";
if (response.getStatus()) { Map<String, String> data = MCMAPI.setup();
sender.sendMessage(ChatColor.GOLD + nextQuestion.getQuestion()); data.putAll(app.getForm());
MCMUtil.staffMessage(ChatColor.GREEN + "New application #" + response.getExtra().getAsString() + " from " + sender.getName(), "/app info " + response.getExtra().getAsString());
} else { CoreWeb.asyncPostCallback(plugin, djangoUrl, data, new ApplicationCallback(sender));
sender.sendMessage(ChatColor.RED + response.getMessage());
}
} else { } else {
sender.sendMessage(ChatColor.GREEN + nextQuestion.getQuestion()); sender.sendMessage(ChatColor.GREEN + nextQuestion.getQuestion());
} }
@ -120,18 +133,26 @@ public class AsyncPlayerChatListener implements Listener {
} }
} }
private boolean isStaffChat(Player player, String message) { private class ApplicationCallback implements ICallback {
if (!player.hasPermission("minecraftmanager.staff")) { private Player player;
return false;
ApplicationCallback(Player player) {
this.player = player;
} }
for (String prefix : this.staffPrefixes) {
if (message.startsWith(prefix) && !message.startsWith(prefix+prefix)) { @Override
return true; public void invoke(String s) {
MCMResponse response = new MCMResponse(s);
if (response.getStatus()) {
player.sendMessage(ChatColor.GOLD + Question.COMPLETE.getQuestion());
MCMUtil.staffMessage(ChatColor.GREEN + "New application #" + response.getExtra().getAsString() + " from " + player.getName(), "/app info " + response.getExtra().getAsString());
} else {
player.sendMessage(ChatColor.RED + response.getMessage());
} }
} }
return false;
} }
private TextComponent generateMessage(String message) { private TextComponent generateMessage(String message) {
TextComponent text = new TextComponent(); TextComponent text = new TextComponent();
for (String part : message.split(" ")) { for (String part : message.split(" ")) {

View File

@ -0,0 +1,84 @@
package xyz.etztech.minecraftmanager.listeners;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.minecraftmanager.MCMAPI;
import xyz.etztech.minecraftmanager.MCMUtil;
import xyz.etztech.minecraftmanager.MinecraftManager;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CommandPreprocessListener implements Listener {
MinecraftManager plugin;
public CommandPreprocessListener(MinecraftManager plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String command = event.getMessage().substring(1); // Strip the slash
String base = command.split(" ")[0];
String[] args = command.trim().length() == base.trim().length() ? new String[0] : command.substring(base.length()+1).split(" ");
Player sender = event.getPlayer();
if (sender.hasPermission("minecraftmanager.warn") && "ban".equalsIgnoreCase(base)) {
if (args.length < 1) {
return;
}
if (plugin.getConfig().getBoolean("ban.enabled")) {
String uuid = MCMUtil.getUUID(args[0]);
if (uuid != null) {
String message = "";
if (StringUtils.isNumeric(args[1])) {
int option = Integer.parseInt(args[1]);
List<String> options = MinecraftManager.getBanOptions();
if (option <= options.size()) {
message = options.get(option-1);
Bukkit.getConsoleSender().sendMessage("Reformatting ban...");
sender.chat("/ban " + args[0] + " " + message);
} else {
sender.sendMessage(ChatColor.RED + "Ban Option not recognized.");
}
event.setCancelled(true);
return;
} else {
message = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
}
if (plugin.getConfig().getBoolean("ban.auto-warning")) {
String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/warning/";
Map<String, String> data = MCMAPI.setup();
data.put("player", uuid);
data.put("staff", sender.getUniqueId().toString());
data.put("severity", "H");
data.put("message", message);
CoreWeb.asyncPost(plugin, djangoUrl, data);
}
}
}
}
}
}

View File

@ -2,19 +2,18 @@ package xyz.etztech.minecraftmanager.listeners;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import xyz.etztech.minecraftmanager.MCMAPI; import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.minecraftmanager.MCMUtil; import xyz.etztech.core.web.ICallback;
import xyz.etztech.minecraftmanager.MinecraftManager; import xyz.etztech.minecraftmanager.*;
import xyz.etztech.minecraftmanager.MinecraftManagerThread; import xyz.etztech.minecraftmanager.objects.MinecraftManagerThread;
import xyz.etztech.minecraftmanager.objects.ModelResponse;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class SessionListener implements Listener { public class SessionListener implements Listener {
@ -28,13 +27,24 @@ public class SessionListener implements Listener {
@EventHandler @EventHandler
public void onLogin(PlayerLoginEvent event) { public void onLogin(PlayerLoginEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
MCMAPI.postLogin(player.getName(), player.getUniqueId().toString(), event.getAddress().getHostAddress()); String djangoUrl = MCMAPI.getDjangoUrl() + "plugin/login/";
Map<String, String> data = MCMAPI.setup();
data.put("username", player.getName());
data.put("uuid", player.getUniqueId().toString());
data.put("ip", event.getAddress().getHostAddress());
CoreWeb.asyncPost(plugin, djangoUrl, data);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
MCMUtil.log(MCMUtil.globalLog, player.getName() + " logged in."); MCMUtil.log(MCMUtil.globalLog, player.getName() + " logged in.");
// Check for guests // Check for guests
if (player.hasPermission("minecraftmanager.guest")) { if (player.hasPermission("minecraftmanager.guest")) {
Map<String, String> filters = new HashMap<>(); Map<String, String> filters = MCMAPI.setup();
filters.put("username__iexact", player.getName()); filters.put("username__iexact", player.getName());
CoreWeb.asyncGetCallback(plugin, MCMAPI.getModelUrl("application"), filters, new JoinCallback(player.getName()));
JsonArray query = MCMAPI.queryModel("application", filters); JsonArray query = MCMAPI.queryModel("application", filters);
if (query.size() == 1) { if (query.size() == 1) {
JsonElement element = query.get(0).getAsJsonObject().get("accepted"); JsonElement element = query.get(0).getAsJsonObject().get("accepted");
@ -46,6 +56,27 @@ public class SessionListener implements Listener {
} }
} }
private class JoinCallback implements ICallback {
private String name;
JoinCallback(String name) {
this.name = name;
}
@Override
public void invoke(String s) {
ModelResponse response = new ModelResponse(s);
JsonArray query = response.getResults();
if (query.size() == 1) {
JsonElement element = query.get(0).getAsJsonObject().get("accepted");
boolean accepted = !element.isJsonNull() && element.getAsBoolean();
if (accepted) {
MinecraftManagerThread.action(name, true);
}
}
}
}
@EventHandler @EventHandler
public void onLogout(PlayerQuitEvent event) { public void onLogout(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -1,6 +1,4 @@
package xyz.etztech.minecraftmanager; package xyz.etztech.minecraftmanager.objects;
import org.apache.commons.lang.StringUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -0,0 +1,41 @@
package xyz.etztech.minecraftmanager.objects;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.ChatColor;
import xyz.etztech.core.web.CoreResponse;
import java.util.logging.Logger;
public class MCMResponse extends CoreResponse {
private JsonElement extra;
public MCMResponse(JsonArray httpResponse) {
super(httpResponse);
setExtra(json.get("extra"));
}
public MCMResponse(JsonObject httpResponse) {
super(httpResponse);
setExtra(httpResponse.get("extra"));
}
public MCMResponse(String rawReponse) {
super(rawReponse);
setExtra(json.get("extra"));
}
public JsonElement getExtra() {
return extra;
}
public void setExtra(JsonElement extra) {
this.extra = extra;
}
}

View File

@ -1,10 +1,12 @@
package xyz.etztech.minecraftmanager; 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.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import xyz.etztech.minecraftmanager.MCMUtil;
import xyz.etztech.minecraftmanager.MinecraftManager;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -99,7 +101,8 @@ public class MinecraftManagerThread extends Thread {
} }
if (online != null) { if (online != null) {
// Set their group // Set their group if accepted
if (accepted) {
String engine = MinecraftManager.config.getString("permissions.engine"); String engine = MinecraftManager.config.getString("permissions.engine");
String promote = MinecraftManager.config.getString("permissions.promote"); String promote = MinecraftManager.config.getString("permissions.promote");
if ("permissionsex".equalsIgnoreCase(engine)) { if ("permissionsex".equalsIgnoreCase(engine)) {
@ -107,6 +110,7 @@ public class MinecraftManagerThread extends Thread {
} else if ("luckperms".equalsIgnoreCase(engine)) { } else if ("luckperms".equalsIgnoreCase(engine)) {
runTask("lp user <player> group set " + promote, username); runTask("lp user <player> group set " + promote, username);
} }
}
// Run misc commands // Run misc commands
List<String> commands = MinecraftManager.config.getStringList(path + ".commands"); List<String> commands = MinecraftManager.config.getStringList(path + ".commands");
@ -114,6 +118,9 @@ public class MinecraftManagerThread extends Thread {
runTask(command, username); runTask(command, username);
} }
} }
// Message to staff
MCMUtil.staffMessage(ChatColor.GREEN + username + " was " + (accepted ? "accepted" : "denied") + ".");
} }
private static void runTask(final String command, final String username) { private static void runTask(final String command, final String username) {

View File

@ -0,0 +1,25 @@
package xyz.etztech.minecraftmanager.objects;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
public class ModelResponse {
private JsonArray results;
public ModelResponse(String results) {
try {
JsonParser parser = new JsonParser();
this.results = (com.google.gson.JsonArray) parser.parse(results);
} catch (Exception ex) {
this.results = new JsonArray();
}
}
public JsonArray getResults() {
return results;
}
public void setResults(JsonArray results) {
this.results = results;
}
}

View File

@ -1,4 +1,4 @@
package xyz.etztech.minecraftmanager; package xyz.etztech.minecraftmanager.objects;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -9,9 +9,11 @@ public enum Question {
THREE1("Have you ever been banned? Please answer just 'yes' or 'no'.", "Your answer must be just 'yes' or 'no'."), 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."), 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."), FOUR("Were you referred to our server by someone?", "Your answer must be under 50 characters long."),
FIVE("Have you read the rules thoroughly?", "Are you sure? Maybe you should read them again..."), FIVE("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!", ""); 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...";
private String question; private String question;
private String error; private String error;
@ -71,8 +73,7 @@ public enum Question {
} else if (question == FOUR) { } else if (question == FOUR) {
return answer.length() <= 50; return answer.length() <= 50;
} else if (question == FIVE) { } else if (question == FIVE) {
String a = MinecraftManager.config.getString("rules.application.answer"); return answer.length() <= 10;
return answer.equalsIgnoreCase(a);
} }
return false; return false;
} }

View File

@ -0,0 +1,70 @@
package xyz.etztech.minecraftmanager.objects;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Rules {
private List<String> rules = new ArrayList<>();
private Map<String, List<String>> subRules = new HashMap<>();
public Rules(FileConfiguration config) {
List<String> configRules = config.getStringList("rules.rules");
if (config.getBoolean("rules.application.validate")) {
String finalAnswer = config.getString("rules.application.answer");
configRules.add("The answer for the final question is \"" + finalAnswer + "\"");
}
for (String configRule : configRules) {
if (configRule.startsWith("*")) {
configRule = configRule.substring(1);
List<String> subs = subRules.get(rules.get(rules.size()-1));
if (subs != null) {
subs.add(configRule);
} else {
subs = new ArrayList<>();
subs.add(configRule);
}
subRules.put(rules.get(rules.size()-1), subs);
} else {
rules.add(configRule);
}
}
}
public List<String> getRules() {
return rules;
}
public void setRules(List<String> rules) {
this.rules = rules;
}
public Map<String, List<String>> getSubRules() {
return subRules;
}
public void setSubRules(Map<String, List<String>> subRules) {
this.subRules = subRules;
}
public String minecraft() {
StringBuilder rulesMessage = new StringBuilder(ChatColor.GOLD + "===== Rules =====");
int idx = 0;
for (String rule : rules) {
rulesMessage.append("\n" + ChatColor.YELLOW + (++idx) + ". " + rule);
List<String> subs = subRules.get(rule);
if (subs != null) {
for (String sub : subs) {
rulesMessage.append("\n" + ChatColor.YELLOW + "* " + sub);
}
}
}
return rulesMessage.toString();
}
}

View File

@ -0,0 +1,108 @@
package xyz.etztech.minecraftmanager.tasks;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import xyz.etztech.minecraftmanager.MCMUtil;
import xyz.etztech.minecraftmanager.MinecraftManager;
import java.io.File;
import java.io.FileWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class ReportRunnable implements Runnable {
private String calledBy;
public ReportRunnable(String calledBy) {
this.calledBy = calledBy;
}
@Override
public void run() {
MCMUtil.staffMessage("A report has been started by " + calledBy + ".");
MinecraftManager.setReportRunning(true);
MinecraftManager.setReportStop(false);
boolean interrupted = false;
JsonObject reportJson = new JsonObject();
dance: // Is it worth the joke? We may never know...
for (World world : Bukkit.getServer().getWorlds()) {
Map<String, Integer> countMap = new HashMap<>();
if (MinecraftManager.getReportStop()) {
interrupted = true;
break;
}
Map<String, JsonArray> entitiesMap = new HashMap<>();
JsonArray playersJson = new JsonArray();
for (Entity entity : world.getEntities()) {
if (MinecraftManager.getReportStop()) {
interrupted = true;
break dance;
}
JsonObject entityJson = new JsonObject();
Location location = entity.getLocation();
entityJson.addProperty("x", location.getBlockX());
entityJson.addProperty("y", location.getBlockY());
entityJson.addProperty("z", location.getBlockZ());
if (entity instanceof Player) {
entityJson.addProperty("name", entity.getName());
playersJson.add(entityJson);
} else {
String type = entity.getType().name();
JsonArray jsonArray = entitiesMap.get(type);
if (jsonArray == null) {
jsonArray = new JsonArray();
}
jsonArray.add(entityJson);
entitiesMap.put(type, jsonArray);
if (countMap.containsKey(type)) {
countMap.put(type, countMap.get(type) + 1);
} else {
countMap.put(type, 1);
}
}
}
JsonObject worldJson = new JsonObject();
JsonObject entitiesJson = new JsonObject();
for (String type : entitiesMap.keySet()) {
entitiesJson.add(type, entitiesMap.get(type));
}
worldJson.add("entities", entitiesJson);
worldJson.add("players", playersJson);
JsonObject countJson = new JsonObject();
for (String type : countMap.keySet()) {
countJson.addProperty(type, countMap.get(type));
}
worldJson.add("counts", countJson);
reportJson.add(world.getName(), worldJson);
reportJson.addProperty("time", new Date().getTime()/1000);
}
File report = new File(Bukkit.getPluginManager().getPlugin("MinecraftManager").getDataFolder().getAbsolutePath() + "/report.json");
try {
if (!report.exists()) {
report.createNewFile();
}
FileWriter writer = new FileWriter(report);
writer.write(reportJson.toString());
writer.close();
} catch (Exception ex) {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Could not generate a report...something went wrong.");
}
MinecraftManager.setReportStop(false);
MinecraftManager.setReportRunning(false);
if (interrupted) {
MCMUtil.staffMessage("The report started by " + calledBy + " has been stopped.");
} else {
MCMUtil.staffMessage("The report started by " + calledBy + " has finished generating.");
}
}
}

View File

@ -2,11 +2,10 @@ package xyz.etztech.minecraftmanager.test;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import xyz.etztech.minecraftmanager.Application; import xyz.etztech.minecraftmanager.objects.Application;
import xyz.etztech.minecraftmanager.MCMAPI; import xyz.etztech.minecraftmanager.MCMAPI;
import xyz.etztech.minecraftmanager.MCMResponse; import xyz.etztech.minecraftmanager.objects.MCMResponse;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -37,6 +36,7 @@ public class Test {
System.out.println("5. Test Application Clear - Clear Testing2 application"); System.out.println("5. Test Application Clear - Clear Testing2 application");
System.out.println("6. Test Login - Spoof a login of user Etzelia with IP 127.0.0.1"); System.out.println("6. Test Login - Spoof a login of user Etzelia with IP 127.0.0.1");
System.out.println("7. Test Ticket - Send a test ticket"); System.out.println("7. Test Ticket - Send a test ticket");
System.out.println("8. Test Warning - Send a test warning, medium importance, issued to Etzelia");
System.out.println("99. Exit"); System.out.println("99. Exit");
System.out.print("Select Option: "); System.out.print("Select Option: ");
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
@ -64,6 +64,9 @@ public class Test {
case 7: case 7:
option = 7; option = 7;
break; break;
case 8:
option = 8;
break;
case 99: case 99:
option = 99; option = 99;
break; break;
@ -148,6 +151,11 @@ public class Test {
System.out.println("===== Ticket ====="); System.out.println("===== Ticket =====");
System.out.println("Status: " + response.getStatus()); System.out.println("Status: " + response.getStatus());
System.out.println("Message: " + response.getMessage()); System.out.println("Message: " + response.getMessage());
} else if (option == 8) {
MCMResponse response = new MCMResponse(MCMAPI.postWarning("bf0446a8-9695-4c41-aa4c-7ff45bfd1171", "bf0446a8-9695-4c41-aa4c-7ff45bfd1171", "M", "Test Warning"));
System.out.println("===== Warning =====");
System.out.println("Status: " + response.getStatus());
System.out.println("Message: " + response.getMessage());
} }
} }
} }

View File

@ -8,18 +8,37 @@ staff-chat:
prefix: prefix:
- "#" - "#"
# Override rules
# A '*' before a rule will show as a sub-rule
rules: rules:
enabled: true enabled: true
rules: rules:
- "Be respectful of other players and staff." - "Respect public and private builds, spaces and boundaries"
- "Do not troll, harass, or ruin the game-play of other players. No PvP unless agreed upon." - "*No griefing, no altering of other player's builds without consent. Respect builds and boundaries of spawn, nether hub and public tunnels."
- "Respect the boundaries of other players and Spawn." - "*Repair damage caused by mobs"
- "No cheating. (X-ray, Duping, etc.)" - "*No PvP unless agreed upon"
- "Don't steal. All chests are private unless marked otherwise." - "Do not cheat"
- "*Don't try to get ahead of other players by cheating. No X-RAY, duping, flying, etc."
- "*Some mods for enhancing gameplay are allowed, ask staff about them."
- "Do not steal"
- "*Don't take anything from other players without permission. All chests are private unless marked otherwise. Be sure to pay for what you buy!"
application: application:
validate: true validate: true
answer: "24karrot" answer: "24karrot"
# Ban options
# Bans can auto-generate a warning (High severity)
# Ban options are shortcuts: Instead of /ban Etzelia Do not steal
# You could instead type /ban Etzelia 1
ban:
enabled: true
auto-warning: true
options:
- "Do not grief and/or PvP without consent"
- "Do not xray and/or use a hacked client"
- "Do not steal"
- "Do not use an alt to evade a ban"
permissions: permissions:
# Can be PermissionsEX or LuckPerms # Can be PermissionsEX or LuckPerms
engine: "PermissionsEX" engine: "PermissionsEX"
@ -40,7 +59,6 @@ deny:
commands: commands:
- "mute <player>" - "mute <player>"
django: django:
# URL to the base MCM API # URL to the base MCM API
url: "http://localhost:8000/api/" url: "http://localhost:8000/api/"

View File

@ -17,6 +17,9 @@ commands:
ticket: ticket:
description: Submit a help ticket description: Submit a help ticket
aliases: [] aliases: []
warning:
description: Issue a warning
aliases: [warn]
application: application:
description: Application commands. Accept, Deny, Search, Info description: Application commands. Accept, Deny, Search, Info
aliases: [app] aliases: [app]
@ -33,6 +36,9 @@ permissions:
minecraftmanager.ticket: minecraftmanager.ticket:
description: Allows use of the Ticket command. description: Allows use of the Ticket command.
default: op default: op
minecraftmanager.warning:
description: Allows use of the Warning command.
default: op
minecraftmanager.application.search: minecraftmanager.application.search:
description: Allows a player to search through applications description: Allows a player to search through applications
default: op default: op
@ -45,6 +51,9 @@ permissions:
minecraftmanager.register: minecraftmanager.register:
description: Who is allowed to register for the MCM web application description: Who is allowed to register for the MCM web application
default: op default: op
minecraftmanager.report:
description: Who is allowed to generate an entity report.
default: op
minecraftmanager.application.*: minecraftmanager.application.*:
description: Wildcard permission for MCM applications description: Wildcard permission for MCM applications
default: op default: op
@ -58,6 +67,8 @@ permissions:
minecraftmanager.use: true minecraftmanager.use: true
minecraftmanager.apply: true minecraftmanager.apply: true
minecraftmanager.ticket: true minecraftmanager.ticket: true
minecraftmanager.warning: true
minecraftmanager.application.*: true minecraftmanager.application.*: true
minecraftmanager.staff: true minecraftmanager.staff: true
minecraftmanager.register: true minecraftmanager.register: true
minecraftmanager.report: true