Merge branch 'master' into OreAlert

master
Etzelia 2018-12-07 17:10:08 -06:00
commit 2d0b768538
9 changed files with 53 additions and 42 deletions

View File

@ -39,6 +39,11 @@
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
<version>2.6</version> <version>2.6</version>
</dependency> </dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency> <dependency>
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>EtzCore</artifactId> <artifactId>EtzCore</artifactId>

View File

@ -1,46 +1,39 @@
package xyz.etztech.minecraftmanager; package xyz.etztech.minecraftmanager;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import net.md_5.bungee.api.chat.*; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
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 xyz.etztech.core.web.CoreWeb; import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.minecraftmanager.objects.ModelResponse; import xyz.etztech.minecraftmanager.objects.ModelResponse;
import javax.xml.soap.Text;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class MCMUtil { public class MCMUtil {
private static FileWriter globalFile; public static Logger globalLogger;
public static PrintWriter globalLog; public static Logger staffLogger;
private static FileWriter staffFile;
public static PrintWriter staffLog;
public static void init() { public static void init() {
MinecraftManager plugin = (MinecraftManager) Bukkit.getPluginManager().getPlugin("MinecraftManager"); MinecraftManager plugin = (MinecraftManager) Bukkit.getPluginManager().getPlugin("MinecraftManager");
String pluginPath = plugin.getDataFolder().getAbsolutePath(); String pluginPath = plugin.getDataFolder().getAbsolutePath();
String globalPath = pluginPath + "/logs/global.log"; System.setProperty("mcm.log", pluginPath + "/logs");
try { try {
globalFile = new FileWriter(globalPath, true); globalLogger = Logger.getLogger("mcm.global");
globalLog = new PrintWriter(globalFile);
} catch (Exception e) { } catch (Exception e) {
plugin.log("Could not connect to global log (" + globalPath + ")."); plugin.log("Could not connect to global log.");
} }
if (plugin.getConfig().getBoolean("staff-chat.enabled")) { if (plugin.getConfig().getBoolean("staff-chat.enabled")) {
String staffPath = pluginPath + "/logs/staff.log";
try { try {
staffFile = new FileWriter(staffPath, true); globalLogger = Logger.getLogger("mcm.staff");
staffLog = new PrintWriter(staffFile);
} catch (Exception e) { } catch (Exception e) {
plugin.log("Could not connect to staff log (" + staffPath + ")."); plugin.log("Could not connect to staff log.");
} }
} }
} }
@ -49,7 +42,7 @@ public class MCMUtil {
staffMessage(message, false); staffMessage(message, false);
} }
public static void staffMessage(String message, boolean mcm) { public static void staffMessage(String message, boolean mcm) {
log(staffLog, message); log(staffLogger, message);
String tag = mcm ? "MCM " : ""; String tag = mcm ? "MCM " : "";
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(tag + "Staff Chat").create()); HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(tag + "Staff Chat").create());
TextComponent text = new TextComponent(message); TextComponent text = new TextComponent(message);
@ -64,7 +57,7 @@ public class MCMUtil {
@Deprecated @Deprecated
public static void staffMessage(String message, String hoverCommand) { public static void staffMessage(String message, String hoverCommand) {
log(staffLog, message); log(staffLogger, 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);
@ -80,7 +73,7 @@ public class MCMUtil {
} }
public static void staffMessage(TextComponent message) { public static void staffMessage(TextComponent message) {
log(staffLog, message.toPlainText()); log(staffLogger, message.toPlainText());
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(message); player.spigot().sendMessage(message);
@ -90,14 +83,14 @@ public class MCMUtil {
} }
public static void globalMessage(String message) { public static void globalMessage(String message) {
log(globalLog, message); log(globalLogger, message);
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.sendMessage(message); player.sendMessage(message);
} }
} }
public static void globalMessage(TextComponent message) { public static void globalMessage(TextComponent message) {
log(globalLog, message.toPlainText()); log(globalLogger, message.toPlainText());
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.spigot().sendMessage(message); player.spigot().sendMessage(message);
} }
@ -122,18 +115,13 @@ public class MCMUtil {
return uuid; return uuid;
} }
public static void log(PrintWriter logger, String message) { public static void log(Logger logger, String message) {
try { try {
//[4/21/17 7:12 PM]
//Bukkit.getServer().getConsoleSender().sendMessage(message);
message = ChatColor.stripColor(message); message = ChatColor.stripColor(message);
Date date = new Date(); logger.info(message);
SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy hh:mm a");
String text = "[" + sdf.format(date) + "] " + message;
logger.append(text + "\n");
logger.flush();
} catch (Exception ex) { } catch (Exception ex) {
Bukkit.getServer().getConsoleSender().sendMessage("Could not log message! Check your log files!"); Bukkit.getServer().getConsoleSender().sendMessage("Could not log message! Check your log files!");
} }
} }
} }

View File

@ -103,6 +103,7 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
public void reloadConfig() { public void reloadConfig() {
super.reloadConfig(); super.reloadConfig();
loadConfig(); loadConfig();
MCMUtil.init();
if (chatListener != null) { if (chatListener != null) {
chatListener.reload(); chatListener.reload();
} }
@ -196,7 +197,7 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
@Override @Override
public void globalLog(Player player, String message) { public void globalLog(Player player, String message) {
MCMUtil.log(MCMUtil.globalLog, player.getName() + " > " + message); MCMUtil.log(MCMUtil.globalLogger, player.getName() + " > " + message);
} }
} }

