mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-04 14:38:47 +00:00
Test commit please ignore
Formatting for everything
This commit is contained in:
1 parent
8a5d531857
commit
f00130f3f7
17 files changed
+219
-119
No files matched your search
@@ -31,7 +31,6 @@ import org.bukkit.entity.Player;
|
||||
* Developer's interface for all things AntiCheat.
|
||||
*/
|
||||
|
||||
|
||||
public class AnticheatAPI
|
||||
{
|
||||
private static CheckManager chk = Anticheat.getManager().getCheckManager();
|
||||
@@ -43,7 +42,8 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Start running a certain check
|
||||
*
|
||||
* @param type Check to start watching for
|
||||
* @param type
|
||||
* Check to start watching for
|
||||
*/
|
||||
public static void activateCheck(CheckType type)
|
||||
{
|
||||
@@ -53,7 +53,8 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Stop running a certain check
|
||||
*
|
||||
* @param type Check to stop watching for
|
||||
* @param type
|
||||
* Check to stop watching for
|
||||
*/
|
||||
public static void deactivateCheck(CheckType type)
|
||||
{
|
||||
@@ -63,7 +64,8 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Find out if a check is currently being watched for
|
||||
*
|
||||
* @param type Type to check
|
||||
* @param type
|
||||
* Type to check
|
||||
* @return true if plugin is watching for this check
|
||||
*/
|
||||
public static boolean isActive(CheckType type)
|
||||
@@ -74,8 +76,10 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Allow a player to skip a certain check
|
||||
*
|
||||
* @param player Player to stop watching
|
||||
* @param type Check to stop watching for
|
||||
* @param player
|
||||
* Player to stop watching
|
||||
* @param type
|
||||
* Check to stop watching for
|
||||
*/
|
||||
public static void exemptPlayer(Player player, CheckType type)
|
||||
{
|
||||
@@ -85,8 +89,10 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Stop allowing a player to skip a certain check
|
||||
*
|
||||
* @param player Player to start watching
|
||||
* @param type Check to start watching for
|
||||
* @param player
|
||||
* Player to start watching
|
||||
* @param type
|
||||
* Check to start watching for
|
||||
*/
|
||||
public static void unexemptPlayer(Player player, CheckType type)
|
||||
{
|
||||
@@ -96,8 +102,10 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Find out if a player is currently exempt from a certain check
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param type Type to check
|
||||
* @param player
|
||||
* Player to check
|
||||
* @param type
|
||||
* Type to check
|
||||
* @return true if plugin is ignoring this check on this player
|
||||
*/
|
||||
public static boolean isExempt(Player player, CheckType type)
|
||||
@@ -106,11 +114,16 @@ public class AnticheatAPI
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if a check will occur for a player. This checks if they are being tracked, the check is active, the player isn't exempt from the check, and the player doesn't have override permission.
|
||||
* Find out if a check will occur for a player. This checks if they are
|
||||
* being tracked, the check is active, the player isn't exempt from the
|
||||
* check, and the player doesn't have override permission.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param type Type to check
|
||||
* @return true if plugin will check this player, and that all things allow it to happen.
|
||||
* @param player
|
||||
* Player to check
|
||||
* @param type
|
||||
* Type to check
|
||||
* @return true if plugin will check this player, and that all things allow
|
||||
* it to happen.
|
||||
*/
|
||||
public boolean willCheck(Player player, CheckType type)
|
||||
{
|
||||
@@ -120,9 +133,11 @@ public class AnticheatAPI
|
||||
//PlayerManager API
|
||||
|
||||
/**
|
||||
* Get a player's integer hack level (0-19 = Low, 20-49 = Medium, 50-60 = High)
|
||||
* Get a player's integer hack level (0-19 = Low, 20-49 = Medium, 50-60 =
|
||||
* High)
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param player
|
||||
* Player to check
|
||||
* @return player's hack level
|
||||
*/
|
||||
public static int getLevel(Player player)
|
||||
@@ -137,8 +152,10 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Set a player's hack level (Min = 0, Max = 60)
|
||||
*
|
||||
* @param player Player to set
|
||||
* @param level Level to set to
|
||||
* @param player
|
||||
* Player to set
|
||||
* @param level
|
||||
* Level to set to
|
||||
*/
|
||||
public static void setLevel(Player player, int level)
|
||||
{
|
||||
@@ -150,7 +167,8 @@ public class AnticheatAPI
|
||||
/**
|
||||
* Find out if a player is detected as using xray hacks (on any ore)
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param player
|
||||
* Player to check
|
||||
* @return true if the player has any xray anomalies.
|
||||
*/
|
||||
public static boolean isXrayer(Player player)
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.entity.*;
|
||||
|
||||
|
||||
public class EntityListener extends EventListener
|
||||
{
|
||||
private final Backend backend = getBackend();
|
||||
|
||||
@@ -114,7 +114,8 @@ public class EventListener implements Listener
|
||||
return BACKEND;
|
||||
}
|
||||
|
||||
public static PlayerManager getPlayerManager() {
|
||||
public static PlayerManager getPlayerManager()
|
||||
{
|
||||
return PLAYER_MANAGER;
|
||||
}
|
||||
|
||||
|
||||
@@ -283,6 +283,7 @@ public class PlayerListener extends EventListener
|
||||
log("tried avoid fall damage.", player, CheckType.NOFALL);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void checkSpeed(PlayerMoveEvent event)
|
||||
{
|
||||
|
||||
@@ -63,7 +63,9 @@ public class AnticheatManager
|
||||
}
|
||||
fileHandler = new FileHandler(plugin.getDataFolder() + "/log/anticheat.log", true);
|
||||
fileHandler.setFormatter(new FileFormatter());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
FILE_LOGGER.setUseParentHandlers(false);
|
||||
@@ -116,6 +118,7 @@ public class AnticheatManager
|
||||
{
|
||||
return backend;
|
||||
}
|
||||
|
||||
public static void close()
|
||||
{
|
||||
fileHandler.close();
|
||||
|
||||
@@ -642,8 +642,7 @@ public class Backend
|
||||
lastZeroHitPlace.put(name, lastZeroHitPlace.get(name) + 1);
|
||||
}
|
||||
}
|
||||
if(thisTime < FASTPLACE_TIMEMAX && lastTime < FASTPLACE_TIMEMAX
|
||||
&& nocheck && lastZeroHitPlace.get(name) > FASTPLACE_ZEROLIMIT)
|
||||
if (thisTime < FASTPLACE_TIMEMAX && lastTime < FASTPLACE_TIMEMAX && nocheck && lastZeroHitPlace.get(name) > FASTPLACE_ZEROLIMIT)
|
||||
{
|
||||
lastBlockPlaceTime.put(name, (time - last));
|
||||
lastBlockPlaced.put(name, time);
|
||||
@@ -784,7 +783,8 @@ public class Backend
|
||||
if (velocitytrack.containsKey(player.getName()))
|
||||
{
|
||||
velocitytrack.put(player.getName(), velocitytrack.get(player.getName()) + 1);
|
||||
if(velocitytrack.get(player.getName()) > VELOCITY_MAXTIMES) {
|
||||
if (velocitytrack.get(player.getName()) > VELOCITY_MAXTIMES)
|
||||
{
|
||||
velocitized.put(player.getName(), System.currentTimeMillis() + VELOCITY_PREVENT);
|
||||
micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable()
|
||||
{
|
||||
@@ -956,6 +956,7 @@ public class Backend
|
||||
}
|
||||
}, time);
|
||||
}
|
||||
|
||||
private void checkChatLevel(Player player, int amount)
|
||||
{
|
||||
if (amount >= CHAT_WARN_LEVEL)
|
||||
@@ -990,6 +991,7 @@ public class Backend
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void increment(Player player, Map<String, Integer> map, int num)
|
||||
{
|
||||
String name = player.getName();
|
||||
|
||||
@@ -26,7 +26,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The manager that AntiCheat will check with to see if it should watch certain checks and certain players.
|
||||
* The manager that AntiCheat will check with to see if it should watch certain
|
||||
* checks and certain players.
|
||||
*/
|
||||
|
||||
public class CheckManager
|
||||
@@ -86,10 +87,7 @@ public class CheckManager
|
||||
|
||||
public boolean willCheck(Player player, CheckType type)
|
||||
{
|
||||
return isActive(type)
|
||||
&& manager.getConfiguration().checkInWorld(player.getWorld())
|
||||
&& !isExempt(player, type)
|
||||
&& !type.checkPermission(player);
|
||||
return isActive(type) && manager.getConfiguration().checkInWorld(player.getWorld()) && !isExempt(player, type) && !type.checkPermission(player);
|
||||
}
|
||||
|
||||
public int getExempt()
|
||||
|
||||
@@ -23,13 +23,11 @@ import java.util.Map;
|
||||
import net.h31ix.anticheat.Permission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* All the types of checks and their corresponding permission nodes.
|
||||
*/
|
||||
|
||||
|
||||
public enum CheckType
|
||||
{
|
||||
ZOMBE_FLY(Permission.CHECK_ZOMBE_FLY),
|
||||
|
||||
@@ -30,11 +30,13 @@ public class Distance
|
||||
l2 = from;
|
||||
}
|
||||
|
||||
public double fromY() {
|
||||
public double fromY()
|
||||
{
|
||||
return l2.getY();
|
||||
}
|
||||
|
||||
public double toY() {
|
||||
public double toY()
|
||||
{
|
||||
return l1.getY();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The manager that AntiCheat will use to monitor player's hack levels and to execute events that the admin has set
|
||||
* The manager that AntiCheat will use to monitor player's hack levels and to
|
||||
* execute events that the admin has set
|
||||
*/
|
||||
|
||||
public class PlayerManager
|
||||
@@ -43,7 +44,8 @@ public class PlayerManager
|
||||
private static final int LEVEL_MAX = 60;
|
||||
private static final int LEVEL_BOOST = 5;
|
||||
|
||||
public PlayerManager(AnticheatManager instance) {
|
||||
public PlayerManager(AnticheatManager instance)
|
||||
{
|
||||
config = instance.getConfiguration();
|
||||
lang = config.getLang();
|
||||
}
|
||||
@@ -53,6 +55,7 @@ public class PlayerManager
|
||||
execute("Medium", player);
|
||||
Utilities.alert(formatArray(lang.getMediumAlert(), player, ChatColor.YELLOW));
|
||||
}
|
||||
|
||||
private static void reactHigh(Player player)
|
||||
{
|
||||
execute("High", player);
|
||||
@@ -164,6 +167,7 @@ public class PlayerManager
|
||||
player.getServer().broadcastMessage(formatString(lang.getBanBroadcast(), player, ChatColor.RED));
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] formatArray(String[] array, Player player, ChatColor color)
|
||||
{
|
||||
for (int i = 0; i < array.length; i++)
|
||||
@@ -172,6 +176,7 @@ public class PlayerManager
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static String formatString(String string, Player player, ChatColor color)
|
||||
{
|
||||
return color + string.replaceAll("&player", ChatColor.WHITE + player.getName() + color);
|
||||
|
||||
@@ -41,7 +41,8 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.
|
||||
* The metrics class obtains data about a plugin and submits statistics about it
|
||||
* to the metrics backend.
|
||||
* </p>
|
||||
* <p>
|
||||
* Public methods provided by this class:
|
||||
@@ -52,7 +53,8 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
* void start(); <br/>
|
||||
* </code>
|
||||
*/
|
||||
public class Metrics {
|
||||
public class Metrics
|
||||
{
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
@@ -75,8 +77,8 @@ public class Metrics {
|
||||
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 = "~~";
|
||||
|
||||
@@ -96,7 +98,8 @@ public class Metrics {
|
||||
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");
|
||||
|
||||
@@ -110,8 +113,10 @@ public class Metrics {
|
||||
*/
|
||||
private final String guid;
|
||||
|
||||
public Metrics(Plugin plugin) throws IOException {
|
||||
if (plugin == null) {
|
||||
public Metrics(Plugin plugin) throws IOException
|
||||
{
|
||||
if (plugin == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
}
|
||||
|
||||
@@ -126,7 +131,8 @@ public class Metrics {
|
||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
|
||||
// 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.save(file);
|
||||
}
|
||||
@@ -136,14 +142,18 @@ public class Metrics {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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) {
|
||||
if (name == null) {
|
||||
public Graph createGraph(String name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Graph name cannot be null");
|
||||
}
|
||||
|
||||
@@ -162,8 +172,10 @@ public class Metrics {
|
||||
*
|
||||
* @param plotter
|
||||
*/
|
||||
public void addCustomData(Plotter plotter) {
|
||||
if (plotter == null) {
|
||||
public void addCustomData(Plotter plotter)
|
||||
{
|
||||
if (plotter == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Plotter cannot be null");
|
||||
}
|
||||
|
||||
@@ -175,23 +187,29 @@ 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.
|
||||
*/
|
||||
public void start() {
|
||||
public void start()
|
||||
{
|
||||
// Did we opt out?
|
||||
if (configuration.getBoolean("opt-out", false)) {
|
||||
if (configuration.getBoolean("opt-out", false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
|
||||
plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable()
|
||||
{
|
||||
private boolean firstPost = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
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!
|
||||
@@ -200,7 +218,9 @@ public class Metrics {
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println("[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -210,35 +230,36 @@ public class Metrics {
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*/
|
||||
private void postPlugin(boolean isPing) throws IOException {
|
||||
private void postPlugin(boolean isPing) throws IOException
|
||||
{
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
|
||||
// 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));
|
||||
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));
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing) {
|
||||
if (isPing)
|
||||
{
|
||||
data += encodeDataPair("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) {
|
||||
synchronized (graphs)
|
||||
{
|
||||
Iterator<Graph> iter = graphs.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
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.
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
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
|
||||
@@ -262,9 +283,12 @@ public class Metrics {
|
||||
|
||||
// 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()) {
|
||||
if (isMineshafterPresent())
|
||||
{
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
connection = url.openConnection();
|
||||
}
|
||||
|
||||
@@ -283,18 +307,25 @@ public class Metrics {
|
||||
writer.close();
|
||||
reader.close();
|
||||
|
||||
if (response.startsWith("ERR")) {
|
||||
if (response.startsWith("ERR"))
|
||||
{
|
||||
throw new IOException(response); //Throw the exception
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Is this the first update this hour?
|
||||
if (response.contains("OK This is your first update this hour")) {
|
||||
synchronized (graphs) {
|
||||
if (response.contains("OK This is your first update this hour"))
|
||||
{
|
||||
synchronized (graphs)
|
||||
{
|
||||
Iterator<Graph> iter = graphs.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Graph graph = iter.next();
|
||||
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
for (Plotter plotter : graph.getPlotters())
|
||||
{
|
||||
plotter.reset();
|
||||
}
|
||||
}
|
||||
@@ -305,22 +336,29 @@ public class Metrics {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
private boolean isMineshafterPresent()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>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:</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 MUST be included manually, e.g:
|
||||
* </p>
|
||||
* <code>
|
||||
* String httpData = encode("guid") + '=' + encode("1234") + encodeDataPair("authors") + "..";
|
||||
* </code>
|
||||
@@ -329,7 +367,8 @@ public class Metrics {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private static String encodeDataPair(String key, String value) throws UnsupportedEncodingException {
|
||||
private static String encodeDataPair(String key, String value) throws UnsupportedEncodingException
|
||||
{
|
||||
return '&' + encode(key) + '=' + encode(value);
|
||||
}
|
||||
|
||||
@@ -339,18 +378,20 @@ public class Metrics {
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String encode(String text) throws UnsupportedEncodingException {
|
||||
private static String encode(String text) throws UnsupportedEncodingException
|
||||
{
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom graph on the website
|
||||
*/
|
||||
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;
|
||||
|
||||
@@ -359,7 +400,8 @@ public class Metrics {
|
||||
*/
|
||||
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
||||
|
||||
private Graph(String name) {
|
||||
private Graph(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -368,7 +410,8 @@ public class Metrics {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -377,7 +420,8 @@ public class Metrics {
|
||||
*
|
||||
* @param plotter
|
||||
*/
|
||||
public void addPlotter(Plotter plotter) {
|
||||
public void addPlotter(Plotter plotter)
|
||||
{
|
||||
plotters.add(plotter);
|
||||
}
|
||||
|
||||
@@ -386,7 +430,8 @@ public class Metrics {
|
||||
*
|
||||
* @param plotter
|
||||
*/
|
||||
public void removePlotter(Plotter plotter) {
|
||||
public void removePlotter(Plotter plotter)
|
||||
{
|
||||
plotters.remove(plotter);
|
||||
}
|
||||
|
||||
@@ -395,18 +440,22 @@ public class Metrics {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<Plotter> getPlotters() {
|
||||
public Set<Plotter> getPlotters()
|
||||
{
|
||||
return Collections.unmodifiableSet(plotters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode()
|
||||
{
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Graph)) {
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if (!(object instanceof Graph))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -419,7 +468,8 @@ public class Metrics {
|
||||
/**
|
||||
* Interface used to collect custom data for a plugin
|
||||
*/
|
||||
public static abstract class Plotter {
|
||||
public static abstract class Plotter
|
||||
{
|
||||
|
||||
/**
|
||||
* The plot's name
|
||||
@@ -429,7 +479,8 @@ public class Metrics {
|
||||
/**
|
||||
* Construct a plotter with the default plot name
|
||||
*/
|
||||
public Plotter() {
|
||||
public Plotter()
|
||||
{
|
||||
this("Default");
|
||||
}
|
||||
|
||||
@@ -438,7 +489,8 @@ public class Metrics {
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public Plotter(String name) {
|
||||
public Plotter(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -454,24 +506,29 @@ public class Metrics {
|
||||
*
|
||||
* @return the plotted point's column name
|
||||
*/
|
||||
public String getColumnName() {
|
||||
public String getColumnName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the website graphs have been updated
|
||||
*/
|
||||
public void reset() {
|
||||
public void reset()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode()
|
||||
{
|
||||
return getColumnName().hashCode() + getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Plotter)) {
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if (!(object instanceof Plotter))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ package net.h31ix.anticheat.util;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class ConsoleFormatter extends Formatter {
|
||||
public class ConsoleFormatter extends Formatter
|
||||
{
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record)
|
||||
|
||||
@@ -24,22 +24,18 @@ import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class FileFormatter extends Formatter {
|
||||
public class FileFormatter extends Formatter
|
||||
{
|
||||
|
||||
private static final DateFormat format = new SimpleDateFormat("h:mm:ss");
|
||||
private static final String lineSep = System.getProperty("line.separator");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
public String format(LogRecord record)
|
||||
{
|
||||
if (record.getMessage().startsWith("[AntiCheat]"))
|
||||
{
|
||||
StringBuilder output = new StringBuilder()
|
||||
.append("[")
|
||||
.append(record.getLevel()).append('|')
|
||||
.append(format.format(new Date(record.getMillis())))
|
||||
.append("]: ")
|
||||
.append(record.getMessage()).append(' ')
|
||||
.append(lineSep);
|
||||
StringBuilder output = new StringBuilder().append("[").append(record.getLevel()).append('|').append(format.format(new Date(record.getMillis()))).append("]: ").append(record.getMessage()).append(' ').append(lineSep);
|
||||
return output.toString();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -38,6 +38,7 @@ public final class Utilities
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void alert(String[] message)
|
||||
{
|
||||
for (String msg : message)
|
||||
@@ -52,40 +53,49 @@ public final class Utilities
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean cantStandAt(Block block)
|
||||
{
|
||||
return !canStand(block) && cantStandClose(block) && cantStandFar(block);
|
||||
}
|
||||
|
||||
public static boolean cantStandClose(Block block)
|
||||
{
|
||||
return !canStand(block.getRelative(BlockFace.NORTH)) && !canStand(block.getRelative(BlockFace.EAST)) && !canStand(block.getRelative(BlockFace.SOUTH)) && !canStand(block.getRelative(BlockFace.WEST));
|
||||
}
|
||||
|
||||
public static boolean cantStandFar(Block block)
|
||||
{
|
||||
return !canStand(block.getRelative(BlockFace.NORTH_WEST)) && !canStand(block.getRelative(BlockFace.NORTH_EAST)) && !canStand(block.getRelative(BlockFace.SOUTH_WEST)) && !canStand(block.getRelative(BlockFace.SOUTH_EAST));
|
||||
}
|
||||
|
||||
public static boolean canStand(Block block)
|
||||
{
|
||||
return !(block.isLiquid() || block.getType() == Material.AIR);
|
||||
}
|
||||
|
||||
public static boolean isInstantBreak(Material m)
|
||||
{
|
||||
return INSTANT_BREAK.contains(m);
|
||||
}
|
||||
|
||||
public static boolean isFood(Material m)
|
||||
{
|
||||
return FOOD.contains(m);
|
||||
}
|
||||
|
||||
public static boolean sprintFly(Player player)
|
||||
{
|
||||
return player.isSprinting() || player.isFlying();
|
||||
}
|
||||
|
||||
public static boolean isOnLilyPad(Player player)
|
||||
{
|
||||
Block block = player.getLocation().getBlock();
|
||||
Material lily = Material.WATER_LILY;
|
||||
return block.getType() == lily || block.getRelative(BlockFace.NORTH).getType() == lily || block.getRelative(BlockFace.SOUTH).getType() == lily || block.getRelative(BlockFace.EAST).getType() == lily || block.getRelative(BlockFace.WEST).getType() == lily;
|
||||
}
|
||||
|
||||
public static boolean isUsingMcMMOAbility(Player player)
|
||||
{
|
||||
boolean b = false;
|
||||
@@ -98,22 +108,27 @@ public final class Utilities
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
public static boolean isSubmersed(Player player)
|
||||
{
|
||||
return player.getLocation().getBlock().isLiquid() && player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid();
|
||||
}
|
||||
|
||||
public static boolean isInWater(Player player)
|
||||
{
|
||||
return player.getLocation().getBlock().isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.DOWN).isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid();
|
||||
}
|
||||
|
||||
public static boolean isOnLadder(Player player)
|
||||
{
|
||||
return player.getLocation().getBlock().getType() == Material.VINE || player.getLocation().getBlock().getType() == Material.LADDER;
|
||||
}
|
||||
|
||||
public static boolean isInt(String string)
|
||||
{
|
||||
boolean x = false;
|
||||
try {
|
||||
try
|
||||
{
|
||||
Integer.parseInt(string);
|
||||
x = true;
|
||||
}
|
||||
@@ -122,6 +137,7 @@ public final class Utilities
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
INSTANT_BREAK.add(Material.RED_MUSHROOM);
|
||||
|
||||
@@ -28,7 +28,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
public class XRayListener implements Listener {
|
||||
public class XRayListener implements Listener
|
||||
{
|
||||
private XRayTracker tracker = Anticheat.getManager().getXRayTracker();
|
||||
private Configuration config = Anticheat.getManager().getConfiguration();
|
||||
private CheckManager checkManager = Anticheat.getManager().getCheckManager();
|
||||
|
||||
@@ -20,7 +20,8 @@ package net.h31ix.anticheat.xray;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class XRayStats {
|
||||
public class XRayStats
|
||||
{
|
||||
private static final int DIVISOR = 100;
|
||||
private double t = 1;
|
||||
private double d = 0;
|
||||
|
||||
@@ -25,7 +25,8 @@ import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class XRayTracker {
|
||||
public class XRayTracker
|
||||
{
|
||||
private Map<String, Integer> diamond = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> gold = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> iron = new HashMap<String, Integer>();
|
||||
|
||||
Reference in new issue
Block a user