-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
906 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="lib" path="E:/Workspace/craftbukkit-1.7.10-R0.1-20140808.005431-8.jar"/> | ||
<classpathentry kind="lib" path="E:/Workspace/MineverseChat (2).jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>MMCLogger</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package net.moddedminecraft.mmclogger; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
import org.bukkit.scheduler.BukkitTask; | ||
|
||
import mineverse.Aust1n46.chat.*; | ||
import mineverse.Aust1n46.chat.alias.*; | ||
|
||
public class ChatLogger implements org.bukkit.event.Listener | ||
{ | ||
private MMCLogger plugin; | ||
|
||
|
||
public ChatLogger(MMCLogger plugins) | ||
{ | ||
this.plugin = plugins; | ||
plugins.getServer().getPluginManager().registerEvents(this, plugins); | ||
} | ||
|
||
@org.bukkit.event.EventHandler(priority=EventPriority.LOWEST) | ||
public void onPlayerChat(AsyncPlayerChatEvent event) throws IOException | ||
{ | ||
Player player = event.getPlayer(); | ||
String name = player.getName(); | ||
String message = event.getMessage(); | ||
Location location = player.getLocation(); | ||
int xLocation = (int)location.getX(); | ||
int yLocation = (int)location.getY(); | ||
int zLocation = (int)location.getZ(); | ||
World world = location.getWorld(); | ||
String ipAddress = player.getAddress().getAddress().getHostAddress(); | ||
String worldName = world.getName(); | ||
String date = getDate(); | ||
checkPlayer(name); | ||
|
||
processInformation(player, name, message, xLocation, yLocation, zLocation, worldName, date, ipAddress); | ||
} | ||
|
||
public void processInformation(Player player, String playerName, String content, int x, int y, int z, String worldName, String date, String ipAddress) { | ||
boolean globalChat = this.plugin.getConfig().getBoolean("Log.toggle.globalChat"); | ||
boolean playerChat = this.plugin.getConfig().getBoolean("Log.toggle.playerChat"); | ||
boolean logNotifyChat = this.plugin.getConfig().getBoolean("Log.toggle.logNotifyChat"); | ||
boolean inGameNotifications = this.plugin.getConfig().getBoolean("Log.toggle.inGameNotifications"); | ||
|
||
File playerFile = new File(plugin.playersFolder, playerName + ".log"); | ||
|
||
BukkitTask task; | ||
if (globalChat) | ||
task = new WriteFile(formatLog(playerName, content, x, y, z, worldName, date, ipAddress), plugin.getChatFile()).runTaskAsynchronously(this.plugin); | ||
if (playerChat) | ||
task = new WriteFile(formatLog(playerName, content, x, y, z, worldName, date, ipAddress), playerFile).runTaskAsynchronously(this.plugin); | ||
if ((checkNotifyList(content)) && (logNotifyChat)) { | ||
task = new WriteFile(formatLog(playerName, content, x, y, z, worldName, date, ipAddress), plugin.notifyChatFile).runTaskAsynchronously(this.plugin); | ||
} | ||
if ((checkNotifyList(content)) && (inGameNotifications)) { | ||
this.plugin.chatNotifier.notifyPlayer(ChatColor.BLUE + "[" + ChatColor.GOLD + "MMCLogger" + ChatColor.BLUE + "] " + ChatColor.GOLD + playerName + ": " + ChatColor.WHITE + content); | ||
} | ||
} | ||
|
||
public String checkApos(String content) { | ||
String fixed = content.replaceAll("'", "''"); | ||
return fixed; | ||
} | ||
|
||
public void checkPlayer(String name) throws IOException | ||
{ | ||
File file = new File(plugin.playersFolder, name + ".log"); | ||
if (!file.exists()) { | ||
file.createNewFile(); | ||
} | ||
} | ||
|
||
public String[] formatLog(String playerName, String command, int x, int y, int z, String worldName, String date, String ipAddress) { | ||
String format = this.plugin.getConfig().getString("Log.logFormat"); | ||
String log = format; | ||
if (log.contains("%ip")) { | ||
log = log.replaceAll("%ip", ipAddress); | ||
} | ||
if (log.contains("%date")) { | ||
log = log.replaceAll("%date", date); | ||
} | ||
if (log.contains("%world")) { | ||
log = log.replaceAll("%world", worldName); | ||
} | ||
if (log.contains("%x")) { | ||
log = log.replaceAll("%x", Integer.toString(x)); | ||
} | ||
if (log.contains("%y")) { | ||
log = log.replaceAll("%y", Integer.toString(y)); | ||
} | ||
if (log.contains("%z")) { | ||
log = log.replaceAll("%z", Integer.toString(z)); | ||
} | ||
if (log.contains("%name")) { | ||
log = log.replaceAll("%name", playerName); | ||
} | ||
if (log.contains("%content")) { | ||
log = log.replaceAll("%content", java.util.regex.Matcher.quoteReplacement(command)); | ||
} | ||
|
||
String[] logArray = { log }; | ||
return logArray; | ||
} | ||
|
||
public String getDate() { | ||
DateFormat dateFormat = new SimpleDateFormat("MMM/dd/yyyy hh:mm:ss a"); | ||
Date date = new Date(); | ||
return dateFormat.format(date); | ||
} | ||
|
||
public static String getFileDate() { | ||
DateFormat dateFormat = new SimpleDateFormat("MMM-dd-yyyy"); | ||
Date date = new Date(); | ||
return dateFormat.format(date); | ||
} | ||
|
||
public boolean checkNotifyList(String message) { | ||
List messageList = this.plugin.getConfig().getStringList("Log.notifications.chat"); | ||
for (int i = 0; i < messageList.size(); i++) { | ||
if (message.toLowerCase().contains((CharSequence)messageList.get(i))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package net.moddedminecraft.mmclogger; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.text.DateFormat; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Location; | ||
import org.bukkit.Server; | ||
import org.bukkit.World; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.player.PlayerCommandPreprocessEvent; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.scheduler.BukkitTask; | ||
|
||
public class CommandLogger implements org.bukkit.event.Listener | ||
{ | ||
private MMCLogger plugin; | ||
private Notifier notifier; | ||
|
||
public CommandLogger(MMCLogger plugins) | ||
{ | ||
this.plugin = plugins; | ||
plugins.getServer().getPluginManager().registerEvents(this, plugins); | ||
} | ||
|
||
@org.bukkit.event.EventHandler(priority=EventPriority.LOWEST) | ||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws IOException { | ||
Player player = event.getPlayer(); | ||
|
||
String name = player.getName(); | ||
|
||
String command = event.getMessage(); | ||
|
||
Location location = player.getLocation(); | ||
|
||
int xLocation = (int)location.getX(); | ||
|
||
int yLocation = (int)location.getY(); | ||
|
||
int zLocation = (int)location.getZ(); | ||
|
||
World world = location.getWorld(); | ||
|
||
String ipAddress = player.getAddress().getAddress().getHostAddress(); | ||
|
||
String worldName = world.getName(); | ||
|
||
String date = getDate(); | ||
|
||
checkPlayer(name); | ||
|
||
processInformation(player, name, command, xLocation, yLocation, zLocation, worldName, date, ipAddress); | ||
} | ||
|
||
public void processInformation(Player player, String playerName, String command, int x, int y, int z, String worldName, String date, String ipAddress) { | ||
boolean data = this.plugin.getConfig().getBoolean("Database.useDatabase"); | ||
boolean playerCommand = this.plugin.getConfig().getBoolean("Log.toggle.playerCommands"); | ||
boolean globalCommand = this.plugin.getConfig().getBoolean("Log.toggle.globalCommands"); | ||
boolean logNotifyCommands = this.plugin.getConfig().getBoolean("Log.toggle.logNotifyCommands"); | ||
boolean inGameNotifications = this.plugin.getConfig().getBoolean("Log.toggle.inGameNotifications"); | ||
|
||
File playerFile = new File(plugin.playersFolder, playerName + ".log"); | ||
|
||
|
||
|
||
BukkitTask task; | ||
if ((globalCommand) && (!commandCheck(command))) | ||
{ | ||
task = new WriteFile(formatLog(playerName, command, x, y, z, worldName, date, ipAddress), plugin.getCmdFile()).runTaskAsynchronously(this.plugin); | ||
} | ||
if ((playerCommand) && (!commandCheck(command))) | ||
{ | ||
task = new WriteFile(formatLog(playerName, command, x, y, z, worldName, date, ipAddress), playerFile).runTaskAsynchronously(this.plugin); | ||
} | ||
if ((checkNotifyList(command)) && (logNotifyCommands)) { | ||
task = new WriteFile(formatLog(playerName, command, x, y, z, worldName, date, ipAddress), plugin.notifyCommandFile).runTaskAsynchronously(this.plugin); | ||
} | ||
if ((checkNotifyList(command)) && (inGameNotifications)) { | ||
this.plugin.chatNotifier.notifyPlayer(ChatColor.BLUE + "[" + ChatColor.GOLD + "MMCLogger" + ChatColor.BLUE + "] " + ChatColor.GOLD + playerName + ": " + ChatColor.WHITE + command); | ||
} | ||
} | ||
|
||
public String checkApos(String command) { | ||
String fixed = command.replaceAll("'", "''"); | ||
return fixed; | ||
} | ||
|
||
public String[] formatLog(String playerName, String command, int x, int y, int z, String worldName, String date, String ipAddress) { | ||
String format = this.plugin.getConfig().getString("Log.logFormat"); | ||
String log = format; | ||
if (log.contains("%ip")) { | ||
log = log.replaceAll("%ip", ipAddress); | ||
} | ||
if (log.contains("%date")) { | ||
log = log.replaceAll("%date", date); | ||
} | ||
if (log.contains("%world")) { | ||
log = log.replaceAll("%world", worldName); | ||
} | ||
if (log.contains("%x")) { | ||
log = log.replaceAll("%x", Integer.toString(x)); | ||
} | ||
if (log.contains("%y")) { | ||
log = log.replaceAll("%y", Integer.toString(y)); | ||
} | ||
if (log.contains("%z")) { | ||
log = log.replaceAll("%z", Integer.toString(z)); | ||
} | ||
if (log.contains("%name")) { | ||
log = log.replaceAll("%name", playerName); | ||
} | ||
if (log.contains("%content")) { | ||
log = log.replaceAll("%content", Matcher.quoteReplacement(command)); | ||
} | ||
|
||
String[] logArray = { log }; | ||
return logArray; | ||
} | ||
|
||
public boolean commandCheck(String command) { | ||
List commands = this.plugin.getConfig().getStringList("Log.commands.blacklist"); | ||
String[] commandsplit = command.split(" "); | ||
String commandconvert = commandsplit[0]; | ||
for (int i = 0; i < commands.size(); i++) { | ||
if (commandconvert.matches((String)commands.get(i))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean checkNotifyList(String command) { | ||
List commands = this.plugin.getConfig().getStringList("Log.notifications.commands"); | ||
String[] commandsplit = command.split(" "); | ||
String commandconvert = commandsplit[0]; | ||
for (int i = 0; i < commands.size(); i++) { | ||
if (commandconvert.matches((String)commands.get(i))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public void checkPlayer(String name) throws IOException { | ||
File file = new File(plugin.playersFolder, name + ".log"); | ||
if (!file.exists()) { | ||
file.createNewFile(); | ||
} | ||
} | ||
|
||
public String getDate() { | ||
DateFormat dateFormat = new java.text.SimpleDateFormat("MMM/dd/yyyy hh:mm:ss a"); | ||
Date date = new Date(); | ||
return dateFormat.format(date); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.moddedminecraft.mmclogger; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
public class CreateFile extends BukkitRunnable | ||
{ | ||
public File file; | ||
|
||
CreateFile(File f) | ||
{ | ||
this.file = f; | ||
} | ||
|
||
public void run() { | ||
BufferedWriter buffwriter = null; | ||
FileWriter filewriter = null; | ||
try { | ||
this.file.createNewFile(); | ||
filewriter = new FileWriter(this.file, true); | ||
buffwriter = new BufferedWriter(filewriter); | ||
buffwriter.flush(); return; | ||
} | ||
catch (IOException e) {}finally { | ||
try { | ||
if (buffwriter != null) { | ||
buffwriter.close(); | ||
} | ||
if (filewriter != null) { | ||
filewriter.close(); | ||
} | ||
} | ||
catch (IOException e) {} | ||
} | ||
} | ||
} |
Oops, something went wrong.