From d5d705fbe4a94fd76b3f22930d4fa61d22cf0d68 Mon Sep 17 00:00:00 2001 From: h31ix Date: Mon, 14 Jan 2013 20:28:52 -0500 Subject: [PATCH] Nitpicky stuff --- .gitignore | 3 +- .../anticheat/manage/AnticheatManager.java | 2 +- .../net/h31ix/anticheat/manage/Backend.java | 10 +- .../java/net/h31ix/anticheat/manage/User.java | 10 +- .../net/h31ix/anticheat/metrics/Metrics.java | 587 ++++++++++++------ .../h31ix/anticheat/util/Configuration.java | 16 - .../anticheat/util/ConsoleFormatter.java | 31 - .../java/net/h31ix/anticheat/util/Magic.java | 5 + .../net/h31ix/anticheat/xray/XRayTracker.java | 2 +- src/main/resources/magic.yml | 1 + 10 files changed, 401 insertions(+), 266 deletions(-) delete mode 100644 src/main/java/net/h31ix/anticheat/util/ConsoleFormatter.java diff --git a/.gitignore b/.gitignore index 04cc7fe..b69b421 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /target/ -/bin/ -/.settings/ /.* +*.iml diff --git a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java index fd3d0f5..68c43b8 100644 --- a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java @@ -122,7 +122,7 @@ public class AnticheatManager { public String getEventChainReport() { String gen = ""; if (!configuration.eventChains()) - return "Event Chains is disabled in the configuration, If @h31ix or @SuPaHsPii need this, please re enable it in the configuration."; + return "Event Chains is disabled by the configuration."; for (Entry e : eventchains.entrySet()) { String toadd = ""; diff --git a/src/main/java/net/h31ix/anticheat/manage/Backend.java b/src/main/java/net/h31ix/anticheat/manage/Backend.java index 2a6e7f6..947e2f3 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Backend.java +++ b/src/main/java/net/h31ix/anticheat/manage/Backend.java @@ -306,8 +306,6 @@ public class Backend { } else if (player.isSprinting()) { reason = "while sprinting "; max = magic.XZ_SPEED_MAX_SPRINT; - } else { - max = magic.XZ_SPEED_MAX; } if (x > max || z > max) { int num = this.increment(player, speedViolation, magic.SPEED_MAX); @@ -431,7 +429,7 @@ public class Backend { } public CheckResult checkYAxis(Player player, Distance distance) { - if (distance.getYDifference() > 400 || distance.getYDifference() < 0) { + if (distance.getYDifference() > magic.TELEPORT_MIN || distance.getYDifference() < 0) { return PASS; } if (!isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) && !player.isInsideVehicle() && !Utilities.isInWater(player)) { @@ -542,7 +540,7 @@ public class Backend { } public CheckResult checkFlight(Player player, Distance distance) { - if (distance.getYDifference() > 400) { + if (distance.getYDifference() > magic.TELEPORT_MIN) { // This was a teleport, so we don't care about it. return PASS; } @@ -926,10 +924,6 @@ public class Backend { return justAnimated(player); } - public boolean justAnimated(Player player, Entity e) { - return justAnimated(player); - } - private boolean justAnimated(Player player) { String name = player.getName(); if (animated.containsKey(name)) { diff --git a/src/main/java/net/h31ix/anticheat/manage/User.java b/src/main/java/net/h31ix/anticheat/manage/User.java index 30b660c..5cba7ef 100644 --- a/src/main/java/net/h31ix/anticheat/manage/User.java +++ b/src/main/java/net/h31ix/anticheat/manage/User.java @@ -107,14 +107,10 @@ public class User { return goodLocation; } - public boolean hasGoodLocation() { - return goodLocation != null; - } - public void setGoodLocation(Location e) { - if (Utilities.cantStandAtExp(e)) { return; } - - if (e.getBlock().isLiquid() && !Utilities.isFullyInWater(e)) { return; } + if (Utilities.cantStandAtExp(e) || (e.getBlock().isLiquid() && !Utilities.isFullyInWater(e))) { + return; + } goodLocation = e; } diff --git a/src/main/java/net/h31ix/anticheat/metrics/Metrics.java b/src/main/java/net/h31ix/anticheat/metrics/Metrics.java index e75e477..7dfdecd 100644 --- a/src/main/java/net/h31ix/anticheat/metrics/Metrics.java +++ b/src/main/java/net/h31ix/anticheat/metrics/Metrics.java @@ -1,7 +1,5 @@ -package net.h31ix.anticheat.metrics; - /* - * Copyright 2011 Tyler Blair. All rights reserved. + * Copyright 2011-2013 Tyler Blair. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -27,223 +25,403 @@ package net.h31ix.anticheat.metrics; * authors and contributors and should not be interpreted as representing official policies, * either expressed or implied, of anybody else. */ +package net.h31ix.anticheat.metrics; -import java.io.*; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.scheduler.BukkitTask; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.net.Proxy; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; -import java.util.*; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.UUID; +import java.util.logging.Level; /** - *

- * The metrics class obtains data about a plugin and submits statistics about it to the metrics backend. - *

- *

- * Public methods provided by this class: - *

+ *

The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.

+ * Public methods provided by this class:

* * Graph createGraph(String name);
- * void addCustomData(Metrics.Plotter plotter);
+ * void addCustomData(BukkitMetrics.Plotter plotter);
* void start();
*
*/ public class Metrics { - + /** * The current revision number */ - private static final int REVISION = 5; - + private final static int REVISION = 6; /** * The base url of the metrics domain */ - private static final String BASE_URL = "http://metrics.griefcraft.com"; - + private static final String BASE_URL = "http://mcstats.org"; /** * The url used to report a server's status */ private static final String REPORT_URL = "/report/%s"; - /** - * The file where guid and opt out is stored in - */ - private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml"; - - /** - * The separator to use for custom data. This MUST NOT change unless you are hosting your own version of metrics and want to change it. + * The separator to use for custom data. This MUST NOT change unless you are hosting your own version of metrics and + * want to change it. */ private static final String CUSTOM_DATA_SEPARATOR = "~~"; - /** * Interval of time to ping (in minutes) */ private static final int PING_INTERVAL = 10; - /** * The plugin this metrics submits for */ private final Plugin plugin; - /** * All of the custom graphs to submit to metrics */ private final Set graphs = Collections.synchronizedSet(new HashSet()); - /** * The default graph, used for addCustomData when you don't want a specific graph */ private final Graph defaultGraph = new Graph("Default"); - /** * The plugin configuration file */ private final YamlConfiguration configuration; - + /** + * The plugin configuration file + */ + private final File configurationFile; /** * Unique server id */ private final String guid; - - public Metrics(Plugin plugin) throws IOException { - if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } - + /** + * Debug mode + */ + private final boolean debug; + /** + * Lock for synchronization + */ + private final Object optOutLock = new Object(); + /** + * The scheduled task + */ + private volatile BukkitTask task = null; + + public Metrics(final Plugin plugin) throws IOException { + if (plugin == null) { + throw new IllegalArgumentException("Plugin cannot be null"); + } + this.plugin = plugin; - + // load the config - File file = new File(CONFIG_FILE); - configuration = YamlConfiguration.loadConfiguration(file); - + configurationFile = getConfigFile(); + configuration = YamlConfiguration.loadConfiguration(configurationFile); + // add some defaults configuration.addDefault("opt-out", false); configuration.addDefault("guid", UUID.randomUUID().toString()); - + configuration.addDefault("debug", false); + // Do we need to create the file? if (configuration.get("guid", null) == null) { - configuration.options().header("http://metrics.griefcraft.com").copyDefaults(true); - configuration.save(file); + configuration.options().header("http://mcstats.org").copyDefaults(true); + configuration.save(configurationFile); } - + // Load the guid then guid = configuration.getString("guid"); + debug = configuration.getBoolean("debug", false); } - + /** - * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics website. Plotters can be added to the graph object returned. - * - * @param name + * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics + * website. Plotters can be added to the graph object returned. + * + * @param name The name of the graph * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given */ - public Graph createGraph(String name) { - if (name == null) { throw new IllegalArgumentException("Graph name cannot be null"); } - + public Graph createGraph(final String name) { + if (name == null) { + throw new IllegalArgumentException("Graph name cannot be null"); + } + // Construct the graph object - Graph graph = new Graph(name); - + final Graph graph = new Graph(name); + // Now we can add our graph graphs.add(graph); - + // and return back return graph; } - + + /** + * Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend + * + * @param graph The name of the graph + */ + public void addGraph(final Graph graph) { + if (graph == null) { + throw new IllegalArgumentException("Graph cannot be null"); + } + + graphs.add(graph); + } + /** * Adds a custom data plotter to the default graph - * - * @param plotter + * + * @param plotter The plotter to use to plot custom data */ - public void addCustomData(Plotter plotter) { - if (plotter == null) { throw new IllegalArgumentException("Plotter cannot be null"); } - + public void addCustomData(final Plotter plotter) { + if (plotter == null) { + throw new IllegalArgumentException("Plotter cannot be null"); + } + // Add the plotter to the graph o/ defaultGraph.addPlotter(plotter); - + // Ensure the default graph is included in the submitted graphs graphs.add(defaultGraph); } - + /** - * Start measuring statistics. This will immediately create an async repeating task as the plugin and send the initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200 ticks. + * Start measuring statistics. This will immediately create an async repeating task as the plugin and send the + * initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200 + * ticks. + * + * @return True if statistics measuring is running, otherwise false. */ - public void start() { - // Did we opt out? - if (configuration.getBoolean("opt-out", false)) { return; } - - // Begin hitting the server with glorious data - plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() { - private boolean firstPost = true; - - @Override - public void run() { - try { - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin(!firstPost); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } catch (IOException e) { - System.err.println("[Metrics] " + e.getMessage()); - } + public boolean start() { + synchronized (optOutLock) { + // Did we opt out? + if (isOptOut()) { + return false; } - }, 0, PING_INTERVAL * 1200); + + // Is metrics already running? + if (task != null) { + return true; + } + + // Begin hitting the server with glorious data + task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { + + private boolean firstPost = true; + + public void run() { + try { + // This has to be synchronized or it can collide with the disable method. + synchronized (optOutLock) { + // Disable Task, if it is running and the server owner decided to opt-out + if (isOptOut() && task != null) { + task.cancel(); + task = null; + // Tell all plotters to stop gathering information. + for (Graph graph : graphs) { + graph.onOptOut(); + } + } + } + + // We use the inverse of firstPost because if it is the first time we are posting, + // it is not a interval ping, so it evaluates to FALSE + // Each time thereafter it will evaluate to TRUE, i.e PING! + postPlugin(!firstPost); + + // After the first post we set firstPost to false + // Each post thereafter will be a ping + firstPost = false; + } catch (IOException e) { + if (debug) { + Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); + } + } + } + }, 0, PING_INTERVAL * 1200); + + return true; + } } - + + /** + * Has the server owner denied plugin metrics? + * + * @return true if metrics should be opted out of it + */ + public boolean isOptOut() { + synchronized (optOutLock) { + try { + // Reload the metrics file + configuration.load(getConfigFile()); + } catch (IOException ex) { + if (debug) { + Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + } + return true; + } catch (InvalidConfigurationException ex) { + if (debug) { + Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + } + return true; + } + return configuration.getBoolean("opt-out", false); + } + } + + /** + * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. + * + * @throws java.io.IOException + */ + public void enable() throws IOException { + // This has to be synchronized or it can collide with the check in the task. + synchronized (optOutLock) { + // Check if the server owner has already set opt-out, if not, set it. + if (isOptOut()) { + configuration.set("opt-out", false); + configuration.save(configurationFile); + } + + // Enable Task, if it is not running + if (task == null) { + start(); + } + } + } + + /** + * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. + * + * @throws java.io.IOException + */ + public void disable() throws IOException { + // This has to be synchronized or it can collide with the check in the task. + synchronized (optOutLock) { + // Check if the server owner has already set opt-out, if not, set it. + if (!isOptOut()) { + configuration.set("opt-out", true); + configuration.save(configurationFile); + } + + // Disable Task, if it is running + if (task != null) { + task.cancel(); + task = null; + } + } + } + + /** + * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status + * + * @return the File object for the config file + */ + public File getConfigFile() { + // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use + // is to abuse the plugin object we already have + // plugin.getDataFolder() => base/plugins/PluginA/ + // pluginsFolder => base/plugins/ + // The base is not necessarily relative to the startup directory. + File pluginsFolder = plugin.getDataFolder().getParentFile(); + + // return => base/plugins/PluginMetrics/config.yml + return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); + } + /** * Generic method that posts a plugin to the metrics website */ - private void postPlugin(boolean isPing) throws IOException { - // The plugin's description file containg all of the plugin data such as name, version, author, etc + private void postPlugin(final boolean isPing) throws IOException { + // Server software specific section PluginDescriptionFile description = plugin.getDescription(); - + String pluginName = description.getName(); + boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled + String pluginVersion = description.getVersion(); + String serverVersion = Bukkit.getVersion(); + int playersOnline = Bukkit.getServer().getOnlinePlayers().length; + + // END server software specific section -- all code below does not use any code outside of this class / Java + // Construct the post data - String data = encode("guid") + '=' + encode(guid) + encodeDataPair("version", description.getVersion().split("-b")[0]) + encodeDataPair("server", Bukkit.getVersion()) + encodeDataPair("players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length)) + encodeDataPair("revision", String.valueOf(REVISION)); - + final StringBuilder data = new StringBuilder(); + + // The plugin's description file containg all of the plugin data such as name, version, author, etc + data.append(encode("guid")).append('=').append(encode(guid)); + encodeDataPair(data, "version", pluginVersion); + encodeDataPair(data, "server", serverVersion); + encodeDataPair(data, "players", Integer.toString(playersOnline)); + encodeDataPair(data, "revision", String.valueOf(REVISION)); + + // New data as of R6 + String osname = System.getProperty("os.name"); + String osarch = System.getProperty("os.arch"); + String osversion = System.getProperty("os.version"); + String java_version = System.getProperty("java.version"); + int coreCount = Runtime.getRuntime().availableProcessors(); + + // normalize os arch .. amd64 -> x86_64 + if (osarch.equals("amd64")) { + osarch = "x86_64"; + } + + encodeDataPair(data, "osname", osname); + encodeDataPair(data, "osarch", osarch); + encodeDataPair(data, "osversion", osversion); + encodeDataPair(data, "cores", Integer.toString(coreCount)); + encodeDataPair(data, "online-mode", Boolean.toString(onlineMode)); + encodeDataPair(data, "java_version", java_version); + // If we're pinging, append it if (isPing) { - data += encodeDataPair("ping", "true"); + encodeDataPair(data, "ping", "true"); } - + // Acquire a lock on the graphs, which lets us make the assumption we also lock everything // inside of the graph (e.g plotters) synchronized (graphs) { - Iterator iter = graphs.iterator(); - + final Iterator iter = graphs.iterator(); + while (iter.hasNext()) { - Graph graph = iter.next(); - - // Because we have a lock on the graphs set already, it is reasonable to assume - // that our lock transcends down to the individual plotters in the graphs also. - // Because our methods are private, no one but us can reasonably access this list - // without reflection so this is a safe assumption without adding more code. + final Graph graph = iter.next(); + for (Plotter plotter : graph.getPlotters()) { // The key name to send to the metrics server // The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top // Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME - String key = String.format("C%s%s%s%s", CUSTOM_DATA_SEPARATOR, graph.getName(), CUSTOM_DATA_SEPARATOR, plotter.getColumnName()); - + final String key = String.format("C%s%s%s%s", CUSTOM_DATA_SEPARATOR, graph.getName(), CUSTOM_DATA_SEPARATOR, plotter.getColumnName()); + // The value to send, which for the foreseeable future is just the string // value of plotter.getValue() - String value = Integer.toString(plotter.getValue()); - + final String value = Integer.toString(plotter.getValue()); + // Add it to the http post data :) - data += encodeDataPair(key, value); + encodeDataPair(data, key, value); } } } - + // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, description.getName())); - + URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(pluginName))); + // Connect to the website URLConnection connection; - + // Mineshafter creates a socks proxy, so we can safely bypass it // It does not reroute POST requests so we need to go around it if (isMineshafterPresent()) { @@ -251,33 +429,33 @@ public class Metrics { } else { connection = url.openConnection(); } - + connection.setDoOutput(true); - + // Write the data - OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); - writer.write(data); + final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); + writer.write(data.toString()); writer.flush(); - + // Now read the response - BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String response = reader.readLine(); - + final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + final String response = reader.readLine(); + // close resources writer.close(); reader.close(); - - if (response.startsWith("ERR")) { - throw new IOException(response); // Throw the exception + + if (response == null || response.startsWith("ERR")) { + throw new IOException(response); //Throw the exception } else { // Is this the first update this hour? if (response.contains("OK This is your first update this hour")) { synchronized (graphs) { - Iterator iter = graphs.iterator(); - + final Iterator iter = graphs.iterator(); + while (iter.hasNext()) { - Graph graph = iter.next(); - + final Graph graph = iter.next(); + for (Plotter plotter : graph.getPlotters()) { plotter.reset(); } @@ -285,13 +463,12 @@ public class Metrics { } } } - // if (response.startsWith("OK")) - We should get "OK" followed by an optional description if everything goes right } - + /** * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return + * + * @return true if mineshafter is installed on the server */ private boolean isMineshafterPresent() { try { @@ -301,164 +478,174 @@ public class Metrics { return false; } } - + /** - *

- * Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first key/value pair MUST be included manually, e.g: - *

+ *

Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first key/value pair + * MUST be included manually, e.g:

* - * String httpData = encode("guid") + '=' + encode("1234") + encodeDataPair("authors") + ".."; + * StringBuffer data = new StringBuffer(); + * data.append(encode("guid")).append('=').append(encode(guid)); + * encodeDataPair(data, "version", description.getVersion()); * - * - * @param key - * @param value - * @return + * + * @param buffer the stringbuilder to append the data pair onto + * @param key the key value + * @param value the value */ - private static String encodeDataPair(String key, String value) throws UnsupportedEncodingException { - return '&' + encode(key) + '=' + encode(value); + private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException { + buffer.append('&').append(encode(key)).append('=').append(encode(value)); } - + /** * Encode text as UTF-8 - * - * @param text - * @return + * + * @param text the text to encode + * @return the encoded text, as UTF-8 */ - private static String encode(String text) throws UnsupportedEncodingException { + private static String encode(final String text) throws UnsupportedEncodingException { return URLEncoder.encode(text, "UTF-8"); } - + /** * Represents a custom graph on the website */ public static class Graph { - + /** - * The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is rejected + * The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is + * rejected */ private final String name; - /** * The set of plotters that are contained within this graph */ private final Set plotters = new LinkedHashSet(); - - private Graph(String name) { + + private Graph(final String name) { this.name = name; } - + /** * Gets the graph's name - * - * @return + * + * @return the Graph's name */ public String getName() { return name; } - + /** * Add a plotter to the graph, which will be used to plot entries - * - * @param plotter + * + * @param plotter the plotter to add to the graph */ - public void addPlotter(Plotter plotter) { + public void addPlotter(final Plotter plotter) { plotters.add(plotter); } - + /** * Remove a plotter from the graph - * - * @param plotter + * + * @param plotter the plotter to remove from the graph */ - public void removePlotter(Plotter plotter) { + public void removePlotter(final Plotter plotter) { plotters.remove(plotter); } - + /** - * Gets an unmodifiable set of the plotter objects in the graph - * - * @return + * Gets an unmodifiable set of the plotter objects in the graph + * + * @return an unmodifiable {@link java.util.Set} of the plotter objects */ public Set getPlotters() { return Collections.unmodifiableSet(plotters); } - + @Override public int hashCode() { return name.hashCode(); } - + @Override - public boolean equals(Object object) { - if (!(object instanceof Graph)) { return false; } - - Graph graph = (Graph) object; + public boolean equals(final Object object) { + if (!(object instanceof Graph)) { + return false; + } + + final Graph graph = (Graph) object; return graph.name.equals(name); } - + + /** + * Called when the server owner decides to opt-out of BukkitMetrics while the server is running. + */ + protected void onOptOut() { + } } - + /** * Interface used to collect custom data for a plugin */ public static abstract class Plotter { - + /** * The plot's name */ private final String name; - + /** * Construct a plotter with the default plot name */ public Plotter() { this("Default"); } - + /** * Construct a plotter with a specific plot name - * - * @param name + * + * @param name the name of the plotter to use, which will show up on the website */ - public Plotter(String name) { + public Plotter(final String name) { this.name = name; } - + /** - * Get the current value for the plotted point - * - * @return + * Get the current value for the plotted point. Since this function defers to an external function it may or may + * not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called + * from any thread so care should be taken when accessing resources that need to be synchronized. + * + * @return the current value for the point to be plotted. */ public abstract int getValue(); - + /** * Get the column name for the plotted point - * + * * @return the plotted point's column name */ public String getColumnName() { return name; } - + /** * Called after the website graphs have been updated */ public void reset() { } - + @Override public int hashCode() { - return getColumnName().hashCode() + getValue(); + return getColumnName().hashCode(); } - + @Override - public boolean equals(Object object) { - if (!(object instanceof Plotter)) { return false; } - - Plotter plotter = (Plotter) object; + public boolean equals(final Object object) { + if (!(object instanceof Plotter)) { + return false; + } + + final Plotter plotter = (Plotter) object; return plotter.name.equals(name) && plotter.getValue() == getValue(); } - } - -} +} \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/util/Configuration.java b/src/main/java/net/h31ix/anticheat/util/Configuration.java index cfe161c..2405f80 100644 --- a/src/main/java/net/h31ix/anticheat/util/Configuration.java +++ b/src/main/java/net/h31ix/anticheat/util/Configuration.java @@ -258,18 +258,6 @@ public class Configuration { } } - public List getWorldsExempt() { - return exemptWorlds; - } - - public File getConfigFile() { - return configFile; - } - - public File getLevelFile() { - return levelFile; - } - public FileConfiguration getMagic() { return magic; } @@ -305,8 +293,4 @@ public class Configuration { Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); } } - - public String getMainConfigurationDump() { - return config.saveToString(); - } } diff --git a/src/main/java/net/h31ix/anticheat/util/ConsoleFormatter.java b/src/main/java/net/h31ix/anticheat/util/ConsoleFormatter.java deleted file mode 100644 index 069ba2b..0000000 --- a/src/main/java/net/h31ix/anticheat/util/ConsoleFormatter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.h31ix.anticheat.util; - -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -public class ConsoleFormatter extends Formatter { - - @Override - public String format(LogRecord record) { - StringBuilder output = new StringBuilder().append(record.getMessage()).append(' '); - return output.toString(); - } -} diff --git a/src/main/java/net/h31ix/anticheat/util/Magic.java b/src/main/java/net/h31ix/anticheat/util/Magic.java index 0ed1e0a..466d809 100644 --- a/src/main/java/net/h31ix/anticheat/util/Magic.java +++ b/src/main/java/net/h31ix/anticheat/util/Magic.java @@ -329,6 +329,10 @@ public class Magic { * The minimum time it should have taken for the player to travel X steps; Type=system; +Leniency=Decrease. */ public final long TIMER_TIMEMIN; + /** + * Minimum travel distance for move to be considered a teleport and subsequently be ignored; Type=int; +Leniency=Increase. + */ + public final long TELEPORT_MIN; private FileConfiguration defaults; private FileConfiguration magic; @@ -414,6 +418,7 @@ public class Magic { INVENTORY_TIMEMIN = getInt("INVENTORY_TIMEMIN"); TIMER_STEP_CHECK = getInt("TIMER_STEP_CHECK"); TIMER_TIMEMIN = getLong("TIMER_TIMEMIN"); + TELEPORT_MIN = getLong("TELEPORT_MIN"); } private int getInt(String path) { diff --git a/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java b/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java index 99d37ab..997ea31 100644 --- a/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java +++ b/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java @@ -136,7 +136,7 @@ public class XRayTracker { float p = (float) Math.pow(POWER, 1); number *= p; float tmp = Math.round(number); - return (float) tmp / p; + return tmp / p; } public void reset(String player) { diff --git a/src/main/resources/magic.yml b/src/main/resources/magic.yml index f29373f..eebb19e 100644 --- a/src/main/resources/magic.yml +++ b/src/main/resources/magic.yml @@ -75,3 +75,4 @@ INVENTORY_CHECK: 10 INVENTORY_TIMEMIN: 50 TIMER_STEP_CHECK: 50 TIMER_TIMEMIN: 2000 +TELEPORT_MIN: 400