View File

@ -199,7 +199,7 @@ public class CommandApplication implements CommandExecutor {
@Override @Override
public void invoke(String s) { public void invoke(String s) {
MCMResponse response = new MCMResponse(s); MCMResponse response = new MCMResponse(s);
commandSender.sendMessage(response.getMCMessage()); commandSender.spigot().sendMessage(response.getMCJSON());
} }
} }
@ -236,7 +236,7 @@ public class CommandApplication implements CommandExecutor {
@Override @Override
public void invoke(String s) { public void invoke(String s) {
MCMResponse response = new MCMResponse(s); MCMResponse response = new MCMResponse(s);
commandSender.sendMessage(response.getMCMessage()); commandSender.spigot().sendMessage(response.getMCJSON());
} }
} }

View File

@ -39,7 +39,7 @@ public class CommandTicket implements CommandExecutor {
@Override @Override
public void invoke(String s) { public void invoke(String s) {
MCMResponse response = new MCMResponse(s); MCMResponse response = new MCMResponse(s);
player.sendMessage(response.getMCMessage()); player.spigot().sendMessage(response.getMCJSON());
try { try {
JsonObject extra = (JsonObject) response.getExtra(); JsonObject extra = (JsonObject) response.getExtra();
MinecraftManagerThread.ticket(player.getName(), extra.get("id").getAsString(), extra.get("link").getAsString()); MinecraftManagerThread.ticket(player.getName(), extra.get("id").getAsString(), extra.get("link").getAsString());

View File

@ -34,7 +34,7 @@ public class CommandWarning implements CommandExecutor {
@Override @Override
public void invoke(String s) { public void invoke(String s) {
MCMResponse response = new MCMResponse(s); MCMResponse response = new MCMResponse(s);
player.sendMessage(response.getMCMessage()); player.spigot().sendMessage(response.getMCJSON());
} }
} }

View File

@ -31,7 +31,6 @@ public class AsyncPlayerChatListener implements Listener {
public AsyncPlayerChatListener(MinecraftManager minecraftManager) { public AsyncPlayerChatListener(MinecraftManager minecraftManager) {
this.plugin = minecraftManager; this.plugin = minecraftManager;
reload(); reload();
MCMUtil.init();
} }
public void reload() { public void reload() {
@ -74,7 +73,7 @@ public class AsyncPlayerChatListener implements Listener {
} else { } else {
message.append(chat); message.append(chat);
if (!MinecraftManager.getLogOverride()) { if (!MinecraftManager.getLogOverride()) {
MCMUtil.log(MCMUtil.globalLog, componentText(message.create())); MCMUtil.log(MCMUtil.globalLogger, componentText(message.create()));
} }
} }
} else { } else {
@ -141,6 +140,7 @@ public class AsyncPlayerChatListener implements Listener {
public void invoke(String s) { public void invoke(String s) {
MCMResponse response = new MCMResponse(s); MCMResponse response = new MCMResponse(s);
if (response.getStatus()) { if (response.getStatus()) {
player.sendMessage(ChatColor.GREEN + "Your application has been submitted! Hang tight while it gets reviewed by staff.");
MinecraftManagerThread.application(player.getName(), response.getExtra().getAsString()); MinecraftManagerThread.application(player.getName(), response.getExtra().getAsString());
} else { } else {
player.sendMessage(ChatColor.RED + response.getMessage()); player.sendMessage(ChatColor.RED + response.getMessage());

View File

@ -38,7 +38,7 @@ public class SessionListener implements Listener {
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
MCMUtil.log(MCMUtil.globalLog, player.getName() + " logged in."); MCMUtil.log(MCMUtil.globalLogger, player.getName() + " logged in.");
// Check for guests // Check for guests
if (player.hasPermission("minecraftmanager.guest")) { if (player.hasPermission("minecraftmanager.guest")) {
@ -72,7 +72,7 @@ public class SessionListener implements Listener {
@EventHandler @EventHandler
public void onLogout(PlayerQuitEvent event) { public void onLogout(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
MCMUtil.log(MCMUtil.globalLog, player.getName() + " logged out."); MCMUtil.log(MCMUtil.globalLogger, player.getName() + " logged out.");
} }

View File

@ -0,0 +1,17 @@
# Root logger option
log4j.rootLogger=INFO, mcm.global, mcm.staff
# Redirect log messages to a log file, support file rolling.
log4j.appender.mcm.global=org.apache.log4j.RollingFileAppender
log4j.appender.mcm.global.File=${mcm.log}/global.log
log4j.appender.mcm.global.MaxFileSize=5MB
log4j.appender.mcm.global.MaxBackupIndex=5
log4j.appender.mcm.global.layout=org.apache.log4j.PatternLayout
log4j.appender.mcm.global.layout.ConversionPattern=[%d{M/d/yy hh:mm a}] %m%n
log4j.appender.mcm.staff=org.apache.log4j.RollingFileAppender
log4j.appender.mcm.staff.File=${mcm.log}/staff.log
log4j.appender.mcm.staff.MaxFileSize=5MB
log4j.appender.mcm.staff.MaxBackupIndex=5
log4j.appender.mcm.staff.layout=org.apache.log4j.PatternLayout
log4j.appender.mcm.staff.layout.ConversionPattern=[%d{M/d/yy hh:mm a}] %m%n