mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 14:38:46 +00:00
Nitpicky stuff
This commit is contained in:
1 parent
d12fb048df
commit
d5d705fbe4
10 files changed
+313
-178
No files matched your search
+1
-2
@@ -1,4 +1,3 @@
|
|||||||
/target/
|
/target/
|
||||||
/bin/
|
|
||||||
/.settings/
|
|
||||||
/.*
|
/.*
|
||||||
|
*.iml
|
||||||
@@ -122,7 +122,7 @@ public class AnticheatManager {
|
|||||||
public String getEventChainReport() {
|
public String getEventChainReport() {
|
||||||
String gen = "";
|
String gen = "";
|
||||||
if (!configuration.eventChains())
|
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<String, RegisteredListener[]> e : eventchains.entrySet()) {
|
for (Entry<String, RegisteredListener[]> e : eventchains.entrySet()) {
|
||||||
String toadd = "";
|
String toadd = "";
|
||||||
|
|||||||
@@ -306,8 +306,6 @@ public class Backend {
|
|||||||
} else if (player.isSprinting()) {
|
} else if (player.isSprinting()) {
|
||||||
reason = "while sprinting ";
|
reason = "while sprinting ";
|
||||||
max = magic.XZ_SPEED_MAX_SPRINT;
|
max = magic.XZ_SPEED_MAX_SPRINT;
|
||||||
} else {
|
|
||||||
max = magic.XZ_SPEED_MAX;
|
|
||||||
}
|
}
|
||||||
if (x > max || z > max) {
|
if (x > max || z > max) {
|
||||||
int num = this.increment(player, speedViolation, magic.SPEED_MAX);
|
int num = this.increment(player, speedViolation, magic.SPEED_MAX);
|
||||||
@@ -431,7 +429,7 @@ public class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CheckResult checkYAxis(Player player, Distance distance) {
|
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;
|
return PASS;
|
||||||
}
|
}
|
||||||
if (!isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) && !player.isInsideVehicle() && !Utilities.isInWater(player)) {
|
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) {
|
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.
|
// This was a teleport, so we don't care about it.
|
||||||
return PASS;
|
return PASS;
|
||||||
}
|
}
|
||||||
@@ -926,10 +924,6 @@ public class Backend {
|
|||||||
return justAnimated(player);
|
return justAnimated(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean justAnimated(Player player, Entity e) {
|
|
||||||
return justAnimated(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean justAnimated(Player player) {
|
private boolean justAnimated(Player player) {
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
if (animated.containsKey(name)) {
|
if (animated.containsKey(name)) {
|
||||||
|
|||||||
@@ -107,14 +107,10 @@ public class User {
|
|||||||
return goodLocation;
|
return goodLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasGoodLocation() {
|
|
||||||
return goodLocation != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGoodLocation(Location e) {
|
public void setGoodLocation(Location e) {
|
||||||
if (Utilities.cantStandAtExp(e)) { return; }
|
if (Utilities.cantStandAtExp(e) || (e.getBlock().isLiquid() && !Utilities.isFullyInWater(e))) {
|
||||||
|
return;
|
||||||
if (e.getBlock().isLiquid() && !Utilities.isFullyInWater(e)) { return; }
|
}
|
||||||
|
|
||||||
goodLocation = e;
|
goodLocation = e;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
@@ -27,28 +25,39 @@ package net.h31ix.anticheat.metrics;
|
|||||||
* authors and contributors and should not be interpreted as representing official policies,
|
* authors and contributors and should not be interpreted as representing official policies,
|
||||||
* either expressed or implied, of anybody else.
|
* 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.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.Collections;
|
||||||
import org.bukkit.Bukkit;
|
import java.util.HashSet;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import java.util.Iterator;
|
||||||
import org.bukkit.plugin.Plugin;
|
import java.util.LinkedHashSet;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p> The metrics class obtains data about a plugin and submits statistics about it to the metrics backend. </p> <p>
|
||||||
* The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.
|
* Public methods provided by this class: </p>
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* Public methods provided by this class:
|
|
||||||
* </p>
|
|
||||||
* <code>
|
* <code>
|
||||||
* Graph createGraph(String name); <br/>
|
* Graph createGraph(String name); <br/>
|
||||||
* void addCustomData(Metrics.Plotter plotter); <br/>
|
* void addCustomData(BukkitMetrics.Plotter plotter); <br/>
|
||||||
* void start(); <br/>
|
* void start(); <br/>
|
||||||
* </code>
|
* </code>
|
||||||
*/
|
*/
|
||||||
@@ -57,92 +66,102 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* The current revision number
|
* The current revision number
|
||||||
*/
|
*/
|
||||||
private static final int REVISION = 5;
|
private final static int REVISION = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base url of the metrics domain
|
* 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
|
* The url used to report a server's status
|
||||||
*/
|
*/
|
||||||
private static final String REPORT_URL = "/report/%s";
|
private static final String REPORT_URL = "/report/%s";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The file where guid and opt out is stored in
|
* 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 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.
|
|
||||||
*/
|
*/
|
||||||
private static final String CUSTOM_DATA_SEPARATOR = "~~";
|
private static final String CUSTOM_DATA_SEPARATOR = "~~";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interval of time to ping (in minutes)
|
* Interval of time to ping (in minutes)
|
||||||
*/
|
*/
|
||||||
private static final int PING_INTERVAL = 10;
|
private static final int PING_INTERVAL = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin this metrics submits for
|
* The plugin this metrics submits for
|
||||||
*/
|
*/
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All of the custom graphs to submit to metrics
|
* All of the custom graphs to submit to metrics
|
||||||
*/
|
*/
|
||||||
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
|
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default graph, used for addCustomData when you don't want a specific graph
|
* The default graph, used for addCustomData when you don't want a specific graph
|
||||||
*/
|
*/
|
||||||
private final Graph defaultGraph = new Graph("Default");
|
private final Graph defaultGraph = new Graph("Default");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin configuration file
|
* The plugin configuration file
|
||||||
*/
|
*/
|
||||||
private final YamlConfiguration configuration;
|
private final YamlConfiguration configuration;
|
||||||
|
/**
|
||||||
|
* The plugin configuration file
|
||||||
|
*/
|
||||||
|
private final File configurationFile;
|
||||||
/**
|
/**
|
||||||
* Unique server id
|
* Unique server id
|
||||||
*/
|
*/
|
||||||
private final String guid;
|
private final String guid;
|
||||||
|
/**
|
||||||
|
* 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(Plugin plugin) throws IOException {
|
public Metrics(final Plugin plugin) throws IOException {
|
||||||
if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); }
|
if (plugin == null) {
|
||||||
|
throw new IllegalArgumentException("Plugin cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
// load the config
|
// load the config
|
||||||
File file = new File(CONFIG_FILE);
|
configurationFile = getConfigFile();
|
||||||
configuration = YamlConfiguration.loadConfiguration(file);
|
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||||
|
|
||||||
// add some defaults
|
// add some defaults
|
||||||
configuration.addDefault("opt-out", false);
|
configuration.addDefault("opt-out", false);
|
||||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||||
|
configuration.addDefault("debug", false);
|
||||||
|
|
||||||
// Do we need to create the file?
|
// Do we need to create the file?
|
||||||
if (configuration.get("guid", null) == null) {
|
if (configuration.get("guid", null) == null) {
|
||||||
configuration.options().header("http://metrics.griefcraft.com").copyDefaults(true);
|
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
||||||
configuration.save(file);
|
configuration.save(configurationFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the guid then
|
// Load the guid then
|
||||||
guid = configuration.getString("guid");
|
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.
|
* 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
|
* @param name The name of the graph
|
||||||
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
||||||
*/
|
*/
|
||||||
public Graph createGraph(String name) {
|
public Graph createGraph(final String name) {
|
||||||
if (name == null) { throw new IllegalArgumentException("Graph name cannot be null"); }
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("Graph name cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
// Construct the graph object
|
// Construct the graph object
|
||||||
Graph graph = new Graph(name);
|
final Graph graph = new Graph(name);
|
||||||
|
|
||||||
// Now we can add our graph
|
// Now we can add our graph
|
||||||
graphs.add(graph);
|
graphs.add(graph);
|
||||||
@@ -151,13 +170,28 @@ public class Metrics {
|
|||||||
return graph;
|
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
|
* 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) {
|
public void addCustomData(final Plotter plotter) {
|
||||||
if (plotter == null) { throw new IllegalArgumentException("Plotter cannot be null"); }
|
if (plotter == null) {
|
||||||
|
throw new IllegalArgumentException("Plotter cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
// Add the plotter to the graph o/
|
// Add the plotter to the graph o/
|
||||||
defaultGraph.addPlotter(plotter);
|
defaultGraph.addPlotter(plotter);
|
||||||
@@ -167,19 +201,44 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
public boolean start() {
|
||||||
|
synchronized (optOutLock) {
|
||||||
// Did we opt out?
|
// Did we opt out?
|
||||||
if (configuration.getBoolean("opt-out", false)) { return; }
|
if (isOptOut()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is metrics already running?
|
||||||
|
if (task != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Begin hitting the server with glorious data
|
// Begin hitting the server with glorious data
|
||||||
plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
|
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
private boolean firstPost = true;
|
private boolean firstPost = true;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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,
|
// 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
|
// it is not a interval ping, so it evaluates to FALSE
|
||||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||||
@@ -189,57 +248,176 @@ public class Metrics {
|
|||||||
// Each post thereafter will be a ping
|
// Each post thereafter will be a ping
|
||||||
firstPost = false;
|
firstPost = false;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("[Metrics] " + e.getMessage());
|
if (debug) {
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, PING_INTERVAL * 1200);
|
}, 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
|
* Generic method that posts a plugin to the metrics website
|
||||||
*/
|
*/
|
||||||
private void postPlugin(boolean isPing) throws IOException {
|
private void postPlugin(final boolean isPing) throws IOException {
|
||||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
// Server software specific section
|
||||||
PluginDescriptionFile description = plugin.getDescription();
|
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
|
// 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 we're pinging, append it
|
||||||
if (isPing) {
|
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
|
// Acquire a lock on the graphs, which lets us make the assumption we also lock everything
|
||||||
// inside of the graph (e.g plotters)
|
// inside of the graph (e.g plotters)
|
||||||
synchronized (graphs) {
|
synchronized (graphs) {
|
||||||
Iterator<Graph> iter = graphs.iterator();
|
final Iterator<Graph> iter = graphs.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Graph graph = iter.next();
|
final 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.
|
|
||||||
for (Plotter plotter : graph.getPlotters()) {
|
for (Plotter plotter : graph.getPlotters()) {
|
||||||
// The key name to send to the metrics server
|
// The key name to send to the metrics server
|
||||||
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
|
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
|
||||||
// Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
|
// 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
|
// The value to send, which for the foreseeable future is just the string
|
||||||
// value of plotter.getValue()
|
// value of plotter.getValue()
|
||||||
String value = Integer.toString(plotter.getValue());
|
final String value = Integer.toString(plotter.getValue());
|
||||||
|
|
||||||
// Add it to the http post data :)
|
// Add it to the http post data :)
|
||||||
data += encodeDataPair(key, value);
|
encodeDataPair(data, key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the url
|
// 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
|
// Connect to the website
|
||||||
URLConnection connection;
|
URLConnection connection;
|
||||||
@@ -255,28 +433,28 @@ public class Metrics {
|
|||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
// Write the data
|
// Write the data
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
||||||
writer.write(data);
|
writer.write(data.toString());
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
// Now read the response
|
// Now read the response
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
String response = reader.readLine();
|
final String response = reader.readLine();
|
||||||
|
|
||||||
// close resources
|
// close resources
|
||||||
writer.close();
|
writer.close();
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
if (response.startsWith("ERR")) {
|
if (response == null || response.startsWith("ERR")) {
|
||||||
throw new IOException(response); // Throw the exception
|
throw new IOException(response); //Throw the exception
|
||||||
} else {
|
} else {
|
||||||
// Is this the first update this hour?
|
// Is this the first update this hour?
|
||||||
if (response.contains("OK This is your first update this hour")) {
|
if (response.contains("OK This is your first update this hour")) {
|
||||||
synchronized (graphs) {
|
synchronized (graphs) {
|
||||||
Iterator<Graph> iter = graphs.iterator();
|
final Iterator<Graph> iter = graphs.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Graph graph = iter.next();
|
final Graph graph = iter.next();
|
||||||
|
|
||||||
for (Plotter plotter : graph.getPlotters()) {
|
for (Plotter plotter : graph.getPlotters()) {
|
||||||
plotter.reset();
|
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
|
* 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() {
|
private boolean isMineshafterPresent() {
|
||||||
try {
|
try {
|
||||||
@@ -303,28 +480,29 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first key/value pair
|
||||||
* 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:
|
* MUST be included manually, e.g:</p>
|
||||||
* </p>
|
|
||||||
* <code>
|
* <code>
|
||||||
* 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());
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param key
|
* @param buffer the stringbuilder to append the data pair onto
|
||||||
* @param value
|
* @param key the key value
|
||||||
* @return
|
* @param value the value
|
||||||
*/
|
*/
|
||||||
private static String encodeDataPair(String key, String value) throws UnsupportedEncodingException {
|
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException {
|
||||||
return '&' + encode(key) + '=' + encode(value);
|
buffer.append('&').append(encode(key)).append('=').append(encode(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode text as UTF-8
|
* Encode text as UTF-8
|
||||||
*
|
*
|
||||||
* @param text
|
* @param text the text to encode
|
||||||
* @return
|
* @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");
|
return URLEncoder.encode(text, "UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,23 +512,23 @@ public class Metrics {
|
|||||||
public static class Graph {
|
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;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The set of plotters that are contained within this graph
|
* The set of plotters that are contained within this graph
|
||||||
*/
|
*/
|
||||||
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
||||||
|
|
||||||
private Graph(String name) {
|
private Graph(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the graph's name
|
* Gets the graph's name
|
||||||
*
|
*
|
||||||
* @return
|
* @return the Graph's name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@@ -359,25 +537,25 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Add a plotter to the graph, which will be used to plot entries
|
* 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);
|
plotters.add(plotter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a plotter from the graph
|
* 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);
|
plotters.remove(plotter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an <strong>unmodifiable</strong> set of the plotter objects in the graph
|
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
|
||||||
*
|
*
|
||||||
* @return
|
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
||||||
*/
|
*/
|
||||||
public Set<Plotter> getPlotters() {
|
public Set<Plotter> getPlotters() {
|
||||||
return Collections.unmodifiableSet(plotters);
|
return Collections.unmodifiableSet(plotters);
|
||||||
@@ -389,13 +567,20 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(final Object object) {
|
||||||
if (!(object instanceof Graph)) { return false; }
|
if (!(object instanceof Graph)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Graph graph = (Graph) object;
|
final Graph graph = (Graph) object;
|
||||||
return graph.name.equals(name);
|
return graph.name.equals(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
|
||||||
|
*/
|
||||||
|
protected void onOptOut() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -418,16 +603,18 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Construct a plotter with a specific plot name
|
* 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;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current value for the plotted point
|
* 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
|
* @return the current value for the point to be plotted.
|
||||||
*/
|
*/
|
||||||
public abstract int getValue();
|
public abstract int getValue();
|
||||||
|
|
||||||
@@ -448,17 +635,17 @@ public class Metrics {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getColumnName().hashCode() + getValue();
|
return getColumnName().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(final Object object) {
|
||||||
if (!(object instanceof Plotter)) { return false; }
|
if (!(object instanceof Plotter)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Plotter plotter = (Plotter) object;
|
final Plotter plotter = (Plotter) object;
|
||||||
return plotter.name.equals(name) && plotter.getValue() == getValue();
|
return plotter.name.equals(name) && plotter.getValue() == getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -258,18 +258,6 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getWorldsExempt() {
|
|
||||||
return exemptWorlds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getConfigFile() {
|
|
||||||
return configFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getLevelFile() {
|
|
||||||
return levelFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileConfiguration getMagic() {
|
public FileConfiguration getMagic() {
|
||||||
return magic;
|
return magic;
|
||||||
}
|
}
|
||||||
@@ -305,8 +293,4 @@ public class Configuration {
|
|||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMainConfigurationDump() {
|
|
||||||
return config.saveToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.
|
* The minimum time it should have taken for the player to travel X steps; Type=system; +Leniency=Decrease.
|
||||||
*/
|
*/
|
||||||
public final long TIMER_TIMEMIN;
|
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 defaults;
|
||||||
private FileConfiguration magic;
|
private FileConfiguration magic;
|
||||||
@@ -414,6 +418,7 @@ public class Magic {
|
|||||||
INVENTORY_TIMEMIN = getInt("INVENTORY_TIMEMIN");
|
INVENTORY_TIMEMIN = getInt("INVENTORY_TIMEMIN");
|
||||||
TIMER_STEP_CHECK = getInt("TIMER_STEP_CHECK");
|
TIMER_STEP_CHECK = getInt("TIMER_STEP_CHECK");
|
||||||
TIMER_TIMEMIN = getLong("TIMER_TIMEMIN");
|
TIMER_TIMEMIN = getLong("TIMER_TIMEMIN");
|
||||||
|
TELEPORT_MIN = getLong("TELEPORT_MIN");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getInt(String path) {
|
private int getInt(String path) {
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public class XRayTracker {
|
|||||||
float p = (float) Math.pow(POWER, 1);
|
float p = (float) Math.pow(POWER, 1);
|
||||||
number *= p;
|
number *= p;
|
||||||
float tmp = Math.round(number);
|
float tmp = Math.round(number);
|
||||||
return (float) tmp / p;
|
return tmp / p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(String player) {
|
public void reset(String player) {
|
||||||
|
|||||||
@@ -75,3 +75,4 @@ INVENTORY_CHECK: 10
|
|||||||
INVENTORY_TIMEMIN: 50
|
INVENTORY_TIMEMIN: 50
|
||||||
TIMER_STEP_CHECK: 50
|
TIMER_STEP_CHECK: 50
|
||||||
TIMER_TIMEMIN: 2000
|
TIMER_TIMEMIN: 2000
|
||||||
|
TELEPORT_MIN: 400
|
||||||
Reference in new issue
Block a user