parent
4cb519c3fc
commit
cba8c226b6
5
pom.xml
5
pom.xml
|
@ -39,6 +39,11 @@
|
|||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>EtzCore</artifactId>
|
||||
|
|
|
@ -1,46 +1,39 @@
|
|||
package xyz.etztech.minecraftmanager;
|
||||
|
||||
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.log4j.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.etztech.core.web.CoreWeb;
|
||||
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;
|
||||
|
||||
public class MCMUtil {
|
||||
private static FileWriter globalFile;
|
||||
public static PrintWriter globalLog;
|
||||
private static FileWriter staffFile;
|
||||
public static PrintWriter staffLog;
|
||||
public static Logger globalLogger;
|
||||
public static Logger staffLogger;
|
||||
|
||||
|
||||
public static void init() {
|
||||
MinecraftManager plugin = (MinecraftManager) Bukkit.getPluginManager().getPlugin("MinecraftManager");
|
||||
String pluginPath = plugin.getDataFolder().getAbsolutePath();
|
||||
String globalPath = pluginPath + "/logs/global.log";
|
||||
System.setProperty("mcm.log", pluginPath + "/logs");
|
||||
try {
|
||||
globalFile = new FileWriter(globalPath, true);
|
||||
globalLog = new PrintWriter(globalFile);
|
||||
globalLogger = Logger.getLogger("mcm.global");
|
||||
} 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")) {
|
||||
String staffPath = pluginPath + "/logs/staff.log";
|
||||
try {
|
||||
staffFile = new FileWriter(staffPath, true);
|
||||
staffLog = new PrintWriter(staffFile);
|
||||
globalLogger = Logger.getLogger("mcm.staff");
|
||||
} 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);
|
||||
}
|
||||
public static void staffMessage(String message, boolean mcm) {
|
||||
log(staffLog, message);
|
||||
log(staffLogger, message);
|
||||
String tag = mcm ? "MCM " : "";
|
||||
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(tag + "Staff Chat").create());
|
||||
TextComponent text = new TextComponent(message);
|
||||
|
@ -64,7 +57,7 @@ public class MCMUtil {
|
|||
|
||||
@Deprecated
|
||||
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());
|
||||
TextComponent text = new TextComponent(message);
|
||||
text.setHoverEvent(hover);
|
||||
|
@ -80,7 +73,7 @@ public class MCMUtil {
|
|||
}
|
||||
|
||||
public static void staffMessage(TextComponent message) {
|
||||
log(staffLog, message.toPlainText());
|
||||
log(staffLogger, message.toPlainText());
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (player.hasPermission("minecraftmanager.staff")) {
|
||||
player.spigot().sendMessage(message);
|
||||
|
@ -90,14 +83,14 @@ public class MCMUtil {
|
|||
}
|
||||
|
||||
public static void globalMessage(String message) {
|
||||
log(globalLog, message);
|
||||
log(globalLogger, message);
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void globalMessage(TextComponent message) {
|
||||
log(globalLog, message.toPlainText());
|
||||
log(globalLogger, message.toPlainText());
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
player.spigot().sendMessage(message);
|
||||
}
|
||||
|
@ -122,18 +115,13 @@ public class MCMUtil {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
public static void log(PrintWriter logger, String message) {
|
||||
public static void log(Logger logger, String message) {
|
||||
try {
|
||||
//[4/21/17 7:12 PM]
|
||||
//Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
message = ChatColor.stripColor(message);
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy hh:mm a");
|
||||
String text = "[" + sdf.format(date) + "] " + message;
|
||||
logger.append(text + "\n");
|
||||
logger.flush();
|
||||
logger.info(message);
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage("Could not log message! Check your log files!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -103,12 +103,12 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
|||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
loadConfig();
|
||||
MCMUtil.init();
|
||||
if (chatListener != null) {
|
||||
chatListener.reload();
|
||||
}
|
||||
rules = new Rules(config);
|
||||
banOptions = config.getStringList("ban.options");
|
||||
MCMUtil.init();
|
||||
}
|
||||
|
||||
|
||||
|
@ -197,7 +197,7 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
|||
|
||||
@Override
|
||||
public void globalLog(Player player, String message) {
|
||||
MCMUtil.log(MCMUtil.globalLog, player.getName() + " > " + message);
|
||||
MCMUtil.log(MCMUtil.globalLogger, player.getName() + " > " + message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ public class CommandApplication implements CommandExecutor {
|
|||
@Override
|
||||
public void invoke(String 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
|
||||
public void invoke(String s) {
|
||||
MCMResponse response = new MCMResponse(s);
|
||||
commandSender.sendMessage(response.getMCMessage());
|
||||
commandSender.spigot().sendMessage(response.getMCJSON());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class CommandTicket implements CommandExecutor {
|
|||
@Override
|
||||
public void invoke(String s) {
|
||||
MCMResponse response = new MCMResponse(s);
|
||||
player.sendMessage(response.getMCMessage());
|
||||
player.spigot().sendMessage(response.getMCJSON());
|
||||
try {
|
||||
JsonObject extra = (JsonObject) response.getExtra();
|
||||
MinecraftManagerThread.ticket(player.getName(), extra.get("id").getAsString(), extra.get("link").getAsString());
|
||||
|
|
|
@ -34,7 +34,7 @@ public class CommandWarning implements CommandExecutor {
|
|||
@Override
|
||||
public void invoke(String s) {
|
||||
MCMResponse response = new MCMResponse(s);
|
||||
player.sendMessage(response.getMCMessage());
|
||||
player.spigot().sendMessage(response.getMCJSON());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ public class AsyncPlayerChatListener implements Listener {
|
|||
public AsyncPlayerChatListener(MinecraftManager minecraftManager) {
|
||||
this.plugin = minecraftManager;
|
||||
reload();
|
||||
MCMUtil.init();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
|
@ -74,7 +73,7 @@ public class AsyncPlayerChatListener implements Listener {
|
|||
} else {
|
||||
message.append(chat);
|
||||
if (!MinecraftManager.getLogOverride()) {
|
||||
MCMUtil.log(MCMUtil.globalLog, componentText(message.create()));
|
||||
MCMUtil.log(MCMUtil.globalLogger, componentText(message.create()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class SessionListener implements Listener {
|
|||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
MCMUtil.log(MCMUtil.globalLog, player.getName() + " logged in.");
|
||||
MCMUtil.log(MCMUtil.globalLogger, player.getName() + " logged in.");
|
||||
|
||||
// Check for guests
|
||||
if (player.hasPermission("minecraftmanager.guest")) {
|
||||
|
@ -72,7 +72,7 @@ public class SessionListener implements Listener {
|
|||
@EventHandler
|
||||
public void onLogout(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
MCMUtil.log(MCMUtil.globalLog, player.getName() + " logged out.");
|
||||
MCMUtil.log(MCMUtil.globalLogger, player.getName() + " logged out.");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue