Skip to content

Commit

Permalink
Add a blacklist to prevent player from being logged
Browse files Browse the repository at this point in the history
  • Loading branch information
leelawd committed Nov 21, 2016
1 parent 5bb1b85 commit 9e6f4d5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/moddedminecraft/mmclogger/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Config {
Expand Down Expand Up @@ -47,6 +48,7 @@ public class Config {
public boolean playerLogin;
public boolean globalLogin;
public String logFormat;
public List<String> playerBlacklist;

private static ConfigurationLoader<CommentedConfigurationNode> loader;
private static CommentedConfigurationNode config;
Expand All @@ -68,6 +70,7 @@ public void configCheck() throws IOException, ObjectMappingException {
BlackList = checkList(config.getNode("log", "command-log", "blacklist"), BlackListString, "what commands do you not want to be logged in any file?").getList(TypeToken.of(String.class));
commandNotifyList = checkList(config.getNode("log", "notifications", "commands"), commandNotifyListString, "what commands do you want to be notified of when they are sent?").getList(TypeToken.of(String.class));
chatNotifyList = checkList(config.getNode("log", "notifications", "chat"), chatNotifyListString, "What words do you want to be notified of when they are said?").getList(TypeToken.of(String.class));
playerBlacklist = check(config.getNode("log", "player", "blacklist"), Collections.EMPTY_LIST, "What players do you not want to be logged?").getList(TypeToken.of(String.class));

globalCommands = check(config.getNode("log", "toggle", "global-commands"), true, "Log all command interactions to the main command files").getBoolean();
globalChat = check(config.getNode("log", "toggle", "global-chat"), true, "Log all chat interactions to the main chat files").getBoolean();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.moddedminecraft.mmclogger;

import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.command.SendCommandEvent;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void onPlayerCommand(SendCommandEvent event, @Root Player player) throws
}

@Listener
public void onPlayerLogin(ClientConnectionEvent.Join event, @Root Player player) throws IOException {
public void onPlayerLogin(ClientConnectionEvent.Join event, @Root Player player) throws IOException, ObjectMappingException {
String name = player.getName();
Location<World> location = player.getLocation();
int xLocation = location.getBlockX();
Expand All @@ -69,7 +70,7 @@ public void onPlayerLogin(ClientConnectionEvent.Join event, @Root Player player)
}

@Listener
public void onPlayerDisconnect(ClientConnectionEvent.Disconnect event, @Root Player player) throws IOException {
public void onPlayerDisconnect(ClientConnectionEvent.Disconnect event, @Root Player player) throws IOException, ObjectMappingException {
String name = player.getName();
Location<World> location = player.getLocation();
int xLocation = location.getBlockX();
Expand Down
40 changes: 26 additions & 14 deletions src/main/java/net/moddedminecraft/mmclogger/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ void processInformation(Player player, String playerName, String chat, int x, in
String message = chat.replaceAll("(&([a-f0-9]))", "");

try {
if (globalChat) {
if (globalChat && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(formatLog(playerName, message, x, y, z, worldName, date), getChatFile())).async().name("mmclogger-A-GlobalChatLog").submit(this);
}
if (playerChat) {
if (playerChat && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(formatLog(playerName, message, x, y, z, worldName, date), playerFile)).async().name("mmclogger-A-PlayerChatLog").submit(this);
}
if ((checkNotifyListPlayer(message)) && (logNotifyChat)) {
if ((checkNotifyListPlayer(message)) && (logNotifyChat) && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(formatLog(playerName, message, x, y, z, worldName, date), notifyChatFile)).async().name("mmclogger-A-NotifyChatLog").submit(this);
}
if ((checkNotifyListPlayer(message)) && (inGameNotifications)) {
if ((checkNotifyListPlayer(message)) && (inGameNotifications) && (!playerCheck(playerName))) {
notifyPlayer(prefix + playerName + "&f: " + message);
}
} catch (ObjectMappingException | IOException e) {
Expand All @@ -114,51 +114,51 @@ void processCMDInformation(Player player, String playerName, String command, Str
String commandLine = "/" +command + " " + args;

try {
if ((globalCommand) && (!commandCheck(command))) {
if ((globalCommand) && (!commandCheck(command)) && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(formatLog(playerName, commandLine, x, y, z, worldName, date), getCmdFile())).async().name("mmclogger-A-GlobalCommandLog").submit(this);
}
if ((playerCommand) && (!commandCheck(command))) {
if ((playerCommand) && (!commandCheck(command)) && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(formatLog(playerName, commandLine, x, y, z, worldName, date), playerFile)).async().name("mmclogger-A-PlayerCommandLog").submit(this);
}
if ((checkNotifyListCMD(command)) && (logNotifyCommands)) {
if ((checkNotifyListCMD(command)) && (logNotifyCommands) && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(formatLog(playerName, commandLine, x, y, z, worldName, date), notifyCommandFile)).async().name("mmclogger-A-NotifyCommandLog").submit(this);
}
if ((checkNotifyListCMD(command)) && (inGameNotifications)) {
if ((checkNotifyListCMD(command)) && (inGameNotifications) && (!playerCheck(playerName))) {
notifyPlayer(prefix + playerName + "&f: " + commandLine);
}
} catch (ObjectMappingException | IOException e) {
e.printStackTrace();
}
}

public void processInformationJoin(String playerName, int x, int y, int z, String worldName, String date) throws IOException {
public void processInformationJoin(String playerName, int x, int y, int z, String worldName, String date) throws IOException, ObjectMappingException {
boolean globalLogin = config().globalLogin;
boolean playerLogin = config().playerLogin;

File playerFile = new File(playersFolder, playerName + ".log");
String log = "logged in.";
String[] content = formatLog(playerName, log, x, y, z, worldName, date);

if (globalLogin) {
if (globalLogin && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(content, getChatFile())).async().name("mmclogger-A-globalLogin").submit(this);
}
if (playerLogin) {
if (playerLogin && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(content, playerFile)).async().name("mmclogger-A-playerLogin").submit(this);
}
}

public void processInformationQuit(String playerName, int x, int y, int z, String worldName, String date) throws IOException {
public void processInformationQuit(String playerName, int x, int y, int z, String worldName, String date) throws IOException, ObjectMappingException {
boolean globalLogin = config().globalLogin;
boolean playerLogin = config().playerLogin;

File playerFile = new File(playersFolder, playerName + ".log");
String log = "logged out.";
String[] content = formatLog(playerName, log, x, y, z, worldName, date);

if (globalLogin) {
if (globalLogin && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(content, getChatFile())).async().name("mmclogger-A-globalLogin").submit(this);
}
if (playerLogin) {
if (playerLogin && (!playerCheck(playerName))) {
scheduler.createTaskBuilder().execute(new WriteFile(content, playerFile)).async().name("mmclogger-A-playerLogin").submit(this);
}
}
Expand All @@ -175,6 +175,18 @@ private boolean commandCheck(String blacklist) throws ObjectMappingException {
return false;
}

private boolean playerCheck(String blacklist) throws ObjectMappingException {
List<String> blacklists = config().playerBlacklist;
String[] blacklistsplit = blacklist.split(" ");
String blacklistconvert = blacklistsplit[0];
for (String blacklist1 : blacklists) {
if (blacklistconvert.matches(blacklist1)) {
return true;
}
}
return false;
}

private String[] formatLog(String playerName, String command, int x, int y, int z, String worldName, String date) throws IOException {
String log = config().logFormat;
if (log.contains("%date")) {
Expand Down

0 comments on commit 9e6f4d5

Please sign in to comment.