diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index bccf4757..58ca6f84 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -4,10 +4,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.logging.Logger; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakCheckListener; @@ -19,12 +24,12 @@ import cc.co.evenprime.bukkit.nocheat.checks.moving.MovingCheckListener; import cc.co.evenprime.bukkit.nocheat.command.CommandHandler; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationManager; +import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.PlayerManager; import cc.co.evenprime.bukkit.nocheat.debug.ActiveCheckPrinter; import cc.co.evenprime.bukkit.nocheat.debug.LagMeasureTask; import cc.co.evenprime.bukkit.nocheat.events.WorkaroundsEventManager; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; -import cc.co.evenprime.bukkit.nocheat.log.LogManager; +import cc.co.evenprime.bukkit.nocheat.log.NoCheatLogEvent; /** * @@ -33,17 +38,15 @@ import cc.co.evenprime.bukkit.nocheat.log.LogManager; * Check various player events for their plausibility and log/deny them/react to * them based on configuration */ -public class NoCheat extends JavaPlugin { +public class NoCheat extends JavaPlugin implements Listener { - private ConfigurationManager conf; - private LogManager log; - private PlayerManager players; + private ConfigurationManager conf; + private PlayerManager players; - private List eventManagers; + private List eventManagers; - private LagMeasureTask lagMeasureTask; - - private int taskId = -1; + private LagMeasureTask lagMeasureTask; + private Logger fileLogger; public NoCheat() { @@ -53,11 +56,6 @@ public class NoCheat extends JavaPlugin { PluginDescriptionFile pdfFile = this.getDescription(); - if(taskId != -1) { - getServer().getScheduler().cancelTask(taskId); - taskId = -1; - } - if(lagMeasureTask != null) { lagMeasureTask.cancel(); lagMeasureTask = null; @@ -71,19 +69,16 @@ public class NoCheat extends JavaPlugin { // Just to be sure nothing gets left out getServer().getScheduler().cancelTasks(this); - log.logToConsole(LogLevel.LOW, "[NoCheat] version [" + pdfFile.getVersion() + "] is disabled."); + System.out.println("[NoCheat] version [" + pdfFile.getVersion() + "] is disabled."); } public void onEnable() { - // First set up logging - this.log = new LogManager(); - // Then set up in memory per player data storage this.players = new PlayerManager(this); // Then read the configuration files - this.conf = new ConfigurationManager(this.getDataFolder()); + this.conf = new ConfigurationManager(this, this.getDataFolder()); eventManagers = new ArrayList(8); // Big enough // Then set up the event listeners @@ -104,8 +99,15 @@ public class NoCheat extends JavaPlugin { // Then print a list of active checks per world ActiveCheckPrinter.printActiveChecks(this, eventManagers); + // register all listeners + for(EventManager eventManager : eventManagers) { + Bukkit.getPluginManager().registerEvents(eventManager, this); + } + + Bukkit.getPluginManager().registerEvents(this, this); + // Tell the server admin that we finished loading NoCheat now - log.logToConsole(LogLevel.LOW, "[NoCheat] version [" + this.getDescription().getVersion() + "] is enabled."); + System.out.println("[NoCheat] version [" + this.getDescription().getVersion() + "] is enabled."); } public ConfigurationCacheStore getConfig(Player player) { @@ -122,10 +124,6 @@ public class NoCheat extends JavaPlugin { return conf.getConfigurationCacheForWorld(null); } - public void log(LogLevel level, String message, ConfigurationCacheStore cc) { - log.log(level, message, cc); - } - public void clearCriticalData(String playerName) { players.clearCriticalData(playerName); } @@ -155,15 +153,9 @@ public class NoCheat extends JavaPlugin { return 1000L; } - public void logToConsole(LogLevel low, String message) { - if(log != null) { - log.logToConsole(low, message); - } - } - public void reloadConfiguration() { conf.cleanup(); - this.conf = new ConfigurationManager(this.getDataFolder()); + this.conf = new ConfigurationManager(this, this.getDataFolder()); players.cleanDataMap(); players.clearCriticalData(); } @@ -201,4 +193,26 @@ public class NoCheat extends JavaPlugin { public NoCheatPlayer getPlayer(Player player) { return players.getPlayer(player); } + + @EventHandler(priority = EventPriority.MONITOR) + public void logEvent(NoCheatLogEvent event) { + if(event.toConsole()) { + System.out.println(event.getPrefix() + event.getMessage()); + } + if(event.toChat()) { + for(Player player : Bukkit.getServer().getOnlinePlayers()) { + if(player.hasPermission(Permissions.ADMIN_CHATLOG)) { + player.sendMessage(event.getPrefix() + event.getMessage()); + } + } + } + if(event.toFile()) { + fileLogger.info(event.getMessage()); + System.out.println("fileend"); + } + } + + public void setFileLogger(Logger logger) { + this.fileLogger = logger; + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java index fe6a0903..e34fefe3 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java @@ -1,9 +1,9 @@ package cc.co.evenprime.bukkit.nocheat; import org.bukkit.entity.Player; - import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.DataStore; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public interface NoCheatPlayer { @@ -28,4 +28,6 @@ public interface NoCheatPlayer { public boolean isCreative(); public void closeInventory(); + + public ExecutionHistory getExecutionHistory(); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/Action.java b/src/cc/co/evenprime/bukkit/nocheat/actions/Action.java index 7e17a95d..8694fcd7 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/Action.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/Action.java @@ -29,4 +29,17 @@ public abstract class Action { this.delay = delay; this.repeat = repeat; } + + /** + * Make a copy of the action, with some modifications + * @param string + * @return + */ + public Action cloneWithProperties(String string) { + return this; + } + + public String getProperties() { + return null; + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionWithParameters.java b/src/cc/co/evenprime/bukkit/nocheat/actions/ActionWithParameters.java index 7b3ff5d4..88209a16 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionWithParameters.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/ActionWithParameters.java @@ -1,7 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.actions; import java.util.ArrayList; - import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.checks.Check; diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/types/ConsolecommandAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/types/ConsolecommandAction.java index a6790bca..3cf46a90 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/types/ConsolecommandAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/types/ConsolecommandAction.java @@ -13,11 +13,9 @@ public class ConsolecommandAction extends ActionWithParameters { public ConsolecommandAction(String name, int delay, int repeat, String command) { super(name, delay, repeat, command); - } public String getCommand(NoCheatPlayer player, Check check) { - return super.getMessage(player, check); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java index 35c10ab5..e58254db 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java @@ -12,5 +12,4 @@ public class DummyAction extends Action { public DummyAction(String name, int delay, int repeat) { super(name, delay, repeat); } - } diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java index 8d97c811..c43f7e39 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java @@ -1,10 +1,10 @@ package cc.co.evenprime.bukkit.nocheat.actions.types; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; +import cc.co.evenprime.bukkit.nocheat.actions.Action; import cc.co.evenprime.bukkit.nocheat.actions.ActionWithParameters; import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.log.Colors; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** * Print a message to various locations @@ -12,16 +12,57 @@ import cc.co.evenprime.bukkit.nocheat.log.LogLevel; */ public class LogAction extends ActionWithParameters { - public final LogLevel level; + private boolean toChat = true; + private boolean toConsole = true; + private boolean toFile = true; + private String message; - public LogAction(String name, int delay, int repeat, LogLevel level, String message) { + public LogAction(String name, int delay, int repeat, String message) { // Log messages may have color codes now super(name, delay, repeat, Colors.replaceColors(message)); + this.message = message; - this.level = level; + } + + private LogAction(String name, int delay, int repeat, boolean toChat, boolean toConsole, boolean toFile, String message) { + // Log messages may have color codes now + super(name, delay, repeat, Colors.replaceColors(message)); + this.toChat = toChat; + this.toConsole = toConsole; + this.toFile = toFile; } public String getLogMessage(NoCheatPlayer player, Check check) { return super.getMessage(player, check); } + + public boolean toChat() { + return toChat; + } + + public boolean toConsole() { + return toConsole; + } + + public boolean toFile() { + return toFile; + } + + @Override + public Action cloneWithProperties(String properties) { + boolean toChat = properties.toLowerCase().contains("ch"); + boolean toFile = properties.toLowerCase().contains("fi"); + boolean toConsole = properties.toLowerCase().contains("co"); + return new LogAction(name, delay, repeat, toChat, toConsole, toFile, message); + } + + @Override + public String getProperties() { + String props = (toChat ? "ch," : "") + (toFile ? "fi," : "") + (toConsole ? "co," : ""); + if(props.length() > 0) { + return props.substring(0, props.length() - 1); + } else { + return ""; + } + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java index 98d58c61..c7ea31ab 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java @@ -1,6 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.checks; import java.util.Locale; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; @@ -14,18 +15,20 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction; import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction; import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; +import cc.co.evenprime.bukkit.nocheat.log.NoCheatLogEvent; public abstract class Check { - private final String name; - private final String permission; + private final String name; + private final String groupId; // used to bundle information of multiple checks + private final String permission; private static final CommandSender noCheatCommandSender = new NoCheatCommandSender(); - protected final NoCheat plugin; + protected final NoCheat plugin; - public Check(NoCheat plugin, String name, String permission) { + public Check(NoCheat plugin, String groupId, String name, String permission) { this.plugin = plugin; + this.groupId = groupId; this.name = name; this.permission = permission; } @@ -47,7 +50,7 @@ public abstract class Check { final ConfigurationCacheStore cc = player.getConfigurationStore(); for(Action ac : actions) { - if(getHistory(player).executeAction(ac, time)) { + if(player.getExecutionHistory().executeAction(groupId, ac, time)) { if(ac instanceof LogAction) { executeLogAction((LogAction) ac, this, player, cc); } else if(ac instanceof SpecialAction) { @@ -63,10 +66,12 @@ public abstract class Check { return special; } - protected abstract ExecutionHistory getHistory(NoCheatPlayer player); - private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCacheStore cc) { - plugin.log(l.level, cc.logging.prefix + l.getLogMessage(player, check), cc); + + if(!cc.logging.active) + return; + + Bukkit.getServer().getPluginManager().callEvent(new NoCheatLogEvent(cc.logging.prefix, l.getLogMessage(player, check), cc.logging.toConsole && l.toConsole(), cc.logging.toChat && l.toChat(), cc.logging.toFile && l.toFile())); } private final void executeConsoleCommand(ConsolecommandAction action, Check check, NoCheatPlayer player, ConfigurationCacheStore cc) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java index df474e3f..5fd0765a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java @@ -5,25 +5,19 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.DataStore; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public abstract class BlockBreakCheck extends Check { private static final String id = "blockbreak"; public BlockBreakCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); + super(plugin, id, name, permission); } public abstract boolean check(NoCheatPlayer player, BlockBreakData data, CCBlockBreak cc); public abstract boolean isEnabled(CCBlockBreak cc); - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return getData(player.getDataStore()).history; - } - public static BlockBreakData getData(DataStore base) { BlockBreakData data = base.get(id); if(data == null) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheckListener.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheckListener.java index 06df3181..1b9969a2 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheckListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheckListener.java @@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -36,8 +35,6 @@ public class BlockBreakCheckListener implements Listener, EventManager { this.checks.add(new DirectionCheck(plugin)); this.plugin = plugin; - - Bukkit.getPluginManager().registerEvents(this, plugin); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java index 3b7f125e..10e20ecb 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java @@ -1,9 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.DataItem; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; /** @@ -26,8 +24,6 @@ public class BlockBreakData implements DataItem { public final SimpleLocation instaBrokenBlockLocation = new SimpleLocation(); public final SimpleLocation brokenBlockLocation = new SimpleLocation(); - public final ExecutionHistory history = new ExecutionHistory(); - public double reachDistance; public boolean armswung = true; public final SimpleLocation lastDamagedBlock = new SimpleLocation(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java index 45fe7a10..3a22e649 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java @@ -1,14 +1,12 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockplace; import java.util.Locale; - import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.DataStore; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; /** @@ -19,18 +17,13 @@ public abstract class BlockPlaceCheck extends Check { private static final String id = "blockplace"; public BlockPlaceCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); + super(plugin, id, name, permission); } public abstract boolean check(NoCheatPlayer player, BlockPlaceData data, CCBlockPlace cc); public abstract boolean isEnabled(CCBlockPlace cc); - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return getData(player.getDataStore()).history; - } - @Override public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.PLACE_LOCATION) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheckListener.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheckListener.java index 4cc90eba..c00832eb 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheckListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheckListener.java @@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockplace; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -31,8 +30,6 @@ public class BlockPlaceCheckListener implements Listener, EventManager { this.checks = new ArrayList(2); this.checks.add(new ReachCheck(plugin)); this.checks.add(new DirectionCheck(plugin)); - - Bukkit.getPluginManager().registerEvents(this, plugin); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java index fb57e5cb..83f91591 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java @@ -1,9 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockplace; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.DataItem; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; /** @@ -18,7 +16,6 @@ public class BlockPlaceData implements DataItem { public double directionTotalVL = 0.0D; public int directionFailed = 0; - public final ExecutionHistory history = new ExecutionHistory(); public long directionLastViolationTime = 0; public final SimpleLocation blockPlacedAgainst = new SimpleLocation(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java index e4c07650..311d3373 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java @@ -14,8 +14,6 @@ public class CCChat implements ConfigItem { public final int spamTimeframe; public final int spamLimit; public final ActionList spamActions; - public final boolean emptyCheck; - public final ActionList emptyActions; public final boolean colorCheck; public final ActionList colorActions; @@ -27,8 +25,6 @@ public class CCChat implements ConfigItem { spamTimeframe = data.getInteger(Configuration.CHAT_SPAM_TIMEFRAME); spamLimit = data.getInteger(Configuration.CHAT_SPAM_LIMIT); spamActions = data.getActionList(Configuration.CHAT_SPAM_ACTIONS); - emptyCheck = data.getBoolean(Configuration.CHAT_EMPTY_CHECK); - emptyActions = data.getActionList(Configuration.CHAT_EMPTY_ACTIONS); colorCheck = data.getBoolean(Configuration.CHAT_COLOR_CHECK); colorActions = data.getActionList(Configuration.CHAT_COLOR_ACTIONS); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java index ea5fca37..50a04a9a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java @@ -5,27 +5,20 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; -import cc.co.evenprime.bukkit.nocheat.data.ChatData; import cc.co.evenprime.bukkit.nocheat.data.DataStore; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public abstract class ChatCheck extends Check { private static final String id = "chat"; public ChatCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); + super(plugin, id, name, permission); } public abstract boolean check(NoCheatPlayer player, ChatData data, CCChat cc); public abstract boolean isEnabled(CCChat cc); - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return getData(player.getDataStore()).history; - } - @Override public String getParameter(ParameterName wildcard, NoCheatPlayer player) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheckListener.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheckListener.java index 94152b9a..b3c1cbac 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheckListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheckListener.java @@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.chat; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -14,7 +13,6 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.data.ChatData; public class ChatCheckListener implements Listener, EventManager { @@ -24,13 +22,10 @@ public class ChatCheckListener implements Listener, EventManager { public ChatCheckListener(NoCheat plugin) { this.checks = new ArrayList(3); - this.checks.add(new EmptyCheck(plugin)); this.checks.add(new SpamCheck(plugin)); this.checks.add(new ColorCheck(plugin)); this.plugin = plugin; - - Bukkit.getPluginManager().registerEvents(this, plugin); } @EventHandler(priority = EventPriority.LOWEST) @@ -78,8 +73,8 @@ public class ChatCheckListener implements Listener, EventManager { CCChat c = ChatCheck.getConfig(cc); if(c.check && c.spamCheck) s.add("chat.spam"); - if(c.check && c.emptyCheck) - s.add("chat.empty"); + if(c.check && c.colorCheck) + s.add("chat.color"); return s; } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatData.java similarity index 69% rename from src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatData.java index 2d7a10a4..d03688e5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatData.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.data; +package cc.co.evenprime.bukkit.nocheat.checks.chat; import java.util.Map; import cc.co.evenprime.bukkit.nocheat.DataItem; @@ -11,25 +11,19 @@ public class ChatData implements DataItem { public int spamVL; public int spamTotalVL; public int spamFailed; - public int emptyVL; - public int emptyTotalVL; - public int emptyFailed; public int colorVL; public int colorTotalVL; public int colorFailed; public int messageCount = 0; public long spamLastTime = 0; - public final ExecutionHistory history = new ExecutionHistory(); public String message = ""; @Override public void collectData(Map map) { map.put("chat.spam.vl", (int) spamTotalVL); - map.put("chat.empty.vl", (int) emptyTotalVL); map.put("chat.color.vl", (int) colorTotalVL); map.put("chat.spam.failed", spamFailed); - map.put("chat.empty.failed", emptyFailed); map.put("chat.color.failed", colorFailed); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java index c18be915..7a7d660a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java @@ -5,7 +5,6 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.data.ChatData; public class ColorCheck extends ChatCheck { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/EmptyCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/EmptyCheck.java deleted file mode 100644 index cd23a6cb..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/EmptyCheck.java +++ /dev/null @@ -1,45 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.checks.chat; - -import java.util.Locale; - -import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.data.ChatData; - -public class EmptyCheck extends ChatCheck { - - public EmptyCheck(NoCheat plugin) { - super(plugin, "chat.empty", Permissions.CHAT_EMPTY); - } - - public boolean check(NoCheatPlayer player, ChatData data, CCChat cc) { - - boolean cancel = false; - - if(data.message.trim().length() == 0) { - - data.emptyVL += 1; - data.emptyTotalVL += 1; - data.emptyFailed++; - - cancel = executeActions(player, cc.emptyActions.getActions(data.emptyVL)); - } - - return cancel; - } - - @Override - public boolean isEnabled(CCChat cc) { - return cc.emptyCheck; - } - - public String getParameter(ParameterName wildcard, NoCheatPlayer player) { - - if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).emptyVL); - else - return super.getParameter(wildcard, player); - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java index e60a3530..87eebac4 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java @@ -6,7 +6,6 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.data.ChatData; public class SpamCheck extends ChatCheck { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java index 2971aa54..d3e9dbbe 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java @@ -5,7 +5,6 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.DataStore; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; /** * Check various things related to fighting players/entities @@ -16,18 +15,13 @@ public abstract class FightCheck extends Check { private static final String id = "fight"; public FightCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); + super(plugin, id, name, permission); } public abstract boolean check(NoCheatPlayer player, FightData data, CCFight cc); public abstract boolean isEnabled(CCFight cc); - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return getData(player.getDataStore()).history; - } - public static FightData getData(DataStore base) { FightData data = base.get(id); if(data == null) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheckListener.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheckListener.java index 0198ee8c..4ab8ea55 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheckListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheckListener.java @@ -3,13 +3,13 @@ package cc.co.evenprime.bukkit.nocheat.checks.fight; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerAnimationEvent; import cc.co.evenprime.bukkit.nocheat.EventManager; @@ -30,19 +30,17 @@ public class FightCheckListener implements Listener, EventManager { this.checks.add(new DirectionCheck(plugin)); this.plugin = plugin; - - Bukkit.getPluginManager().registerEvents(this, plugin); } @EventHandler(priority = EventPriority.LOWEST) - public void entityDamage(final EntityDamageByEntityEvent event) { - if(event.isCancelled()) + public void entityDamage(final EntityDamageEvent event) { + if(event.isCancelled() || !(event instanceof EntityDamageByEntityEvent)) return; if(event.getCause() == DamageCause.ENTITY_ATTACK) { - normalDamage(event); - } else { - customDamage(event); + normalDamage((EntityDamageByEntityEvent) event); + } else if(event.getCause() == DamageCause.CUSTOM) { + customDamage((EntityDamageByEntityEvent) event); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java index d63b22b6..d3c3484d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java @@ -1,10 +1,8 @@ package cc.co.evenprime.bukkit.nocheat.checks.fight; import java.util.Map; - import net.minecraft.server.Entity; import cc.co.evenprime.bukkit.nocheat.DataItem; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public class FightData implements DataItem { @@ -19,7 +17,6 @@ public class FightData implements DataItem { public int noswingFailed = 0; public long directionLastViolationTime = 0; - public final ExecutionHistory history = new ExecutionHistory(); public Entity damagee; public boolean armswung = true; diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/CCInventory.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/CCInventory.java index d4d7b295..129ab782 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/CCInventory.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/CCInventory.java @@ -6,7 +6,6 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; public class CCInventory implements ConfigItem { - public final boolean closebeforeteleports; public final boolean check; public final boolean dropCheck; @@ -21,7 +20,5 @@ public class CCInventory implements ConfigItem { dropTimeFrame = data.getInteger(Configuration.INVENTORY_DROP_TIMEFRAME); dropLimit = data.getInteger(Configuration.INVENTORY_DROP_LIMIT); dropActions = data.getActionList(Configuration.INVENTORY_DROP_ACTIONS); - - closebeforeteleports = data.getBoolean(Configuration.INVENTORY_PREVENTITEMDUPE); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java index 39a4552e..db963f4d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java @@ -1,7 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.inventory; import java.util.Locale; - import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; @@ -45,7 +44,6 @@ public class DropCheck extends InventoryCheck { @Override public boolean isEnabled(CCInventory cc) { - // TODO Auto-generated method stub return cc.dropCheck; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheck.java index d81b03e2..f17916a9 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheck.java @@ -5,25 +5,19 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.DataStore; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public abstract class InventoryCheck extends Check { private static final String id = "inventory"; public InventoryCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); + super(plugin, id, name, permission); } public abstract boolean check(NoCheatPlayer player, InventoryData data, CCInventory cc); public abstract boolean isEnabled(CCInventory cc); - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return getData(player.getDataStore()).history; - } - public static InventoryData getData(DataStore base) { InventoryData data = base.get(id); if(data == null) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java index 6b4a8b3c..6ce9afc0 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java @@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.inventory; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -27,8 +26,6 @@ public class InventoryCheckListener implements Listener, EventManager { this.checks.add(new DropCheck(plugin)); this.plugin = plugin; - - Bukkit.getPluginManager().registerEvents(this, plugin); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java index 48281fc9..2c0b0a5c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java @@ -1,9 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.inventory; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.DataItem; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public class InventoryData implements DataItem { @@ -12,7 +10,6 @@ public class InventoryData implements DataItem { public int dropFailed = 0; public long dropLastTime; public int dropCount; - public final ExecutionHistory history = new ExecutionHistory(); @Override public void collectData(Map map) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheck.java index 210de699..c7530842 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheck.java @@ -1,14 +1,12 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving; import java.util.Locale; - import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.DataStore; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; public abstract class MovingCheck extends Check { @@ -16,7 +14,7 @@ public abstract class MovingCheck extends Check { private static final String id = "moving"; public MovingCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); + super(plugin, id, name, permission); } /** @@ -29,11 +27,6 @@ public abstract class MovingCheck extends Check { public abstract boolean isEnabled(CCMoving moving); - @Override - protected ExecutionHistory getHistory(NoCheatPlayer player) { - return getData(player.getDataStore()).history; - } - @Override public String getParameter(ParameterName wildcard, NoCheatPlayer player) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheckListener.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheckListener.java index 3fbe98e6..9f289f58 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheckListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheckListener.java @@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; @@ -43,8 +42,6 @@ public class MovingCheckListener implements Listener, EventManager { checks.add(new MorePacketsCheck(plugin)); this.plugin = plugin; - - Bukkit.getPluginManager().registerEvents(this, plugin); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java index 61da449d..ba6aaab0 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java @@ -1,9 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.DataItem; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; /** @@ -59,8 +57,6 @@ public class MovingData implements DataItem { public int lastElapsedIngameSeconds; - public final ExecutionHistory history = new ExecutionHistory(); - public final PreciseLocation from = new PreciseLocation(); public final PreciseLocation to = new PreciseLocation(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/CCLogging.java b/src/cc/co/evenprime/bukkit/nocheat/config/CCLogging.java index 144eda48..a0f319d6 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/CCLogging.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/CCLogging.java @@ -1,9 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.config; -import java.util.logging.Logger; - import cc.co.evenprime.bukkit.nocheat.log.Colors; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** * Configurations specific for logging. Every world gets one of these. @@ -11,21 +8,18 @@ import cc.co.evenprime.bukkit.nocheat.log.LogLevel; */ public class CCLogging { - public final LogLevel fileLevel; - public final LogLevel consoleLevel; - public final LogLevel chatLevel; - public final Logger filelogger; - public final boolean active; - public final String prefix; + public final boolean active; + public final boolean toFile; + public final boolean toConsole; + public final boolean toChat; + public final String prefix; - public CCLogging(Configuration data, Logger worldSpecificFileLogger) { + public CCLogging(Configuration data) { active = data.getBoolean(Configuration.LOGGING_ACTIVE); prefix = Colors.replaceColors(data.getString(Configuration.LOGGING_PREFIX)); - fileLevel = data.getLogLevel(Configuration.LOGGING_FILELEVEL); - consoleLevel = data.getLogLevel(Configuration.LOGGING_CONSOLELEVEL); - chatLevel = data.getLogLevel(Configuration.LOGGING_CHATLEVEL); - - filelogger = worldSpecificFileLogger; + toFile = data.getBoolean(Configuration.LOGGING_LOGTOFILE); + toConsole = data.getBoolean(Configuration.LOGGING_LOGTOCONSOLE); + toChat = data.getBoolean(Configuration.LOGGING_LOGTOCHAT); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java index 31f7c213..d5c071d5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java @@ -5,7 +5,6 @@ import java.util.Map; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode.DataType; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** * This class describes a basic configuration for NoCheat. NoCheats @@ -19,22 +18,19 @@ public abstract class Configuration { protected final static OptionNode ROOT = new OptionNode(null, null, DataType.PARENT); - protected final static OptionNode INACTIVE = new OptionNode(null, null, DataType.PARENT); - private final static OptionNode LOGGING = new OptionNode("logging", ROOT, DataType.PARENT); public final static OptionNode LOGGING_ACTIVE = new OptionNode("active", LOGGING, DataType.BOOLEAN); public final static OptionNode LOGGING_PREFIX = new OptionNode("prefix", LOGGING, DataType.STRING); public final static OptionNode LOGGING_FILENAME = new OptionNode("filename", LOGGING, DataType.STRING); - public final static OptionNode LOGGING_FILELEVEL = new OptionNode("filelevel", LOGGING, DataType.LOGLEVEL); - public final static OptionNode LOGGING_CONSOLELEVEL = new OptionNode("consolelevel", LOGGING, DataType.LOGLEVEL); - public final static OptionNode LOGGING_CHATLEVEL = new OptionNode("chatlevel", LOGGING, DataType.LOGLEVEL); + public final static OptionNode LOGGING_LOGTOFILE = new OptionNode("logtofile", LOGGING, DataType.BOOLEAN); + public final static OptionNode LOGGING_LOGTOCONSOLE = new OptionNode("logtoconsole", LOGGING, DataType.BOOLEAN); + public final static OptionNode LOGGING_LOGTOCHAT = new OptionNode("logtochat", LOGGING, DataType.BOOLEAN); private final static OptionNode DEBUG = new OptionNode("debug", ROOT, DataType.PARENT); public final static OptionNode DEBUG_SHOWACTIVECHECKS = new OptionNode("showactivechecks", DEBUG, DataType.BOOLEAN); public final static OptionNode DEBUG_COMPATIBILITY = new OptionNode("compatibility", DEBUG, DataType.BOOLEAN); private final static OptionNode INVENTORY = new OptionNode("inventory", ROOT, DataType.PARENT); - public final static OptionNode INVENTORY_PREVENTITEMDUPE = new OptionNode("preventitemdupe", INVENTORY, DataType.BOOLEAN); public static final OptionNode INVENTORY_CHECK = new OptionNode("check", INVENTORY, DataType.BOOLEAN); private final static OptionNode INVENTORY_DROP = new OptionNode("drop", INVENTORY, DataType.PARENT); @@ -116,10 +112,6 @@ public abstract class Configuration { public final static OptionNode CHAT_SPAM_LIMIT = new OptionNode("limit", CHAT_SPAM, DataType.INTEGER); public final static OptionNode CHAT_SPAM_ACTIONS = new OptionNode("actions", CHAT_SPAM, DataType.ACTIONLIST); - private final static OptionNode CHAT_EMPTY = new OptionNode("empty", CHAT, DataType.PARENT); - public final static OptionNode CHAT_EMPTY_CHECK = new OptionNode("check", CHAT_EMPTY, DataType.BOOLEAN); - public final static OptionNode CHAT_EMPTY_ACTIONS = new OptionNode("actions", CHAT_EMPTY, DataType.ACTIONLIST); - private final static OptionNode FIGHT = new OptionNode("fight", ROOT, DataType.PARENT); public final static OptionNode FIGHT_CHECK = new OptionNode("check", FIGHT, DataType.BOOLEAN); @@ -181,14 +173,6 @@ public abstract class Configuration { return (Integer) getRecursive(id); } - public LogLevel getLogLevel(OptionNode id) { - if(id.getType() != DataType.LOGLEVEL) { - throw new IllegalArgumentException(id + " is no loglevel value!"); - } - - return (LogLevel) getRecursive(id); - } - public ActionList getActionList(OptionNode id) { if(id.getType() != DataType.ACTIONLIST) { @@ -205,13 +189,6 @@ public abstract class Configuration { set(id, value); } - public void setValue(OptionNode id, LogLevel value) { - if(id.getType() != DataType.LOGLEVEL) { - throw new IllegalArgumentException(id + " is no loglevel value!"); - } - set(id, value); - } - public void setValue(OptionNode id, Boolean value) { if(id.getType() != DataType.BOOLEAN) { throw new IllegalArgumentException(id + " is no boolean value!"); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationCacheStore.java b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationCacheStore.java index 7641c79f..e91f5596 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationCacheStore.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationCacheStore.java @@ -2,8 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config; import java.util.HashMap; import java.util.Map; -import java.util.logging.Logger; - import cc.co.evenprime.bukkit.nocheat.ConfigItem; /** @@ -24,9 +22,9 @@ public class ConfigurationCacheStore { * Instantiate a config cache and populate it with the data of a * Config tree (and its parent tree) */ - public ConfigurationCacheStore(Configuration data, Logger worldSpecificFileLogger) { + public ConfigurationCacheStore(Configuration data) { - logging = new CCLogging(data, worldSpecificFileLogger); + logging = new CCLogging(data); debug = new CCDebug(data); this.data = data; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java index b51cd8a9..a4571127 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java @@ -14,7 +14,7 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; - +import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; /** @@ -29,12 +29,11 @@ public class ConfigurationManager { private final Map worldnameToConfigCacheMap = new HashMap(); - // Only use one filehandler per file, therefore keep open filehandlers in a - // map - private final Map fileToFileHandlerMap = new HashMap(); - private final Configuration defaultConfig; + private FileHandler fileHandler; + private NoCheat plugin; + private static class LogFileFormatter extends Formatter { private final SimpleDateFormat date; @@ -69,9 +68,11 @@ public class ConfigurationManager { // private final static String loggerName = "cc.co.evenprime.nocheat"; // public final Logger logger = Logger.getLogger(loggerName); - public ConfigurationManager(File rootConfigFolder) { + public ConfigurationManager(NoCheat plugin, File rootConfigFolder) { ActionMapper actionMapper = new ActionMapper(); + + this.plugin = plugin; // Parse actions file initializeActions(rootConfigFolder, actionMapper); @@ -135,7 +136,9 @@ public class ConfigurationManager { // Create a corresponding Configuration Cache // put the global config on the config map - worldnameToConfigCacheMap.put(null, new ConfigurationCacheStore(root, setupFileLogger(new File(rootConfigFolder, root.getString(DefaultConfiguration.LOGGING_FILENAME))))); + worldnameToConfigCacheMap.put(null, new ConfigurationCacheStore(root)); + + plugin.setFileLogger(setupFileLogger(new File(rootConfigFolder, root.getString(DefaultConfiguration.LOGGING_FILENAME)))); // Try to find world-specific config files Map worldFiles = getWorldSpecificConfigFiles(rootConfigFolder); @@ -149,7 +152,7 @@ public class ConfigurationManager { try { world.load(action); - worldnameToConfigCacheMap.put(worldEntry.getKey(), createConfigurationCache(rootConfigFolder, world)); + worldnameToConfigCacheMap.put(worldEntry.getKey(), new ConfigurationCacheStore(world)); // write the config file back to disk immediately world.save(); @@ -161,12 +164,6 @@ public class ConfigurationManager { } } - private ConfigurationCacheStore createConfigurationCache(File rootConfigFolder, Configuration configProvider) { - - return new ConfigurationCacheStore(configProvider, setupFileLogger(new File(rootConfigFolder, configProvider.getString(DefaultConfiguration.LOGGING_FILENAME)))); - - } - private static File getGlobalConfigFile(File rootFolder) { File globalConfig = new File(rootFolder, configFileName); @@ -195,36 +192,33 @@ public class ConfigurationManager { private Logger setupFileLogger(File logfile) { - FileHandler fh = fileToFileHandlerMap.get(logfile); - - // this logger will be used ONLY for logging to a single log-file and - // only - // in this plugin, therefore it doesn't need any namespace Logger l = Logger.getAnonymousLogger(); l.setLevel(Level.INFO); // Ignore parent's settings l.setUseParentHandlers(false); + for(Handler h : l.getHandlers()) { + l.removeHandler(h); + } - if(fh == null) { + if(fileHandler != null) { + fileHandler.close(); + l.removeHandler(fileHandler); + fileHandler = null; + } + + try { try { - try { - logfile.getParentFile().mkdirs(); - } catch(Exception e) { - e.printStackTrace(); - } - fh = new FileHandler(logfile.getCanonicalPath(), true); - // We decide before logging what gets logged there anyway - // because different worlds may use this filehandler and - // therefore may need to log different message levels - fh.setLevel(Level.ALL); - fh.setFormatter(new LogFileFormatter()); - fileToFileHandlerMap.put(logfile, fh); - - l.addHandler(fh); - + logfile.getParentFile().mkdirs(); } catch(Exception e) { e.printStackTrace(); } + fileHandler = new FileHandler(logfile.getCanonicalPath(), true); + fileHandler.setLevel(Level.ALL); + fileHandler.setFormatter(new LogFileFormatter()); + + l.addHandler(fileHandler); + } catch(Exception e) { + e.printStackTrace(); } return l; @@ -235,19 +229,11 @@ public class ConfigurationManager { * to be able to use them next time without problems */ public void cleanup() { - - // Remove handlers from the logger - for(ConfigurationCacheStore c : worldnameToConfigCacheMap.values()) { - for(Handler h : c.logging.filelogger.getHandlers()) { - c.logging.filelogger.removeHandler(h); - } - } - - // Close all file handlers - for(FileHandler fh : fileToFileHandlerMap.values()) { - fh.flush(); - fh.close(); - } + fileHandler.flush(); + fileHandler.close(); + Logger l = Logger.getLogger("NoCheat"); + l.removeHandler(fileHandler); + fileHandler = null; } /** diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java index c82dbe74..2cbdbbf6 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java @@ -6,7 +6,6 @@ import java.io.FileWriter; import java.io.IOException; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** * The place where the structure of the configuration tree is defined, the @@ -23,9 +22,9 @@ public class DefaultConfiguration extends Configuration { setValue(LOGGING_ACTIVE, true); setValue(LOGGING_PREFIX, "&4NC&f: "); setValue(LOGGING_FILENAME, "nocheat.log"); - setValue(LOGGING_FILELEVEL, LogLevel.LOW); - setValue(LOGGING_CONSOLELEVEL, LogLevel.HIGH); - setValue(LOGGING_CHATLEVEL, LogLevel.MED); + setValue(LOGGING_LOGTOFILE, true); + setValue(LOGGING_LOGTOCONSOLE, true); + setValue(LOGGING_LOGTOCHAT, true); } /*** DEBUG ***/ @@ -36,8 +35,6 @@ public class DefaultConfiguration extends Configuration { /*** INVENTORY ***/ { - setValue(INVENTORY_PREVENTITEMDUPE, true); - setValue(INVENTORY_CHECK, true); setValue(INVENTORY_DROP_CHECK, true); @@ -45,7 +42,7 @@ public class DefaultConfiguration extends Configuration { setValue(INVENTORY_DROP_LIMIT, 100); ActionList dropActionList = new ActionList(); - dropActionList.setActions(0, action.getActions("dropLog dropkick".split(" "))); + dropActionList.setActions(0, action.getActions("dropLog:co,ch,fi dropkick".split(" "))); setValue(INVENTORY_DROP_ACTIONS, dropActionList); } @@ -69,16 +66,16 @@ public class DefaultConfiguration extends Configuration { setValue(MOVING_RUNFLY_SWIMMINGSPEEDLIMIT, 18); ActionList movingActionList = new ActionList(); - movingActionList.setActions(0, action.getActions("moveLogLowShort moveCancel".split(" "))); - movingActionList.setActions(100, action.getActions("moveLogMedShort moveCancel".split(" "))); - movingActionList.setActions(400, action.getActions("moveLogHighShort moveCancel".split(" "))); + movingActionList.setActions(0, action.getActions("moveLogShort:fi moveCancel".split(" "))); + movingActionList.setActions(100, action.getActions("moveLogShort:ch,fi moveCancel".split(" "))); + movingActionList.setActions(400, action.getActions("moveLogLong:co,ch,fi moveCancel".split(" "))); setValue(MOVING_RUNFLY_ACTIONS, movingActionList); setValue(MOVING_RUNFLY_CHECKNOFALL, true); setValue(MOVING_RUNFLY_NOFALLMULTIPLIER, 200); ActionList nofallActionList = new ActionList(); - nofallActionList.setActions(0, action.getActions("nofallLog nofallDamage".split(" "))); + nofallActionList.setActions(0, action.getActions("nofallLog:co,ch,fi nofallDamage".split(" "))); setValue(MOVING_RUNFLY_NOFALLACTIONS, nofallActionList); setValue(MOVING_RUNFLY_ALLOWLIMITEDFLYING, false); @@ -87,17 +84,17 @@ public class DefaultConfiguration extends Configuration { setValue(MOVING_RUNFLY_FLYINGHEIGHTLIMIT, 250); ActionList flyingActionList = new ActionList(); - flyingActionList.setActions(0, action.getActions("moveLogLowShort moveCancel".split(" "))); - flyingActionList.setActions(100, action.getActions("moveLogMedShort moveCancel".split(" "))); - flyingActionList.setActions(400, action.getActions("moveLogHighShort moveCancel".split(" "))); + flyingActionList.setActions(0, action.getActions("moveLogShort:fi moveCancel".split(" "))); + flyingActionList.setActions(100, action.getActions("moveLogShort:ch,fi moveCancel".split(" "))); + flyingActionList.setActions(400, action.getActions("moveLogShort:co,ch,fi moveCancel".split(" "))); setValue(MOVING_RUNFLY_FLYINGACTIONS, flyingActionList); setValue(MOVING_MOREPACKETS_CHECK, true); ActionList morepacketsActionList = new ActionList(); - morepacketsActionList.setActions(0, action.getActions("morepacketsLow moveCancel".split(" "))); - morepacketsActionList.setActions(30, action.getActions("morepacketsMed moveCancel".split(" "))); - morepacketsActionList.setActions(60, action.getActions("morepacketsHigh moveCancel".split(" "))); + morepacketsActionList.setActions(0, action.getActions("morepackets:fi moveCancel".split(" "))); + morepacketsActionList.setActions(30, action.getActions("morepackets:ch,fi moveCancel".split(" "))); + morepacketsActionList.setActions(60, action.getActions("morepackets:co,ch,fi moveCancel".split(" "))); setValue(MOVING_MOREPACKETS_ACTIONS, morepacketsActionList); } @@ -110,7 +107,7 @@ public class DefaultConfiguration extends Configuration { ActionList reachActionList = new ActionList(); reachActionList.setActions(0, action.getActions("blockbreakCancel".split(" "))); - reachActionList.setActions(5, action.getActions("reachLog blockbreakCancel".split(" "))); + reachActionList.setActions(5, action.getActions("reachLog:fi,ch blockbreakCancel".split(" "))); setValue(BLOCKBREAK_REACH_ACTIONS, reachActionList); setValue(BLOCKBREAK_DIRECTION_CHECK, true); @@ -119,12 +116,12 @@ public class DefaultConfiguration extends Configuration { setValue(BLOCKBREAK_DIRECTION_PENALTYTIME, 300); ActionList directionActionList = new ActionList(); directionActionList.setActions(0, action.getActions("blockbreakCancel".split(" "))); - directionActionList.setActions(10, action.getActions("directionLog blockbreakCancel".split(" "))); + directionActionList.setActions(10, action.getActions("directionLog:fi,co,ch blockbreakCancel".split(" "))); setValue(BLOCKBREAK_DIRECTION_ACTIONS, directionActionList); setValue(BLOCKBREAK_NOSWING_CHECK, true); ActionList noswingActionList = new ActionList(); - noswingActionList.setActions(0, action.getActions("noswingLog blockbreakCancel".split(" "))); + noswingActionList.setActions(0, action.getActions("noswingLog:fi,co,ch blockbreakCancel".split(" "))); setValue(BLOCKBREAK_NOSWING_ACTIONS, noswingActionList); } @@ -136,7 +133,7 @@ public class DefaultConfiguration extends Configuration { ActionList reachActionList = new ActionList(); reachActionList.setActions(0, action.getActions("blockplaceCancel".split(" "))); - reachActionList.setActions(5, action.getActions("reachLog blockplaceCancel".split(" "))); + reachActionList.setActions(5, action.getActions("reachLog:fi,co,ch blockplaceCancel".split(" "))); setValue(BLOCKPLACE_REACH_ACTIONS, reachActionList); setValue(BLOCKPLACE_DIRECTION_CHECK, true); @@ -144,7 +141,7 @@ public class DefaultConfiguration extends Configuration { setValue(BLOCKPLACE_DIRECTION_PENALTYTIME, 100); ActionList directionActionList = new ActionList(); directionActionList.setActions(0, action.getActions("blockplaceCancel".split(" "))); - directionActionList.setActions(10, action.getActions("directionLog blockplaceCancel".split(" "))); + directionActionList.setActions(10, action.getActions("directionLog:fi,co,ch blockplaceCancel".split(" "))); setValue(BLOCKPLACE_DIRECTION_ACTIONS, directionActionList); } @@ -154,7 +151,7 @@ public class DefaultConfiguration extends Configuration { setValue(CHAT_COLOR_CHECK, true); ActionList colorActionList = new ActionList(); - colorActionList.setActions(0, action.getActions("colorLog chatCancel".split(" "))); + colorActionList.setActions(0, action.getActions("colorLog:fi,co,ch chatCancel".split(" "))); setValue(CHAT_COLOR_ACTIONS, colorActionList); setValue(CHAT_SPAM_CHECK, true); @@ -163,15 +160,9 @@ public class DefaultConfiguration extends Configuration { setValue(CHAT_SPAM_LIMIT, 5); ActionList spamActionList = new ActionList(); - spamActionList.setActions(0, action.getActions("spamLog chatCancel".split(" "))); - spamActionList.setActions(50, action.getActions("spamLog chatCancel spamkick".split(" "))); + spamActionList.setActions(0, action.getActions("spamLog:fi,co,ch chatCancel".split(" "))); + spamActionList.setActions(50, action.getActions("spamLog:fi,co,ch chatCancel spamkick".split(" "))); setValue(CHAT_SPAM_ACTIONS, spamActionList); - - setValue(CHAT_EMPTY_CHECK, true); - - ActionList emptyActionList = new ActionList(); - emptyActionList.setActions(0, action.getActions("emptyChatLog chatCancel emptyChatKick".split(" "))); - setValue(CHAT_EMPTY_ACTIONS, emptyActionList); } /*** FIGHT ***/ @@ -184,9 +175,9 @@ public class DefaultConfiguration extends Configuration { ActionList directionActionList = new ActionList(); directionActionList.setActions(0, action.getActions("fightCancel".split(" "))); - directionActionList.setActions(5, action.getActions("fightDirectionLogLow fightCancel".split(" "))); - directionActionList.setActions(20, action.getActions("fightDirectionLog fightCancel".split(" "))); - directionActionList.setActions(50, action.getActions("fightDirectionLogHigh fightCancel".split(" "))); + directionActionList.setActions(5, action.getActions("fightDirectionLog:fi fightCancel".split(" "))); + directionActionList.setActions(20, action.getActions("fightDirectionLog:fi,ch fightCancel".split(" "))); + directionActionList.setActions(50, action.getActions("fightDirectionLog:fi,ch,co fightCancel".split(" "))); setValue(FIGHT_DIRECTION_ACTIONS, directionActionList); setValue(FIGHT_NOSWING_CHECK, true); @@ -248,39 +239,40 @@ public class DefaultConfiguration extends Configuration { w(w, "# - Then comes their name. That name is used in the config file to identify them"); w(w, "# - Then comes the 'delay', that is how often has this action to be called before it really gets executed"); w(w, "# - Then comes the 'repeat', that is how many seconds have to be between two executions of the action"); - w(w, "# - Then comes the 'loglevel', that is how the log message gets categorized (low, med, high)"); w(w, "# - Then comes the 'message', depending on where the action is used, different keywords in [ ] may be used"); w(w, ""); w(w, "# Gives a very short log message of the violation, only containing name, violation type and total violation value, at most once every 15 seconds, only if more than 3 violations happened within the last minute (low) and immediatly (med,high)"); - w(w, "log moveLogLowShort 3 15 low [player] failed [check]. VL [violations]"); - w(w, "log moveLogMedShort 0 15 med [player] failed [check]. VL [violations]"); - w(w, "log moveLogHighShort 0 15 high [player] failed [check]. VL [violations]"); + w(w, "log moveLogLowShort 3 15 [player] failed [check]. VL [violations]"); + w(w, "log moveLogMedShort 0 15 [player] failed [check]. VL [violations]"); + w(w, "log moveLogHighShort 0 15 [player] failed [check]. VL [violations]"); + w(w, "log moveLogShort 0 5 [player] failed [check]. VL [violations]"); w(w, ""); w(w, "# Gives a log message of the violation, only containing name, violation type and total violation value, at most once every second, only if more than 5 violations happened within the last minute (low) and immediatly (med,high)"); - w(w, "log morepacketsLow 5 1 low [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); - w(w, "log morepacketsMed 0 1 med [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); - w(w, "log morepacketsHigh 0 1 high [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); + w(w, "log morepacketsLow 5 1 [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); + w(w, "log morepacketsMed 0 1 [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); + w(w, "log morepacketsHigh 0 1 [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); + w(w, "log morepackets 0 1 [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); w(w, ""); w(w, "# Gives a lengthy log message of the violation, containing name, location, violation type and total violation, at most once every 15 seconds, only if more than 3 violations happened within the last minute (low) and immediatly (med,high)"); - w(w, "log moveLogLowLong 3 15 low [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); - w(w, "log moveLogMedLong 0 15 med [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); - w(w, "log moveLogHighLong 0 15 high [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); + w(w, "log moveLogLowLong 3 15 [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); + w(w, "log moveLogMedLong 0 15 [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); + w(w, "log moveLogHighLong 0 15 [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); + w(w, "log moveLogLong 0 5 [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); w(w, ""); w(w, "# Some other log messages that are limited a bit by default, to avoid too extreme spam"); - w(w, "log reachLog 0 5 med [player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]"); - w(w, "log directionLog 2 5 med [player] failed [check]: tried to interact with a block out of line of sight. VL [violations]"); - w(w, "log spamLog 0 5 med [player] failed [check]: Last sent message \"[text]\". VL [violations]"); - w(w, "log nofallLog 0 5 med [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks. VL [violations]"); - w(w, "log noswingLog 2 5 med [player] failed [check]: Didn't swing arm. VL [violations]"); - w(w, "log emptyChatLog 0 5 med [player] failed [check]: Sent empty chat message. VL [violations]"); - w(w, "log colorLog 0 5 med [player] failed [check]: Sent colored chat message \"[text]\". VL [violations]"); - w(w, "log dropLog 0 5 med [player] failed [check]: Tried to drop more items than allowed. VL [violations]"); + w(w, "log reachLog 0 5 [player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]"); + w(w, "log directionLog 2 5 [player] failed [check]: tried to interact with a block out of line of sight. VL [violations]"); + w(w, "log spamLog 0 5 [player] failed [check]: Last sent message \"[text]\". VL [violations]"); + w(w, "log nofallLog 0 5 [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks. VL [violations]"); + w(w, "log noswingLog 2 5 [player] failed [check]: Didn't swing arm. VL [violations]"); + w(w, "log colorLog 0 5 [player] failed [check]: Sent colored chat message \"[text]\". VL [violations]"); + w(w, "log dropLog 0 5 [player] failed [check]: Tried to drop more items than allowed. VL [violations]"); w(w, ""); w(w, ""); w(w, "# Some log messages related to fighting, displaying the same text, but with different level (Info, Warning, Severe)"); - w(w, "log fightDirectionLogLow 0 5 low [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]."); - w(w, "log fightDirectionLog 0 5 med [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]."); - w(w, "log fightDirectionLogHigh 0 5 high [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]."); + w(w, "log fightDirectionLogLow 0 5 [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]."); + w(w, "log fightDirectionLog 0 5 [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]."); + w(w, "log fightDirectionLogHigh 0 5 [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]."); w(w, ""); w(w, "log fightSelfhitlog 0 1 med [player] failed [check]: tried to attack himself. Total violation level so far [violations]."); w(w, ""); @@ -310,7 +302,6 @@ public class DefaultConfiguration extends Configuration { w(w, "# E.g. Kick a player"); w(w, "consolecommand kick 0 1 kick [player]"); w(w, "consolecommand spamkick 0 1 kick [player]"); - w(w, "consolecommand emptyChatKick 0 1 kick [player]"); w(w, "consolecommand dropKick 0 1 kick [player]"); w.flush(); w.close(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java index 1c5a88cc..1a1d0965 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java @@ -19,14 +19,13 @@ public class Explainations { set(Configuration.LOGGING_PREFIX, "The short text that appears in front of messages by NoCheat. Color codes are &0-&9 and &A-&F"); set(Configuration.LOGGING_FILENAME, "Where logs that go to the logfile are stored. You can have different files for different worlds."); - set(Configuration.LOGGING_FILELEVEL, "What log-level need messages to have to get stored in the logfile. Values are:\n low: all messages\n med: med and high messages only\n high: high messages only\n off: no messages at all."); - set(Configuration.LOGGING_CONSOLELEVEL, "What log-level need messages to have to get displayed in your server console. Values are:\n low: all messages\n med: med and high messages only\n high: high messages only\n off: no messages at all."); - set(Configuration.LOGGING_CHATLEVEL, "What log-level need messages to have to get displayed in the ingame chat. Values are:\n low: all messages\n med: med and high messages only\n high: high messages only\n off: no messages at all."); + set(Configuration.LOGGING_LOGTOFILE, "Should messages get logged to the specified logfile?"); + set(Configuration.LOGGING_LOGTOCHAT, "Should messages get logged to the ingame chat?"); + set(Configuration.LOGGING_LOGTOCONSOLE, "Should messages get logged to the server console?"); set(Configuration.DEBUG_SHOWACTIVECHECKS, "Print to the console an overview of all checks that are enabled when NoCheat gets loaded."); set(Configuration.DEBUG_COMPATIBILITY, "Do some voodoo to fix common mistakes of other plugins which interfere with NoCheat."); - set(Configuration.INVENTORY_PREVENTITEMDUPE, "Close inventories of players before they get teleported between worlds, preventing creation of duplicate items."); set(Configuration.INVENTORY_CHECK, "If true, do various checks on Inventory related things."); set(Configuration.INVENTORY_DROP_CHECK, "If true, prevent players from dropping too many items in a short timeframe to reduce lag"); set(Configuration.INVENTORY_DROP_TIMEFRAME, "Over how many seconds should item drops be counted."); @@ -94,9 +93,6 @@ public class Explainations { set(Configuration.CHAT_SPAM_LIMIT, "How many messages per timeframe may the player send without it counting as spamming?"); set(Configuration.CHAT_SPAM_ACTIONS, "What should be done if a player is trying to spam the chat.\nUnit is number of chat messages above the limit you declared above."); - set(Configuration.CHAT_EMPTY_CHECK, "If true, check if a player is sending an empty message."); - set(Configuration.CHAT_EMPTY_ACTIONS, "What should be done if a player sends an empty message.\nUnit is number of empty chat messages sent by the player."); - set(Configuration.FIGHT_CHECK, "If true, do various checks on Events related to fighting."); set(Configuration.FIGHT_DIRECTION_CHECK, "If true, check if a player is really looking at enemies that he attacks."); set(Configuration.FIGHT_DIRECTION_PRECISION, "Set how precise the check should be. If you experience the check to be too zealous, increase this value. \nIf you want to make it tighter, reduce this value. Default is 100."); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java index 370a3c1b..0e496d94 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java @@ -7,13 +7,11 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; - import cc.co.evenprime.bukkit.nocheat.actions.Action; import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction; import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction; import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction; import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; public class FlatFileAction { @@ -88,7 +86,7 @@ public class FlatFileAction { throw new IllegalArgumentException("Missing fifth parameter of action " + name + " from file " + file.getName() + "."); } - return readLogAction(name, delay, repeat, parts[4]); + return new LogAction(name, delay, repeat, parts[4]); } else if(type.equalsIgnoreCase("consolecommand")) { // A consolecommand action, it seems if(parts.length < 5) { @@ -103,24 +101,4 @@ public class FlatFileAction { throw new IllegalArgumentException("Unknown action type " + type + " of action with name " + name + "."); } } - - // Moved outside because of bigger complexity of log message parsing - private Action readLogAction(String name, int delay, int repeat, String lastPart) { - - String[] rest = lastPart.split("\\s+", 2); - - if(rest.length < 2) { - throw new IllegalArgumentException("Missing sixth parameter of action " + name + " from file " + file.getName() + "."); - } - - LogLevel level; - try { - level = LogLevel.getLogLevelFromString(rest[0]); - } catch(IllegalArgumentException e) { - throw new IllegalArgumentException("Illegal fifth parameter of action " + name + ". " + e.getMessage()); - } - - return new LogAction(name, delay, repeat, level, rest[1]); - } - } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java index b0ab84f4..b141e3e0 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java @@ -9,13 +9,11 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.List; - import cc.co.evenprime.bukkit.nocheat.actions.Action; import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; public class FlatFileConfiguration extends Configuration { @@ -80,9 +78,6 @@ public class FlatFileConfiguration extends Configuration { case INTEGER: this.set(node, Integer.valueOf(removeQuotationMarks(value))); break; - case LOGLEVEL: - this.set(node, LogLevel.getLogLevelFromString(removeQuotationMarks(value))); - break; case BOOLEAN: this.set(node, Boolean.valueOf(removeQuotationMarks(value))); break; @@ -107,12 +102,15 @@ public class FlatFileConfiguration extends Configuration { List actions = new LinkedList(); for(String name : value.split("\\s+")) { - Action a2 = action.getAction(name); + String nameParts[] = name.split(":", 2); + Action a2 = action.getAction(nameParts[0]); if(a2 == null) { - System.out.println("Nocheat: Action with name " + name + " isn't defined. You need to define it in your actions.txt file to make it work."); + System.out.println("Nocheat: Action with name " + nameParts[0] + " isn't defined. You need to define it in your actions.txt file to make it work."); actions.add(new DummyAction(name, 0, 0)); + } else if(nameParts.length == 2) { + actions.add(a2.cloneWithProperties(nameParts[1])); } else { - actions.add(action.getAction(name)); + actions.add(a2); } } @@ -264,6 +262,9 @@ public class FlatFileConfiguration extends Configuration { StringBuilder s = new StringBuilder(""); for(Action s2 : actionList.getActions(treshold)) { s.append(" ").append(s2.name); + if(s2.getProperties() != null) { + s.append(":").append(s2.getProperties()); + } } saveValue(w, id + "." + treshold, s.toString().trim()); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java index 35523f29..0e8a4c86 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java @@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config.util; import java.util.HashMap; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.actions.Action; /** @@ -25,7 +24,10 @@ public class ActionMapper { Action[] result = new Action[actionNames.length]; for(int i = 0; i < actionNames.length; i++) { - result[i] = this.actions.get(actionNames[i].toLowerCase()); + String actionParts[] = actionNames[i].toLowerCase().split(":", 2); + result[i] = this.actions.get(actionParts[0]); + if(actionParts.length == 2) + result[i] = result[i].cloneWithProperties(actionParts[1]); } return result; diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/ExecutionHistory.java b/src/cc/co/evenprime/bukkit/nocheat/data/ExecutionHistory.java index 873c8e35..18b62940 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/ExecutionHistory.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/ExecutionHistory.java @@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.data; import java.util.HashMap; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.actions.Action; /** @@ -81,10 +80,10 @@ public class ExecutionHistory { // Store data between Events // time + action + action-counter - private final Map executionHistory; + private final Map> executionHistories; public ExecutionHistory() { - executionHistory = new HashMap(); + executionHistories = new HashMap>(); } /** @@ -93,13 +92,21 @@ public class ExecutionHistory { * which will influence further requests, so only use once and remember * the result * + * @param check * @param action * @param time * a time IN SECONDS * @return */ - public boolean executeAction(Action action, long time) { + public boolean executeAction(String check, Action action, long time) { + Map executionHistory = executionHistories.get(check); + + if(executionHistory == null) { + executionHistory = new HashMap(); + executionHistories.put(check, executionHistory); + } + ExecutionHistoryEntry entry = executionHistory.get(action); if(entry == null) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java b/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java index 983938f0..0f902e07 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java +++ b/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java @@ -5,7 +5,6 @@ import org.bukkit.World; import cc.co.evenprime.bukkit.nocheat.EventManager; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; -import cc.co.evenprime.bukkit.nocheat.log.LogLevel; public class ActiveCheckPrinter { @@ -35,11 +34,11 @@ public class ActiveCheckPrinter { } if(!introPrinted) { - plugin.logToConsole(LogLevel.LOW, intro); + System.out.println(intro); introPrinted = true; } - plugin.logToConsole(LogLevel.LOW, line.toString()); + System.out.println(line.toString()); line = new StringBuilder(length); diff --git a/src/cc/co/evenprime/bukkit/nocheat/log/Colors.java b/src/cc/co/evenprime/bukkit/nocheat/log/Colors.java index bb342bdc..bbd3d67b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/log/Colors.java +++ b/src/cc/co/evenprime/bukkit/nocheat/log/Colors.java @@ -8,10 +8,16 @@ import org.bukkit.ChatColor; */ public class Colors { + /** + * Replace instances of &X with a color + * + * @param text + * @return + */ public static String replaceColors(String text) { for(ChatColor c : ChatColor.values()) { - text = text.replace("&" + Integer.toHexString(c.getCode()), c.toString()); + text = text.replace("&" + c.getChar(), c.toString()); } return text; diff --git a/src/cc/co/evenprime/bukkit/nocheat/log/LogLevel.java b/src/cc/co/evenprime/bukkit/nocheat/log/LogLevel.java deleted file mode 100644 index bfe0a547..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/log/LogLevel.java +++ /dev/null @@ -1,47 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.log; - -import java.util.logging.Level; - -/** - * Define the available log levels (low, med, high, off) - * - */ -public enum LogLevel { - - OFF("off", Level.OFF), LOW("low", Level.INFO), MED("med", Level.WARNING), HIGH("high", Level.SEVERE); - - public final String name; - public final Level level; - - private LogLevel(String name, Level level) { - this.name = name; - this.level = level; - } - - public static LogLevel getLogLevelFromString(String s) { - for(LogLevel l : values()) { - if(l.name.equalsIgnoreCase(s)) { - return l; - } - } - - throw new IllegalArgumentException("Unknown log level " + s); - } - - public String toString() { - return this.name; - } - - /** - * Is this level smaller or equal to "level" - * - * @param level - */ - public boolean matches(LogLevel level) { - if(this == OFF || level == OFF) { - return false; - } else { - return this.level.intValue() <= level.level.intValue(); - } - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java b/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java deleted file mode 100644 index 2a6b2126..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java +++ /dev/null @@ -1,83 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.log; - -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; -import cc.co.evenprime.bukkit.nocheat.config.Permissions; - -/** - * Manage logging throughout NoCheat. Messages may be logged directly to a - * specific place or go through configuration/permissions to decide if and where - * the message will be visible - * - */ -public class LogManager { - - public LogManager() { - - } - - /** - * Check if and where the message should be logged to and then do it - * - * @param level - * @param message - * @param cc - */ - public void log(LogLevel level, String message, ConfigurationCacheStore cc) { - - if(!cc.logging.active) - return; - - if(cc.logging.fileLevel.matches(level)) { - logToFile(level, ChatColor.stripColor(message), cc.logging.filelogger); - } - - if(cc.logging.consoleLevel.matches(level)) { - logToConsole(level, ChatColor.stripColor(message)); - } - - if(cc.logging.chatLevel.matches(level)) { - logToChat(level, message); - } - } - - /** - * Directly log to the server console, no checks - * - * @param level - * @param message - */ - public void logToConsole(LogLevel level, String message) { - Logger.getLogger("Minecraft").log(level.level, message); - } - - /** - * Directly log to the chat, no checks - * - * @param level - * @param message - */ - private void logToChat(LogLevel level, String message) { - for(Player player : Bukkit.getServer().getOnlinePlayers()) { - if(player.hasPermission(Permissions.ADMIN_CHATLOG)) { - player.sendMessage(message); - } - } - } - - /** - * Directly log to the file, no checks - * - * @param level - * @param message - * @param fileLogger - */ - private void logToFile(LogLevel level, String message, Logger fileLogger) { - fileLogger.log(level.level, message); - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/log/NoCheatLogEvent.java b/src/cc/co/evenprime/bukkit/nocheat/log/NoCheatLogEvent.java new file mode 100644 index 00000000..a5c60731 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/log/NoCheatLogEvent.java @@ -0,0 +1,65 @@ +package cc.co.evenprime.bukkit.nocheat.log; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class NoCheatLogEvent extends Event { + + private static final long serialVersionUID = 1L; + + private static final HandlerList handlers = new HandlerList(); + private String message; + private String prefix; + private boolean toConsole, toChat, toFile; + + public NoCheatLogEvent(String prefix, String message, boolean toConsole, boolean toChat, boolean toFile) { + this.message = message; + this.toConsole = toConsole; + this.toChat = toChat; + this.toFile = toFile; + } + + public String getPrefix() { + return prefix; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean toFile() { + return toFile; + } + + public void setToFile(boolean toFile) { + this.toFile = toFile; + } + + public boolean toChat() { + return toChat; + } + + public void setToChat(boolean toChat) { + this.toChat = toChat; + } + + public boolean toConsole() { + return toConsole; + } + + public void setToConsole(boolean toConsole) { + this.toConsole = toConsole; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java b/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java index 398b6b92..a9693ef5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java +++ b/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java @@ -2,15 +2,14 @@ package cc.co.evenprime.bukkit.nocheat.player; import net.minecraft.server.EntityPlayer; import net.minecraft.server.MobEffectList; - import org.bukkit.GameMode; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; - import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.DataStore; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public class NoCheatPlayerImpl implements NoCheatPlayer { @@ -19,12 +18,14 @@ public class NoCheatPlayerImpl implements NoCheatPlayer { protected final DataStore data; protected ConfigurationCacheStore config; protected long lastUsedTime; + protected final ExecutionHistory history; public NoCheatPlayerImpl(Player player, NoCheat plugin) { this.player = player; this.plugin = plugin; this.data = new DataStore(); + this.history = new ExecutionHistory(); this.lastUsedTime = System.currentTimeMillis(); } @@ -99,4 +100,9 @@ public class NoCheatPlayerImpl implements NoCheatPlayer { public void closeInventory() { ((CraftPlayer) this.player).getHandle().closeInventory(); } + + @Override + public ExecutionHistory getExecutionHistory() { + return history; + } }