From 7a95b233677612b6bf69027f31b6ecab305e32de Mon Sep 17 00:00:00 2001 From: Super Spy Date: Mon, 21 May 2012 20:05:53 -0500 Subject: [PATCH] Hey guys, i'm invading @H31IX's Repository! --- .gitignore | 6 +- README.md | 58 +- pom.xml | 136 +- .../java/net/h31ix/anticheat/Anticheat.java | 674 ++++----- .../net/h31ix/anticheat/CommandHandler.java | 670 ++++----- .../net/h31ix/anticheat/Configuration.java | 440 +++--- .../h31ix/anticheat/event/BlockListener.java | 240 ++-- .../h31ix/anticheat/event/EntityListener.java | 322 ++--- .../h31ix/anticheat/event/EventListener.java | 244 ++-- .../h31ix/anticheat/event/PlayerListener.java | 490 +++---- .../anticheat/event/VehicleListener.java | 94 +- .../anticheat/manage/AnticheatManager.java | 178 +-- .../net/h31ix/anticheat/manage/Backend.java | 1248 ++++++++--------- .../h31ix/anticheat/manage/CheckManager.java | 178 +-- .../net/h31ix/anticheat/manage/CheckType.java | 126 +- .../net/h31ix/anticheat/manage/Distance.java | 92 +- .../h31ix/anticheat/manage/PlayerManager.java | 322 ++--- .../net/h31ix/anticheat/manage/Utilities.java | 276 ++-- .../net/h31ix/anticheat/metrics/Metrics.java | 988 ++++++------- .../h31ix/anticheat/xray/XRayListener.java | 164 +-- .../net/h31ix/anticheat/xray/XRayStats.java | 218 +-- .../net/h31ix/anticheat/xray/XRayTracker.java | 364 ++--- src/main/resources/config.yml | 36 +- src/main/resources/plugin.yml | 24 +- 24 files changed, 3794 insertions(+), 3794 deletions(-) diff --git a/.gitignore b/.gitignore index 18e9d77..fcc2770 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/target/ -/bin/ -/.settings/ +/target/ +/bin/ +/.settings/ /.* \ No newline at end of file diff --git a/README.md b/README.md index 68887b8..1e1c014 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,30 @@ -AntiCheat -============= - -Stop hackers and cheaters in their tracks! - -Usage -------- -Simply drag and drop the plugin into your Plugins folder. Optional configuration and permissions are avaliable: - -http://dev.bukkit.org/server-mods/anticheat/pages/configuration/ - -http://dev.bukkit.org/server-mods/anticheat/pages/permissions/ - -Developer stuff: -------- -API Usage: http://dev.bukkit.org/server-mods/anticheat/pages/api-documentation/ - -Bug Reporting/Support/Questions ------------- - -Feel free to leave a DETAILED comment describing the problem, the steps you take to re-create the problem, the result you got, and the result you EXPECTED to get on my BukkitDev page (see below). If you do that I'll be sure to reply back and take a look at the bug. -I'm also around a lot in IRC. Feel free to join me in #anticheat on irc.esper.net and ping me to report a game-breaking bug, or just to ask questions, get support, etc. - -Resources -------- -BukkitDev --- http://dev.bukkit.org/server-mods/anticheat/ - -Jenkins (Downloads) --- http://ci.h31ix.net/job/AntiCheat/ - +AntiCheat +============= + +Stop heckers and cheaters in their tracks! + +Usage +------- +Simply drag and drop the plugin into your Plugins folder. Optional configuration and permissions are avaliable: + +http://dev.bukkit.org/server-mods/anticheat/pages/configuration/ + +http://dev.bukkit.org/server-mods/anticheat/pages/permissions/ + +Developer stuff: +------- +API Usage: http://dev.bukkit.org/server-mods/anticheat/pages/api-documentation/ + +Bug Reporting/Support/Questions +------------ + +Feel free to leave a DETAILED comment describing the problem, the steps you take to re-create the problem, the result you got, and the result you EXPECTED to get on my BukkitDev page (see below). If you do that I'll be sure to reply back and take a look at the bug. +I'm also around a lot in IRC. Feel free to join me in #anticheat on irc.esper.net and ping me to report a game-breaking bug, or just to ask questions, get support, etc. + +Resources +------- +BukkitDev --- http://dev.bukkit.org/server-mods/anticheat/ + +Jenkins (Downloads) --- http://ci.h31ix.net/job/AntiCheat/ + Latest version download: http://bukget.org/api/plugin/anticheat/latest/download \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0be1f71..35bf6f8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,69 +1,69 @@ - - 4.0.0 - net.h31ix.anticheat - AntiCheat - 1.1-PRE - AntiCheat - http://H31IX.NET/ - - - bukkit-repo - http://repo.bukkit.org/content/repositories/releases/ - - - - ${basedir}/src/main/java - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.6 - 1.6 - - - - AntiCheat - - - . - true - ${basedir}/src/main/resources - - plugin.yml - config.yml - - - - - - - org.bukkit - craftbukkit - 1.2.5-R2.0 - jar - compile - - - org.bukkit - bukkit - 1.2.5-R2.0 - jar - compile - - - com.google.guava - guava - 12.0 - jar - compile - - - jsr305 - com.google.code.findbugs - - - - + + 4.0.0 + net.h31ix.anticheat + AntiCheat + 1.1-PRE + AntiCheat + http://H31IX.NET/ + + + bukkit-repo + http://repo.bukkit.org/content/repositories/releases/ + + + + ${basedir}/src/main/java + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + AntiCheat + + + . + true + ${basedir}/src/main/resources + + plugin.yml + config.yml + + + + + + + org.bukkit + craftbukkit + 1.2.5-R2.0 + jar + compile + + + org.bukkit + bukkit + 1.2.5-R2.0 + jar + compile + + + com.google.guava + guava + 12.0 + jar + compile + + + jsr305 + com.google.code.findbugs + + + + \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/Anticheat.java b/src/main/java/net/h31ix/anticheat/Anticheat.java index 404d735..8ea189c 100644 --- a/src/main/java/net/h31ix/anticheat/Anticheat.java +++ b/src/main/java/net/h31ix/anticheat/Anticheat.java @@ -1,337 +1,337 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.h31ix.anticheat.event.*; -import net.h31ix.anticheat.manage.AnticheatManager; -import net.h31ix.anticheat.manage.CheckType; -import net.h31ix.anticheat.manage.Utilities; -import net.h31ix.anticheat.metrics.Metrics; -import net.h31ix.anticheat.metrics.Metrics.Graph; -import net.h31ix.anticheat.xray.XRayListener; -import net.h31ix.anticheat.xray.XRayTracker; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; - -public class Anticheat extends JavaPlugin -{ - private static AnticheatManager manager; - private final List eventList = new ArrayList(); - private static boolean update = false; - private static final int BYTE_SIZE = 1024; - private static final Logger logger = Logger.getLogger("Minecraft"); - private static Configuration config; - private static boolean verbose; - private static String updateFolder; - private static Metrics metrics; - - @Override - public void onDisable() - { - Map map = manager.getPlayerManager().getLevels(); - Iterator set = map.keySet().iterator(); - while (set.hasNext()) - { - String player = set.next(); - config.saveLevel(player, map.get(player)); - } - config.saveLevels(); - getServer().getScheduler().cancelAllTasks(); - } - - @Override - public void onEnable() - { - manager = new AnticheatManager(this); - config = manager.getConfiguration(); - checkConfig(); - verbose = config.verboseStartup(); - updateFolder = config.updateFolder(); - checkForUpdate(); - eventList.add(new PlayerListener()); - eventList.add(new BlockListener()); - eventList.add(new EntityListener()); - eventList.add(new VehicleListener()); - final XRayTracker xtracker = manager.getXRayTracker(); - if (config.logXRay()) - { - eventList.add(new XRayListener()); - if (config.alertXRay()) - { - getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() - { - @Override - public void run() - { - for (Player player : getServer().getOnlinePlayers()) - { - String name = player.getName(); - if (!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name)) - { - String[] alert = new String[2]; - alert[0] = ChatColor.YELLOW - + "[ALERT] " + ChatColor.WHITE - + name + ChatColor.YELLOW - + " might be using xray."; - alert[1] = ChatColor.YELLOW - + "[ALERT] Please check their xray stats using " - + ChatColor.WHITE - + "/anticheat xray " + name - + ChatColor.YELLOW + "."; - Utilities.alert(alert); - xtracker.logAlert(name); - } - } - } - }, 1200L, 1200L); - } - } - for (Listener listener : eventList) - { - getServer().getPluginManager().registerEvents(listener, this); - if (verbose) - { - logger.log(Level.INFO, "[AC] Registered events for ".concat(listener.toString())); - } - } - getCommand("anticheat").setExecutor(new CommandHandler()); - if (verbose) - { - logger.log(Level.INFO, "[AC] Registered commands"); - logger.log(Level.INFO, "[AC] Finished loading."); - } - if (update && config.autoUpdate()) - { - if (verbose) - { - logger.log(Level.INFO, "[AC] Downloading the new update..."); - } - File file = new File("plugins/" + updateFolder); - if (!file.exists()) - { - try - { - file.mkdir(); - } - catch (Exception ex) - { - } - } - try - { - saveFile(file.getCanonicalPath() + "/AntiCheat.jar","http://dl.dropbox.com/u/38228324/AntiCheat.jar"); - } - catch (IOException ex) - { - } - } - try - { - metrics = new Metrics(this); - final EventListener listener = new EventListener(); - Graph graph = metrics.createGraph("Hacks blocked"); - for (final CheckType type : CheckType.values()) - { - char[] chars = type.toString().replaceAll("_", " ").toLowerCase().toCharArray(); - chars[0] = Character.toUpperCase(chars[0]); - graph.addPlotter(new Metrics.Plotter(new String(chars)) - { - @Override - public int getValue() - { - return listener.getCheats(type); - } - }); - listener.resetCheck(type); - } - metrics.start(); - } - catch (IOException ex) - { - } - for (Player player : getServer().getOnlinePlayers()) - { - String name = player.getName(); - manager.getPlayerManager().setLevel(player,config.getLevel(name)); - } - } - - private void saveFile(String file, String url) - { - BufferedInputStream in = null; - FileOutputStream fout = null; - try - { - in = new BufferedInputStream(new URL(url).openStream()); - fout = new FileOutputStream(file); - - byte[] data = new byte[BYTE_SIZE]; - int count; - while ((count = in.read(data, 0, BYTE_SIZE)) != -1) - { - fout.write(data, 0, count); - } - } - catch (Exception ex) - { - } - finally - { - try - { - if (in != null) - { - in.close(); - } - if (fout != null) - { - fout.close(); - } - } - catch (Exception ex) - { - } - if (verbose) - { - logger.log(Level.INFO,"[AC] AntiCheat update has been downloaded and will be installed on next launch."); - } - } - } - - public void checkConfig() - { - if (!new File(getDataFolder() + "/config.yml").exists()) - { - saveDefaultConfig(); - if (verbose) - { - logger.log(Level.INFO, "[AC] Config file created"); - } - } - } - - private void checkForUpdate() - { - if (verbose) - { - logger.log(Level.INFO, "[AC] Checking for updates..."); - } - URL url = null; - URLConnection urlConn = null; - InputStreamReader inStream = null; - BufferedReader buff = null; - String v = ""; - try - { - url = new URL("http://dl.dropbox.com/u/38228324/anticheatVersion.txt"); - urlConn = url.openConnection(); - inStream = new InputStreamReader(urlConn.getInputStream()); - } - catch (Exception ex) - { - } - buff = new BufferedReader(inStream); - try - { - v = buff.readLine(); - urlConn = null; - inStream = null; - buff.close(); - buff = null; - } - catch (Exception ex) - { - } - if (!this.getDescription().getVersion().equalsIgnoreCase(v)) - { - String version = this.getDescription().getVersion(); - if (version.endsWith("-PRE") || version.endsWith("-DEV")) - { - if (version.replaceAll("-PRE", "").replaceAll("-DEV", "").equalsIgnoreCase(v)) - { - update = true; - if (verbose) - { - logger.log(Level.INFO,"[AC] Your dev build has been promoted to release. Downloading the update."); - } - } - else - { - update = false; - if (verbose) - { - logger.log(Level.INFO,"[AC] Dev build detected, so skipping update checking until this version is released."); - } - } - } - else - { - update = true; - if (verbose) - { - logger.log(Level.INFO, "[AC] An update was found."); - } - } - } - else - { - if (verbose) - { - logger.log(Level.INFO, "[AC] No update found."); - } - update = false; - } - } - - public static Anticheat getPlugin() - { - return manager.getPlugin(); - } - - public static AnticheatManager getManager() - { - return manager; - } - - public static boolean isUpdated() - { - return !update; - } - - public static String getVersion() - { - return manager.getPlugin().getDescription().getVersion(); - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.h31ix.anticheat.event.*; +import net.h31ix.anticheat.manage.AnticheatManager; +import net.h31ix.anticheat.manage.CheckType; +import net.h31ix.anticheat.manage.Utilities; +import net.h31ix.anticheat.metrics.Metrics; +import net.h31ix.anticheat.metrics.Metrics.Graph; +import net.h31ix.anticheat.xray.XRayListener; +import net.h31ix.anticheat.xray.XRayTracker; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +public class Anticheat extends JavaPlugin +{ + private static AnticheatManager manager; + private final List eventList = new ArrayList(); + private static boolean update = false; + private static final int BYTE_SIZE = 1024; + private static final Logger logger = Logger.getLogger("Minecraft"); + private static Configuration config; + private static boolean verbose; + private static String updateFolder; + private static Metrics metrics; + + @Override + public void onDisable() + { + Map map = manager.getPlayerManager().getLevels(); + Iterator set = map.keySet().iterator(); + while (set.hasNext()) + { + String player = set.next(); + config.saveLevel(player, map.get(player)); + } + config.saveLevels(); + getServer().getScheduler().cancelAllTasks(); + } + + @Override + public void onEnable() + { + manager = new AnticheatManager(this); + config = manager.getConfiguration(); + checkConfig(); + verbose = config.verboseStartup(); + updateFolder = config.updateFolder(); + checkForUpdate(); + eventList.add(new PlayerListener()); + eventList.add(new BlockListener()); + eventList.add(new EntityListener()); + eventList.add(new VehicleListener()); + final XRayTracker xtracker = manager.getXRayTracker(); + if (config.logXRay()) + { + eventList.add(new XRayListener()); + if (config.alertXRay()) + { + getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() + { + @Override + public void run() + { + for (Player player : getServer().getOnlinePlayers()) + { + String name = player.getName(); + if (!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name)) + { + String[] alert = new String[2]; + alert[0] = ChatColor.YELLOW + + "[ALERT] " + ChatColor.WHITE + + name + ChatColor.YELLOW + + " might be using xray."; + alert[1] = ChatColor.YELLOW + + "[ALERT] Please check their xray stats using " + + ChatColor.WHITE + + "/anticheat xray " + name + + ChatColor.YELLOW + "."; + Utilities.alert(alert); + xtracker.logAlert(name); + } + } + } + }, 1200L, 1200L); + } + } + for (Listener listener : eventList) + { + getServer().getPluginManager().registerEvents(listener, this); + if (verbose) + { + logger.log(Level.INFO, "[AC] Registered events for ".concat(listener.toString())); + } + } + getCommand("anticheat").setExecutor(new CommandHandler()); + if (verbose) + { + logger.log(Level.INFO, "[AC] Registered commands"); + logger.log(Level.INFO, "[AC] Finished loading."); + } + if (update && config.autoUpdate()) + { + if (verbose) + { + logger.log(Level.INFO, "[AC] Downloading the new update..."); + } + File file = new File("plugins/" + updateFolder); + if (!file.exists()) + { + try + { + file.mkdir(); + } + catch (Exception ex) + { + } + } + try + { + saveFile(file.getCanonicalPath() + "/AntiCheat.jar","http://dl.dropbox.com/u/38228324/AntiCheat.jar"); + } + catch (IOException ex) + { + } + } + try + { + metrics = new Metrics(this); + final EventListener listener = new EventListener(); + Graph graph = metrics.createGraph("Hacks blocked"); + for (final CheckType type : CheckType.values()) + { + char[] chars = type.toString().replaceAll("_", " ").toLowerCase().toCharArray(); + chars[0] = Character.toUpperCase(chars[0]); + graph.addPlotter(new Metrics.Plotter(new String(chars)) + { + @Override + public int getValue() + { + return listener.getCheats(type); + } + }); + listener.resetCheck(type); + } + metrics.start(); + } + catch (IOException ex) + { + } + for (Player player : getServer().getOnlinePlayers()) + { + String name = player.getName(); + manager.getPlayerManager().setLevel(player,config.getLevel(name)); + } + } + + private void saveFile(String file, String url) + { + BufferedInputStream in = null; + FileOutputStream fout = null; + try + { + in = new BufferedInputStream(new URL(url).openStream()); + fout = new FileOutputStream(file); + + byte[] data = new byte[BYTE_SIZE]; + int count; + while ((count = in.read(data, 0, BYTE_SIZE)) != -1) + { + fout.write(data, 0, count); + } + } + catch (Exception ex) + { + } + finally + { + try + { + if (in != null) + { + in.close(); + } + if (fout != null) + { + fout.close(); + } + } + catch (Exception ex) + { + } + if (verbose) + { + logger.log(Level.INFO,"[AC] AntiCheat update has been downloaded and will be installed on next launch."); + } + } + } + + public void checkConfig() + { + if (!new File(getDataFolder() + "/config.yml").exists()) + { + saveDefaultConfig(); + if (verbose) + { + logger.log(Level.INFO, "[AC] Config file created"); + } + } + } + + private void checkForUpdate() + { + if (verbose) + { + logger.log(Level.INFO, "[AC] Checking for updates..."); + } + URL url = null; + URLConnection urlConn = null; + InputStreamReader inStream = null; + BufferedReader buff = null; + String v = ""; + try + { + url = new URL("http://dl.dropbox.com/u/38228324/anticheatVersion.txt"); + urlConn = url.openConnection(); + inStream = new InputStreamReader(urlConn.getInputStream()); + } + catch (Exception ex) + { + } + buff = new BufferedReader(inStream); + try + { + v = buff.readLine(); + urlConn = null; + inStream = null; + buff.close(); + buff = null; + } + catch (Exception ex) + { + } + if (!this.getDescription().getVersion().equalsIgnoreCase(v)) + { + String version = this.getDescription().getVersion(); + if (version.endsWith("-PRE") || version.endsWith("-DEV")) + { + if (version.replaceAll("-PRE", "").replaceAll("-DEV", "").equalsIgnoreCase(v)) + { + update = true; + if (verbose) + { + logger.log(Level.INFO,"[AC] Your dev build has been promoted to release. Downloading the update."); + } + } + else + { + update = false; + if (verbose) + { + logger.log(Level.INFO,"[AC] Dev build detected, so skipping update checking until this version is released."); + } + } + } + else + { + update = true; + if (verbose) + { + logger.log(Level.INFO, "[AC] An update was found."); + } + } + } + else + { + if (verbose) + { + logger.log(Level.INFO, "[AC] No update found."); + } + update = false; + } + } + + public static Anticheat getPlugin() + { + return manager.getPlugin(); + } + + public static AnticheatManager getManager() + { + return manager; + } + + public static boolean isUpdated() + { + return !update; + } + + public static String getVersion() + { + return manager.getPlugin().getDescription().getVersion(); + } +} diff --git a/src/main/java/net/h31ix/anticheat/CommandHandler.java b/src/main/java/net/h31ix/anticheat/CommandHandler.java index 2a99678..9392b18 100644 --- a/src/main/java/net/h31ix/anticheat/CommandHandler.java +++ b/src/main/java/net/h31ix/anticheat/CommandHandler.java @@ -1,335 +1,335 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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; - -import java.util.ArrayList; -import java.util.List; -import net.h31ix.anticheat.manage.AnticheatManager; -import net.h31ix.anticheat.manage.PlayerManager; -import net.h31ix.anticheat.xray.XRayTracker; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Server; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class CommandHandler implements CommandExecutor -{ - private Configuration config = Anticheat.getManager().getConfiguration(); - private PlayerManager playerManager = Anticheat.getManager().getPlayerManager(); - private XRayTracker xtracker = Anticheat.getManager().getXRayTracker(); - private static final ChatColor RED = ChatColor.RED; - private static final ChatColor YELLOW = ChatColor.YELLOW; - private static final ChatColor GREEN = ChatColor.GREEN; - private static final ChatColor WHITE = ChatColor.WHITE; - private List high = new ArrayList(); - private List med = new ArrayList(); - private List low = new ArrayList(); - private static final Server SERVER = Bukkit.getServer(); - private static final int MED_THRESHOLD = 20; - private static final int HIGH_THRESHOLD = 50; - - public void handleLog(CommandSender cs, String [] args) - { - if(hasPermission(cs,"system.log") || hasPermission(cs,"admin")) - { - if(args[1].equalsIgnoreCase("enable")) - { - if(!config.logConsole()) - { - config.setLog(true); - cs.sendMessage(GREEN+"Console logging enabled."); - } - else - { - cs.sendMessage(GREEN+"Console logging is already enabled!"); - } - } - else if(args[1].equalsIgnoreCase("disable")) - { - if(config.logConsole()) - { - config.setLog(false); - cs.sendMessage(GREEN+"Console logging disabled."); - } - else - { - cs.sendMessage(GREEN+"Console logging is already disabled!"); - } - } - else - { - cs.sendMessage(RED+"Usage: /anticheat log [enable/disable]"); - } - } - } - - public void handleXRay(CommandSender cs, String [] args) - { - if(hasPermission(cs,"system.xray") || hasPermission(cs,"admin") || hasPermission(cs,"mod")) - { - if(config.logXRay()) - { - List list = SERVER.matchPlayer(args[1]); - if(list.size() == 1) - { - Player player = list.get(0); - if(xtracker.sufficientData(player.getName())) - { - xtracker.sendStats(cs, player.getName()); - } - else - { - cs.sendMessage(RED+"Insufficient data collected from "+WHITE+args[1]+RED+"."); - cs.sendMessage(RED+"Please wait until more info is collected before predictions are calculated."); - } - } - else if(list.size() > 1) - { - cs.sendMessage(RED+"Multiple players found by name: "+WHITE+args[1]+RED+"."); - } - else if(xtracker.sufficientData(args[1])) - { - xtracker.sendStats(cs, args[1]); - } - else - { - cs.sendMessage(RED+"Insufficient data collected from "+WHITE+args[1]+RED+"."); - cs.sendMessage(RED+"Please wait until more info is collected before predictions are calculated."); - } - } - else - { - cs.sendMessage(RED+"XRay logging is off in the config."); - } - } - } - - public void handleReset(CommandSender cs, String [] args) - { - if(hasPermission(cs,"system.reset") || hasPermission(cs,"admin")) - { - List list = SERVER.matchPlayer(args[1]); - if(list.size() == 1) - { - Player player = list.get(0); - getPlayers(); - if(low.contains(player)) - { - cs.sendMessage(player.getName()+RED+" is already in Low Level!"); - } - else if (med.contains(player) || high.contains(player)) - { - playerManager.reset(player); - cs.sendMessage(player.getName()+GREEN+" has been reset to Low Level."); - } - xtracker.reset(player.getName()); - cs.sendMessage(player.getName()+GREEN+"'s XRay stats have been reset."); - } - else if(list.size() > 1) - { - cs.sendMessage(RED+"Multiple players found by name: "+WHITE+args[1]+RED+"."); - } - else - { - cs.sendMessage(RED+"Player: "+WHITE+args[1]+RED+" not found."); - } - } - } - - public void handleHelp(CommandSender cs) - { - if(hasPermission(cs,"system.help") || hasPermission(cs,"admin") || hasPermission(cs,"mod")) - { - String base = "/AntiCheat "; - cs.sendMessage("----------------------["+GREEN+"AntiCheat"+WHITE+"]----------------------"); - cs.sendMessage(base+GREEN+"log [Enable/Disable]"+WHITE+" - toggle logging"); - cs.sendMessage(base+GREEN+"report"+WHITE+" - get a detailed cheat report"); - cs.sendMessage(base+GREEN+"reload"+WHITE+" - reload AntiCheat configuration"); - cs.sendMessage(base+GREEN+"reset [user]"+WHITE+" - reset user's hack level"); - cs.sendMessage(base+GREEN+"xray [user]"+WHITE+" - check user's xray levels"); - cs.sendMessage(base+GREEN+"help"+WHITE+" - access this page"); - cs.sendMessage(base+GREEN+"update"+WHITE+" - check update status"); - cs.sendMessage("-----------------------------------------------------"); - } - } - - public void handleUpdate(CommandSender cs) - { - if(hasPermission(cs,"system.update") || hasPermission(cs,"admin")) - { - cs.sendMessage("Running "+GREEN+"AntiCheat "+WHITE+"v"+GREEN+Anticheat.getVersion()); - cs.sendMessage("-----------------------------------------------------"); - if(!Anticheat.isUpdated()) - { - cs.sendMessage("There "+GREEN+"IS"+WHITE+" a newer version avaliable."); - if(config.autoUpdate()) - { - cs.sendMessage("It will be installed automatically for you on next launch."); - } - else - { - cs.sendMessage("Due to your config settings, we "+RED+"can not"+WHITE+" auto update."); - cs.sendMessage("Please visit http://dev.bukkit.org/server-mods/anticheat/"); - } - } - else - { - cs.sendMessage("AntiCheat is "+GREEN+"UP TO DATE!"); - } - } - } - - public void handleReport(CommandSender cs) - { - if(hasPermission(cs,"system.report") || hasPermission(cs,"admin") || hasPermission(cs,"mod")) - { - getPlayers(); - if(!low.isEmpty()) - { - cs.sendMessage(GREEN+"----Level: Low (Not likely hacking)----"); - for(Player player : low) - { - cs.sendMessage(GREEN+player.getName()); - } - } - if(!med.isEmpty()) - { - cs.sendMessage(YELLOW+"----Level: Medium (Possibly hacking/lagging)----"); - for(Player player : med) - { - cs.sendMessage(YELLOW+player.getName()); - } - } - if(!high.isEmpty()) - { - cs.sendMessage(RED+"----Level: High (Probably hacking or bad connection)----"); - for(Player player : high) - { - cs.sendMessage(RED+player.getName()); - } - } - } - } - - public void handleReload(CommandSender cs) - { - if(hasPermission(cs,"system.reload") || hasPermission(cs,"admin")) - { - config.load(); - cs.sendMessage(GREEN+"AntiCheat configuration reloaded."); - } - } - - @Override - public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) - { - if(args.length == 2) - { - if(args[0].equalsIgnoreCase("log")) - { - handleLog(cs,args); - } - else if(args[0].equalsIgnoreCase("xray")) - { - handleXRay(cs,args); - } - else if(args[0].equalsIgnoreCase("reset")) - { - handleReset(cs,args); - } - else - { - cs.sendMessage(RED+"Unrecognized command."); - } - } - else if (args.length == 1) - { - if(args[0].equalsIgnoreCase("help")) - { - handleHelp(cs); - } - else if(args[0].equalsIgnoreCase("report")) - { - handleReport(cs); - } - else if(args[0].equalsIgnoreCase("reload")) - { - handleReload(cs); - } - else if(args[0].equalsIgnoreCase("update")) - { - handleUpdate(cs); - } - else - { - cs.sendMessage(RED+"Unrecognized command."); - } - } - else - { - cs.sendMessage(RED+"Unrecognized command. Try "+ChatColor.WHITE+"/anticheat help"); - } - return true; - } - - public boolean hasPermission(CommandSender cs, String permission) - { - if(cs instanceof Player) - { - if(((Player)cs).hasPermission("anticheat."+permission)) - { - return true; - } - else - { - cs.sendMessage("Insufficient permissions."); - return false; - } - } - else - { - return true; - } - } - public void getPlayers() - { - high.clear(); - med.clear(); - low.clear(); - for(Player player : SERVER.getOnlinePlayers()) - { - int level = playerManager.getLevel(player); - if(level <= MED_THRESHOLD) - { - low.add(player); - } - else if(level <= HIGH_THRESHOLD) - { - med.add(player); - } - else - { - high.add(player); - } - } - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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; + +import java.util.ArrayList; +import java.util.List; +import net.h31ix.anticheat.manage.AnticheatManager; +import net.h31ix.anticheat.manage.PlayerManager; +import net.h31ix.anticheat.xray.XRayTracker; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Server; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandHandler implements CommandExecutor +{ + private Configuration config = Anticheat.getManager().getConfiguration(); + private PlayerManager playerManager = Anticheat.getManager().getPlayerManager(); + private XRayTracker xtracker = Anticheat.getManager().getXRayTracker(); + private static final ChatColor RED = ChatColor.RED; + private static final ChatColor YELLOW = ChatColor.YELLOW; + private static final ChatColor GREEN = ChatColor.GREEN; + private static final ChatColor WHITE = ChatColor.WHITE; + private List high = new ArrayList(); + private List med = new ArrayList(); + private List low = new ArrayList(); + private static final Server SERVER = Bukkit.getServer(); + private static final int MED_THRESHOLD = 20; + private static final int HIGH_THRESHOLD = 50; + + public void handleLog(CommandSender cs, String [] args) + { + if(hasPermission(cs,"system.log") || hasPermission(cs,"admin")) + { + if(args[1].equalsIgnoreCase("enable")) + { + if(!config.logConsole()) + { + config.setLog(true); + cs.sendMessage(GREEN+"Console logging enabled."); + } + else + { + cs.sendMessage(GREEN+"Console logging is already enabled!"); + } + } + else if(args[1].equalsIgnoreCase("disable")) + { + if(config.logConsole()) + { + config.setLog(false); + cs.sendMessage(GREEN+"Console logging disabled."); + } + else + { + cs.sendMessage(GREEN+"Console logging is already disabled!"); + } + } + else + { + cs.sendMessage(RED+"Usage: /anticheat log [enable/disable]"); + } + } + } + + public void handleXRay(CommandSender cs, String [] args) + { + if(hasPermission(cs,"system.xray") || hasPermission(cs,"admin") || hasPermission(cs,"mod")) + { + if(config.logXRay()) + { + List list = SERVER.matchPlayer(args[1]); + if(list.size() == 1) + { + Player player = list.get(0); + if(xtracker.sufficientData(player.getName())) + { + xtracker.sendStats(cs, player.getName()); + } + else + { + cs.sendMessage(RED+"Insufficient data collected from "+WHITE+args[1]+RED+"."); + cs.sendMessage(RED+"Please wait until more info is collected before predictions are calculated."); + } + } + else if(list.size() > 1) + { + cs.sendMessage(RED+"Multiple players found by name: "+WHITE+args[1]+RED+"."); + } + else if(xtracker.sufficientData(args[1])) + { + xtracker.sendStats(cs, args[1]); + } + else + { + cs.sendMessage(RED+"Insufficient data collected from "+WHITE+args[1]+RED+"."); + cs.sendMessage(RED+"Please wait until more info is collected before predictions are calculated."); + } + } + else + { + cs.sendMessage(RED+"XRay logging is off in the config."); + } + } + } + + public void handleReset(CommandSender cs, String [] args) + { + if(hasPermission(cs,"system.reset") || hasPermission(cs,"admin")) + { + List list = SERVER.matchPlayer(args[1]); + if(list.size() == 1) + { + Player player = list.get(0); + getPlayers(); + if(low.contains(player)) + { + cs.sendMessage(player.getName()+RED+" is already in Low Level!"); + } + else if (med.contains(player) || high.contains(player)) + { + playerManager.reset(player); + cs.sendMessage(player.getName()+GREEN+" has been reset to Low Level."); + } + xtracker.reset(player.getName()); + cs.sendMessage(player.getName()+GREEN+"'s XRay stats have been reset."); + } + else if(list.size() > 1) + { + cs.sendMessage(RED+"Multiple players found by name: "+WHITE+args[1]+RED+"."); + } + else + { + cs.sendMessage(RED+"Player: "+WHITE+args[1]+RED+" not found."); + } + } + } + + public void handleHelp(CommandSender cs) + { + if(hasPermission(cs,"system.help") || hasPermission(cs,"admin") || hasPermission(cs,"mod")) + { + String base = "/AntiCheat "; + cs.sendMessage("----------------------["+GREEN+"AntiCheat"+WHITE+"]----------------------"); + cs.sendMessage(base+GREEN+"log [Enable/Disable]"+WHITE+" - toggle logging"); + cs.sendMessage(base+GREEN+"report"+WHITE+" - get a detailed cheat report"); + cs.sendMessage(base+GREEN+"reload"+WHITE+" - reload AntiCheat configuration"); + cs.sendMessage(base+GREEN+"reset [user]"+WHITE+" - reset user's hack level"); + cs.sendMessage(base+GREEN+"xray [user]"+WHITE+" - check user's xray levels"); + cs.sendMessage(base+GREEN+"help"+WHITE+" - access this page"); + cs.sendMessage(base+GREEN+"update"+WHITE+" - check update status"); + cs.sendMessage("-----------------------------------------------------"); + } + } + + public void handleUpdate(CommandSender cs) + { + if(hasPermission(cs,"system.update") || hasPermission(cs,"admin")) + { + cs.sendMessage("Running "+GREEN+"AntiCheat "+WHITE+"v"+GREEN+Anticheat.getVersion()); + cs.sendMessage("-----------------------------------------------------"); + if(!Anticheat.isUpdated()) + { + cs.sendMessage("There "+GREEN+"IS"+WHITE+" a newer version avaliable."); + if(config.autoUpdate()) + { + cs.sendMessage("It will be installed automatically for you on next launch."); + } + else + { + cs.sendMessage("Due to your config settings, we "+RED+"can not"+WHITE+" auto update."); + cs.sendMessage("Please visit http://dev.bukkit.org/server-mods/anticheat/"); + } + } + else + { + cs.sendMessage("AntiCheat is "+GREEN+"UP TO DATE!"); + } + } + } + + public void handleReport(CommandSender cs) + { + if(hasPermission(cs,"system.report") || hasPermission(cs,"admin") || hasPermission(cs,"mod")) + { + getPlayers(); + if(!low.isEmpty()) + { + cs.sendMessage(GREEN+"----Level: Low (Not likely hacking)----"); + for(Player player : low) + { + cs.sendMessage(GREEN+player.getName()); + } + } + if(!med.isEmpty()) + { + cs.sendMessage(YELLOW+"----Level: Medium (Possibly hacking/lagging)----"); + for(Player player : med) + { + cs.sendMessage(YELLOW+player.getName()); + } + } + if(!high.isEmpty()) + { + cs.sendMessage(RED+"----Level: High (Probably hacking or bad connection)----"); + for(Player player : high) + { + cs.sendMessage(RED+player.getName()); + } + } + } + } + + public void handleReload(CommandSender cs) + { + if(hasPermission(cs,"system.reload") || hasPermission(cs,"admin")) + { + config.load(); + cs.sendMessage(GREEN+"AntiCheat configuration reloaded."); + } + } + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) + { + if(args.length == 2) + { + if(args[0].equalsIgnoreCase("log")) + { + handleLog(cs,args); + } + else if(args[0].equalsIgnoreCase("xray")) + { + handleXRay(cs,args); + } + else if(args[0].equalsIgnoreCase("reset")) + { + handleReset(cs,args); + } + else + { + cs.sendMessage(RED+"Unrecognized command."); + } + } + else if (args.length == 1) + { + if(args[0].equalsIgnoreCase("help")) + { + handleHelp(cs); + } + else if(args[0].equalsIgnoreCase("report")) + { + handleReport(cs); + } + else if(args[0].equalsIgnoreCase("reload")) + { + handleReload(cs); + } + else if(args[0].equalsIgnoreCase("update")) + { + handleUpdate(cs); + } + else + { + cs.sendMessage(RED+"Unrecognized command."); + } + } + else + { + cs.sendMessage(RED+"Unrecognized command. Try "+ChatColor.WHITE+"/anticheat help"); + } + return true; + } + + public boolean hasPermission(CommandSender cs, String permission) + { + if(cs instanceof Player) + { + if(((Player)cs).hasPermission("anticheat."+permission)) + { + return true; + } + else + { + cs.sendMessage("Insufficient permissions."); + return false; + } + } + else + { + return true; + } + } + public void getPlayers() + { + high.clear(); + med.clear(); + low.clear(); + for(Player player : SERVER.getOnlinePlayers()) + { + int level = playerManager.getLevel(player); + if(level <= MED_THRESHOLD) + { + low.add(player); + } + else if(level <= HIGH_THRESHOLD) + { + med.add(player); + } + else + { + high.add(player); + } + } + } +} diff --git a/src/main/java/net/h31ix/anticheat/Configuration.java b/src/main/java/net/h31ix/anticheat/Configuration.java index 87f321c..4d1e6c0 100644 --- a/src/main/java/net/h31ix/anticheat/Configuration.java +++ b/src/main/java/net/h31ix/anticheat/Configuration.java @@ -1,220 +1,220 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import net.h31ix.anticheat.manage.AnticheatManager; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -public class Configuration -{ - private AnticheatManager micromanage = null; //like a boss! - private File configFile = null; - private File levelFile = null; - private File bukkitFile = null; - private FileConfiguration config; - private FileConfiguration level; - private FileConfiguration bukkit; - private boolean logConsole; - private boolean logXRay; - private boolean alertXRay; - private boolean autoUpdate; - private boolean verboseStartup; - private String updateFolder; - private List worlds = new ArrayList(); - - public Configuration(AnticheatManager instance) - { - micromanage = instance; - configFile = new File(micromanage.getPlugin().getDataFolder()+"/config.yml"); - levelFile = new File(micromanage.getPlugin().getDataFolder()+"/data/level.yml"); - bukkitFile = new File("bukkit.yml"); - load(); - } - - private void save() - { - try - { - config.save(configFile); - } - catch (IOException ex) - { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public boolean logConsole() - { - return logConsole; - } - - public boolean logXRay() - { - return logXRay; - } - - public boolean alertXRay() - { - return alertXRay; - } - - public boolean autoUpdate() - { - return autoUpdate; - } - - public boolean verboseStartup() - { - return verboseStartup; - } - - public String updateFolder() - { - return updateFolder; - } - - public final void load() - { - micromanage.getPlugin().checkConfig(); - config = YamlConfiguration.loadConfiguration(configFile); - level = YamlConfiguration.loadConfiguration(levelFile); - bukkit = YamlConfiguration.loadConfiguration(bukkitFile); - updateFolder = bukkit.getString("settings.update-folder"); - if(config.getString("Logging.Log to console") != null) - { - boolean b = config.getBoolean("Logging.Log to console"); - config.set("Logging", null); - config.set("System.Log to console",b); - save(); - } - logConsole = config.getBoolean("System.Log to console"); - if(config.getList("Enable in") == null) - { - List w = new ArrayList(); - for(World world : Bukkit.getServer().getWorlds()) - { - w.add(world.getName()); - } - config.set("Enable in", w); - save(); - } - worlds = (List)(config.getList("Enable in")); - if(config.getString("XRay.Log xray stats") == null) - { - config.set("XRay.Log xray stats", true); - save(); - } - logXRay = config.getBoolean("XRay.Log xray stats"); - if(config.getString("System.Auto update") == null) - { - config.set("System.Auto update", true); - save(); - } - autoUpdate = config.getBoolean("System.Auto update"); - if(config.getString("System.Verbose startup") == null) - { - config.set("System.Verbose startup", false); - save(); - } - verboseStartup = config.getBoolean("System.Verbose startup"); - if(config.getString("XRay.Alert when xray is found") == null) - { - config.set("XRay.Alert when xray is found", false); - save(); - } - alertXRay = config.getBoolean("XRay.Alert when xray is found"); - } - - public String getResult(String event) - { - return config.getString("Events.Level "+event); - } - - public void setLog(boolean b) - { - config.set("System.Log to console", b); - this.logConsole = b; - try - { - config.save(configFile); - } - catch (IOException ex) - { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public List getWorlds() - { - return worlds; - } - - public File getConfigFile() - { - return configFile; - } - - public File getLevelFile() - { - return levelFile; - } - - public boolean checkInWorld(World world) - { - return worlds.contains(world.getName()); - } - - public int getLevel(String player) - { - int x = 0; - if(level.getString(player) != null) - { - x = level.getInt(player); - } - return x; - } - - public void saveLevel(String player, int x) - { - level.set(player,x); - } - - public void saveLevels() - { - try - { - level.save(levelFile); - } - catch (IOException ex) - { - Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); - } - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.h31ix.anticheat.manage.AnticheatManager; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +public class Configuration +{ + private AnticheatManager micromanage = null; //like a boss! + private File configFile = null; + private File levelFile = null; + private File bukkitFile = null; + private FileConfiguration config; + private FileConfiguration level; + private FileConfiguration bukkit; + private boolean logConsole; + private boolean logXRay; + private boolean alertXRay; + private boolean autoUpdate; + private boolean verboseStartup; + private String updateFolder; + private List worlds = new ArrayList(); + + public Configuration(AnticheatManager instance) + { + micromanage = instance; + configFile = new File(micromanage.getPlugin().getDataFolder()+"/config.yml"); + levelFile = new File(micromanage.getPlugin().getDataFolder()+"/data/level.yml"); + bukkitFile = new File("bukkit.yml"); + load(); + } + + private void save() + { + try + { + config.save(configFile); + } + catch (IOException ex) + { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public boolean logConsole() + { + return logConsole; + } + + public boolean logXRay() + { + return logXRay; + } + + public boolean alertXRay() + { + return alertXRay; + } + + public boolean autoUpdate() + { + return autoUpdate; + } + + public boolean verboseStartup() + { + return verboseStartup; + } + + public String updateFolder() + { + return updateFolder; + } + + public final void load() + { + micromanage.getPlugin().checkConfig(); + config = YamlConfiguration.loadConfiguration(configFile); + level = YamlConfiguration.loadConfiguration(levelFile); + bukkit = YamlConfiguration.loadConfiguration(bukkitFile); + updateFolder = bukkit.getString("settings.update-folder"); + if(config.getString("Logging.Log to console") != null) + { + boolean b = config.getBoolean("Logging.Log to console"); + config.set("Logging", null); + config.set("System.Log to console",b); + save(); + } + logConsole = config.getBoolean("System.Log to console"); + if(config.getList("Enable in") == null) + { + List w = new ArrayList(); + for(World world : Bukkit.getServer().getWorlds()) + { + w.add(world.getName()); + } + config.set("Enable in", w); + save(); + } + worlds = (List)(config.getList("Enable in")); + if(config.getString("XRay.Log xray stats") == null) + { + config.set("XRay.Log xray stats", true); + save(); + } + logXRay = config.getBoolean("XRay.Log xray stats"); + if(config.getString("System.Auto update") == null) + { + config.set("System.Auto update", true); + save(); + } + autoUpdate = config.getBoolean("System.Auto update"); + if(config.getString("System.Verbose startup") == null) + { + config.set("System.Verbose startup", false); + save(); + } + verboseStartup = config.getBoolean("System.Verbose startup"); + if(config.getString("XRay.Alert when xray is found") == null) + { + config.set("XRay.Alert when xray is found", false); + save(); + } + alertXRay = config.getBoolean("XRay.Alert when xray is found"); + } + + public String getResult(String event) + { + return config.getString("Events.Level "+event); + } + + public void setLog(boolean b) + { + config.set("System.Log to console", b); + this.logConsole = b; + try + { + config.save(configFile); + } + catch (IOException ex) + { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public List getWorlds() + { + return worlds; + } + + public File getConfigFile() + { + return configFile; + } + + public File getLevelFile() + { + return levelFile; + } + + public boolean checkInWorld(World world) + { + return worlds.contains(world.getName()); + } + + public int getLevel(String player) + { + int x = 0; + if(level.getString(player) != null) + { + x = level.getInt(player); + } + return x; + } + + public void saveLevel(String player, int x) + { + level.set(player,x); + } + + public void saveLevels() + { + try + { + level.save(levelFile); + } + catch (IOException ex) + { + Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/src/main/java/net/h31ix/anticheat/event/BlockListener.java b/src/main/java/net/h31ix/anticheat/event/BlockListener.java index 1831081..7d23f77 100644 --- a/src/main/java/net/h31ix/anticheat/event/BlockListener.java +++ b/src/main/java/net/h31ix/anticheat/event/BlockListener.java @@ -1,121 +1,121 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.event; - -import net.h31ix.anticheat.Anticheat; -import net.h31ix.anticheat.manage.Backend; -import net.h31ix.anticheat.manage.CheckManager; -import net.h31ix.anticheat.manage.CheckType; -import net.h31ix.anticheat.manage.Distance; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockPlaceEvent; - -public class BlockListener extends EventListener -{ - private final Backend backend = getBackend(); - private final CheckManager checkManager = getCheckManager(); - private final Anticheat plugin = getPlugin(); - - @EventHandler - public void onBlockDamage(BlockDamageEvent event) - { - if(event.getInstaBreak()) - { - backend.logInstantBreak(event.getPlayer()); - } - } - - @EventHandler - public void onBlockPlace(BlockPlaceEvent event) - { - final Player player = event.getPlayer(); - Block block = event.getBlock(); - if(player != null) - { - if(checkManager.willCheck(player, CheckType.FAST_PLACE)) - { - if(backend.checkFastPlace(player)) - { - event.setCancelled(true); - log("tried to place a block of "+block.getType().name()+" too fast.",player,CheckType.FAST_PLACE); - } - else - { - decrease(player); - backend.logBlockPlace(player); - } - } - } - } - - @EventHandler - public void onBlockBreak(BlockBreakEvent event) - { - final Player player = event.getPlayer(); - Block block = event.getBlock(); - boolean noHack = true; - if(player != null) - { - if(checkManager.willCheck(player, CheckType.NO_SWING)) - { - if(backend.checkSwing(player)) - { - event.setCancelled(true); - log("tried to break a block of "+block.getType().name()+" without swinging their arm.",player,CheckType.NO_SWING); - noHack = false; - } - } - if(checkManager.willCheck(player, CheckType.LONG_REACH)) - { - Distance distance = new Distance(player.getLocation(),block.getLocation()); - if(backend.checkLongReachBlock(distance.getXDifference(),distance.getYDifference(),distance.getZDifference())) - { - event.setCancelled(true); - log("tried to break a block of "+block.getType().name()+" that was too far away.",player,CheckType.LONG_REACH); - noHack = false; - } - } - if(checkManager.willCheck(player, CheckType.FAST_BREAK)) - { - if(backend.checkFastBreak(player,block)) - { - event.setCancelled(true); - log("tried to break a block of "+block.getType().name()+" too fast.",player,CheckType.FAST_BREAK); - noHack = false; - } - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() - { - @Override - public void run() - { - backend.checkSwing(player); - } - }, 2L); - } - } - if(noHack) - { - decrease(player); - } - } +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.event; + +import net.h31ix.anticheat.Anticheat; +import net.h31ix.anticheat.manage.Backend; +import net.h31ix.anticheat.manage.CheckManager; +import net.h31ix.anticheat.manage.CheckType; +import net.h31ix.anticheat.manage.Distance; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +public class BlockListener extends EventListener +{ + private final Backend backend = getBackend(); + private final CheckManager checkManager = getCheckManager(); + private final Anticheat plugin = getPlugin(); + + @EventHandler + public void onBlockDamage(BlockDamageEvent event) + { + if(event.getInstaBreak()) + { + backend.logInstantBreak(event.getPlayer()); + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) + { + final Player player = event.getPlayer(); + Block block = event.getBlock(); + if(player != null) + { + if(checkManager.willCheck(player, CheckType.FAST_PLACE)) + { + if(backend.checkFastPlace(player)) + { + event.setCancelled(true); + log("tried to place a block of "+block.getType().name()+" too fast.",player,CheckType.FAST_PLACE); + } + else + { + decrease(player); + backend.logBlockPlace(player); + } + } + } + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + final Player player = event.getPlayer(); + Block block = event.getBlock(); + boolean noHack = true; + if(player != null) + { + if(checkManager.willCheck(player, CheckType.NO_SWING)) + { + if(backend.checkSwing(player)) + { + event.setCancelled(true); + log("tried to break a block of "+block.getType().name()+" without swinging their arm.",player,CheckType.NO_SWING); + noHack = false; + } + } + if(checkManager.willCheck(player, CheckType.LONG_REACH)) + { + Distance distance = new Distance(player.getLocation(),block.getLocation()); + if(backend.checkLongReachBlock(distance.getXDifference(),distance.getYDifference(),distance.getZDifference())) + { + event.setCancelled(true); + log("tried to break a block of "+block.getType().name()+" that was too far away.",player,CheckType.LONG_REACH); + noHack = false; + } + } + if(checkManager.willCheck(player, CheckType.FAST_BREAK)) + { + if(backend.checkFastBreak(player,block)) + { + event.setCancelled(true); + log("tried to break a block of "+block.getType().name()+" too fast.",player,CheckType.FAST_BREAK); + noHack = false; + } + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() + { + @Override + public void run() + { + backend.checkSwing(player); + } + }, 2L); + } + } + if(noHack) + { + decrease(player); + } + } } \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/event/EntityListener.java b/src/main/java/net/h31ix/anticheat/event/EntityListener.java index 956abd5..77e4935 100644 --- a/src/main/java/net/h31ix/anticheat/event/EntityListener.java +++ b/src/main/java/net/h31ix/anticheat/event/EntityListener.java @@ -1,162 +1,162 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.event; - -import net.h31ix.anticheat.manage.Backend; -import net.h31ix.anticheat.manage.CheckManager; -import net.h31ix.anticheat.manage.CheckType; -import net.h31ix.anticheat.manage.Distance; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; -import org.bukkit.event.entity.EntityShootBowEvent; -import org.bukkit.event.entity.FoodLevelChangeEvent; - - -public class EntityListener extends EventListener -{ - private final Backend backend = getBackend(); - private final CheckManager checkManager = getCheckManager(); - - @EventHandler - public void onEntityShootBow(EntityShootBowEvent event) - { - if(event.getEntity() instanceof Player) - { - Player player = (Player)event.getEntity(); - if(checkManager.willCheck(player, CheckType.FAST_BOW)) - { - if(backend.justWoundUp(player)) - { - event.setCancelled(true); - log("tried to fire a bow too fast.",player,CheckType.FAST_BOW); - } - else - { - decrease(player); - } - } - } - } - - @EventHandler - public void onEntityRegainHealth(EntityRegainHealthEvent event) - { - if(event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) - { - Player player = (Player)event.getEntity(); - if(checkManager.willCheck(player, CheckType.FAST_HEAL)) - { - if(backend.justHealed(player)) - { - event.setCancelled(true); - log("tried to heal too fast.",player,CheckType.FAST_HEAL); - } - else - { - decrease(player); - } - } - } - } - - @EventHandler - public void onFoodLevelChange(FoodLevelChangeEvent event) - { - if(event.getEntity() instanceof Player) - { - Player player = (Player)event.getEntity(); - if(checkManager.willCheck(player, CheckType.FAST_EAT)) - { - if(backend.justStartedEating(player)) - { - event.setCancelled(true); - log("tried to eat too fast.",player,CheckType.FAST_EAT); - } - else - { - decrease(player); - } - } - } - } - - @EventHandler - public void onEntityDamage(EntityDamageEvent event) - { - boolean noHack = true; - if (event instanceof EntityDamageByEntityEvent) - { - EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; - if(event.getEntity() instanceof Player) - { - Player player = (Player)event.getEntity(); - if (e.getDamager() instanceof Player) - { - Player p = (Player)e.getDamager(); - backend.logDamage(p); - backend.logDamage(player); - if(checkManager.willCheck(p, CheckType.LONG_REACH)) - { - Distance distance = new Distance(player.getLocation(),p.getLocation()); - if(backend.checkLongReachDamage(distance.getXDifference(),distance.getYDifference(),distance.getZDifference())) - { - event.setCancelled(true); - log("tried to damage a player too far away from them.",p,CheckType.LONG_REACH); - noHack = false; - } - } - } - else - { - backend.logDamage(player); - } - } - if(e.getDamager() instanceof Player) - { - Player player = (Player) e.getDamager(); - if(checkManager.willCheck(player, CheckType.FORCEFIELD)) - { - if(backend.justSprinted(player)) - { - event.setCancelled(true); - log("tried to sprint & damage too fast.",player,CheckType.FORCEFIELD); - noHack = false; - } - } - if(checkManager.willCheck(player, CheckType.NO_SWING)) - { - if(!backend.justAnimated(player)) - { - event.setCancelled(true); - log("tried to damage an entity without swinging their arm.",player,CheckType.NO_SWING); - noHack = false; - } - } - if(noHack) - { - decrease(player); - } - } - } - } +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.event; + +import net.h31ix.anticheat.manage.Backend; +import net.h31ix.anticheat.manage.CheckManager; +import net.h31ix.anticheat.manage.CheckType; +import net.h31ix.anticheat.manage.Distance; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; + + +public class EntityListener extends EventListener +{ + private final Backend backend = getBackend(); + private final CheckManager checkManager = getCheckManager(); + + @EventHandler + public void onEntityShootBow(EntityShootBowEvent event) + { + if(event.getEntity() instanceof Player) + { + Player player = (Player)event.getEntity(); + if(checkManager.willCheck(player, CheckType.FAST_BOW)) + { + if(backend.justWoundUp(player)) + { + event.setCancelled(true); + log("tried to fire a bow too fast.",player,CheckType.FAST_BOW); + } + else + { + decrease(player); + } + } + } + } + + @EventHandler + public void onEntityRegainHealth(EntityRegainHealthEvent event) + { + if(event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) + { + Player player = (Player)event.getEntity(); + if(checkManager.willCheck(player, CheckType.FAST_HEAL)) + { + if(backend.justHealed(player)) + { + event.setCancelled(true); + log("tried to heal too fast.",player,CheckType.FAST_HEAL); + } + else + { + decrease(player); + } + } + } + } + + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) + { + if(event.getEntity() instanceof Player) + { + Player player = (Player)event.getEntity(); + if(checkManager.willCheck(player, CheckType.FAST_EAT)) + { + if(backend.justStartedEating(player)) + { + event.setCancelled(true); + log("tried to eat too fast.",player,CheckType.FAST_EAT); + } + else + { + decrease(player); + } + } + } + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent event) + { + boolean noHack = true; + if (event instanceof EntityDamageByEntityEvent) + { + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; + if(event.getEntity() instanceof Player) + { + Player player = (Player)event.getEntity(); + if (e.getDamager() instanceof Player) + { + Player p = (Player)e.getDamager(); + backend.logDamage(p); + backend.logDamage(player); + if(checkManager.willCheck(p, CheckType.LONG_REACH)) + { + Distance distance = new Distance(player.getLocation(),p.getLocation()); + if(backend.checkLongReachDamage(distance.getXDifference(),distance.getYDifference(),distance.getZDifference())) + { + event.setCancelled(true); + log("tried to damage a player too far away from them.",p,CheckType.LONG_REACH); + noHack = false; + } + } + } + else + { + backend.logDamage(player); + } + } + if(e.getDamager() instanceof Player) + { + Player player = (Player) e.getDamager(); + if(checkManager.willCheck(player, CheckType.FORCEFIELD)) + { + if(backend.justSprinted(player)) + { + event.setCancelled(true); + log("tried to sprint & damage too fast.",player,CheckType.FORCEFIELD); + noHack = false; + } + } + if(checkManager.willCheck(player, CheckType.NO_SWING)) + { + if(!backend.justAnimated(player)) + { + event.setCancelled(true); + log("tried to damage an entity without swinging their arm.",player,CheckType.NO_SWING); + noHack = false; + } + } + if(noHack) + { + decrease(player); + } + } + } + } } \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/event/EventListener.java b/src/main/java/net/h31ix/anticheat/event/EventListener.java index b751e17..0a94cdc 100644 --- a/src/main/java/net/h31ix/anticheat/event/EventListener.java +++ b/src/main/java/net/h31ix/anticheat/event/EventListener.java @@ -1,122 +1,122 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.event; - -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Map; -import net.h31ix.anticheat.Anticheat; -import net.h31ix.anticheat.manage.*; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; - -public class EventListener implements Listener -{ - private static final Map usageList = new EnumMap(CheckType.class); - private static final Map decreaseList = new HashMap(); - private static final CheckManager CHECK_MANAGER = Anticheat.getManager().getCheckManager(); - private static final Backend BACKEND = Anticheat.getManager().getBackend(); - private static final Anticheat PLUGIN = Anticheat.getManager().getPlugin(); - private static final PlayerManager PLAYER_MANAGER = Anticheat.getManager().getPlayerManager(); - - public void log(String message,Player player, CheckType type) - { - if(Anticheat.getManager().getConfiguration().logConsole()) - { - Anticheat.getManager().log(player.getName()+" "+message); - } - PLAYER_MANAGER.increaseLevel(player); - removeDecrease(player); - logCheat(type); - } - - private void logCheat(CheckType type) - { - usageList.put(type, getCheats(type)+1); - } - - public void resetCheck(CheckType type) - { - usageList.put(type, 0); - } - - public int getCheats(CheckType type) - { - int x = 0; - if(usageList.get(type) != null) - { - x = usageList.get(type); - } - return x; - } - - private static void removeDecrease(Player player) - { - int x = 0; - if(decreaseList.get(player.getName()) != null) - { - x = decreaseList.get(player.getName()); - x-=2; - if(x < 0) - { - x = 0; - } - } - decreaseList.put(player.getName(), x); - } - - public static void decrease(Player player) - { - int x = 0; - if(decreaseList.get(player.getName()) != null) - { - x = decreaseList.get(player.getName()); - } - x+=1; - decreaseList.put(player.getName(), x); - if(x >= 10) - { - PLAYER_MANAGER.decreaseLevel(player); - decreaseList.put(player.getName(),0); - } - } - - public static CheckManager getCheckManager() - { - return CHECK_MANAGER; - } - - public static AnticheatManager getManager() { - return Anticheat.getManager(); - } - - public static Backend getBackend() - { - return BACKEND; - } - - public static PlayerManager getPlayerManager() { - return PLAYER_MANAGER; - } - - public static Anticheat getPlugin() - { - return PLUGIN; - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.event; + +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; +import net.h31ix.anticheat.Anticheat; +import net.h31ix.anticheat.manage.*; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +public class EventListener implements Listener +{ + private static final Map usageList = new EnumMap(CheckType.class); + private static final Map decreaseList = new HashMap(); + private static final CheckManager CHECK_MANAGER = Anticheat.getManager().getCheckManager(); + private static final Backend BACKEND = Anticheat.getManager().getBackend(); + private static final Anticheat PLUGIN = Anticheat.getManager().getPlugin(); + private static final PlayerManager PLAYER_MANAGER = Anticheat.getManager().getPlayerManager(); + + public void log(String message,Player player, CheckType type) + { + if(Anticheat.getManager().getConfiguration().logConsole()) + { + Anticheat.getManager().log(player.getName()+" "+message); + } + PLAYER_MANAGER.increaseLevel(player); + removeDecrease(player); + logCheat(type); + } + + private void logCheat(CheckType type) + { + usageList.put(type, getCheats(type)+1); + } + + public void resetCheck(CheckType type) + { + usageList.put(type, 0); + } + + public int getCheats(CheckType type) + { + int x = 0; + if(usageList.get(type) != null) + { + x = usageList.get(type); + } + return x; + } + + private static void removeDecrease(Player player) + { + int x = 0; + if(decreaseList.get(player.getName()) != null) + { + x = decreaseList.get(player.getName()); + x-=2; + if(x < 0) + { + x = 0; + } + } + decreaseList.put(player.getName(), x); + } + + public static void decrease(Player player) + { + int x = 0; + if(decreaseList.get(player.getName()) != null) + { + x = decreaseList.get(player.getName()); + } + x+=1; + decreaseList.put(player.getName(), x); + if(x >= 10) + { + PLAYER_MANAGER.decreaseLevel(player); + decreaseList.put(player.getName(),0); + } + } + + public static CheckManager getCheckManager() + { + return CHECK_MANAGER; + } + + public static AnticheatManager getManager() { + return Anticheat.getManager(); + } + + public static Backend getBackend() + { + return BACKEND; + } + + public static PlayerManager getPlayerManager() { + return PLAYER_MANAGER; + } + + public static Anticheat getPlugin() + { + return PLUGIN; + } +} diff --git a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java index 0644160..1e7c334 100644 --- a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java +++ b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java @@ -1,246 +1,246 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.event; - -import net.h31ix.anticheat.manage.*; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerBedEnterEvent; -import org.bukkit.event.player.PlayerBedLeaveEvent; -import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerToggleSprintEvent; -import org.bukkit.inventory.PlayerInventory; - -public class PlayerListener extends EventListener -{ - private final Backend backend = getBackend(); - private final CheckManager checkManager = getCheckManager(); - - @EventHandler - public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) - { - Player player = event.getPlayer(); - if(checkManager.willCheck(player, CheckType.SPAM)) - { - backend.logChat(player); - } - } - - @EventHandler - public void onPlayerChat(PlayerChatEvent event) - { - Player player = event.getPlayer(); - if(checkManager.willCheck(player, CheckType.SPAM)) - { - backend.logChat(player); - if(backend.checkSpam(player, event.getMessage())) - { - event.setCancelled(true); - player.sendMessage(ChatColor.RED+"Please do not spam."); - } - } - } - - @EventHandler - public void onPlayerKick(PlayerKickEvent event) - { - backend.clearChatLevel(event.getPlayer()); - } - - @EventHandler - public void onPlayerToggleSprint(PlayerToggleSprintEvent event) - { - Player player = event.getPlayer(); - if(checkManager.willCheck(player, CheckType.SPRINT)) - { - if(backend.checkSprint(event)) - { - event.setCancelled(true); - log("tried to sprint while hungry.",player,CheckType.SPRINT); - } - else - { - decrease(player); - } - } - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) - { - Player player = event.getPlayer(); - PlayerInventory inv = player.getInventory(); - if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) - { - Material m = inv.getItemInHand().getType(); - if(m == Material.BOW) - { - backend.logBowWindUp(player); - } - else if(Utilities.isFood(m)) - { - backend.logEatingStart(player); - } - } - } - - @EventHandler - public void onPlayerDropItem(PlayerDropItemEvent event) - { - Player player = event.getPlayer(); - if(checkManager.willCheck(player, CheckType.ITEM_SPAM)) - { - if(backend.justDroppedItem(player)) - { - event.setCancelled(true); - } - else - { - backend.logDroppedItem(player); - } - } - } - - @EventHandler - public void onPlayerEnterBed(PlayerBedEnterEvent event) - { - backend.logEnterExit(event.getPlayer()); - } - - @EventHandler - public void onPlayerExitBed(PlayerBedLeaveEvent event) - { - backend.logEnterExit(event.getPlayer()); - } - - @EventHandler - public void onPlayerAnimation(PlayerAnimationEvent event) - { - Player player = event.getPlayer(); - backend.logAnimation(player); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - if(checkManager.willCheck(player, CheckType.ZOMBE_FLY)) - { - player.sendMessage("§f §f §1 §0 §2 §4"); - } - if(checkManager.willCheck(player, CheckType.ZOMBE_CHEAT)) - { - player.sendMessage("§f §f §2 §0 §4 §8"); - } - if(checkManager.willCheck(player, CheckType.ZOMBE_NOCLIP)) - { - player.sendMessage("§f §f §4 §0 §9 §6"); - } - backend.logJoin(event.getPlayer()); - if(!getPlayerManager().hasLevel(player)) - { - getPlayerManager().setLevel(player, getManager().getConfiguration().getLevel(player.getName())); - } - } - - @EventHandler(priority = EventPriority.LOW) - public void checkExploit(PlayerMoveEvent event) - { - Player player = event.getPlayer(); - Location from = event.getFrom(); - Location to = event.getTo(); - Distance distance = new Distance(from, to); - double x = distance.getXDifference(); - double y = distance.getYDifference(); - double z = distance.getZDifference(); - if(checkManager.willCheck(player, CheckType.FLY) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && backend.checkFlight(player, from.getY(), to.getY())) - { - from.setX(from.getX()-1); - from.setY(from.getY()-1); - from.setZ(from.getZ()-1); - event.setTo(from); - //Lets really give this flyer a real pushdown. - Location newLocation = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY()-2, player.getLocation().getZ()); - Block newBlock = newLocation.getBlock(); - if(newBlock.getTypeId() != 0) - { - event.setTo(newLocation); - } - log("tried to fly.",player,CheckType.FLY); - } - if(checkManager.willCheck(player, CheckType.SPEED) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && checkManager.willCheck(player, CheckType.FLY)) - { - if(event.getFrom().getY() < event.getTo().getY() && backend.checkYSpeed(player, y)) - { - event.setTo(from); - log("tried to ascend to fast.",player,CheckType.SPEED); - } - if(backend.checkXZSpeed(player,x,z)) - { - event.setTo(from); - log("tried to move too fast.",player,CheckType.SPEED); - } - } - if(checkManager.willCheck(player, CheckType.NOFALL) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && checkManager.willCheck(player, CheckType.FLY) && event.getFrom().getY() > event.getTo().getY() && backend.checkNoFall(player, y)) - { - event.setTo(from); - log("tried avoid fall damage.",player,CheckType.NOFALL); - } - } - @EventHandler - public void checkDirSpeed(PlayerMoveEvent event) - { - Player player = event.getPlayer(); - Location from = event.getFrom(); - Location to = event.getTo(); - Distance distance = new Distance(from, to); - double x = distance.getXDifference(); - double y = distance.getYDifference(); - double z = distance.getZDifference(); - if(checkManager.willCheck(player, CheckType.WATER_WALK) && backend.checkWaterWalk(player,x,z)) - { - event.setTo(from); - log("tried to walk on water.",player,CheckType.WATER_WALK); - } - if(checkManager.willCheck(player, CheckType.SNEAK) && backend.checkSneak(player,x,z)) - { - event.setTo(from); - player.setSneaking(false); - log("tried to sneak too fast.",player,CheckType.SNEAK); - } - if(checkManager.willCheck(player, CheckType.SPIDER) && backend.checkSpider(player, y)) - { - event.setTo(from); - log("tried to climb a wall.",player,CheckType.SPIDER); - } - } +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.event; + +import net.h31ix.anticheat.manage.*; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerBedEnterEvent; +import org.bukkit.event.player.PlayerBedLeaveEvent; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.inventory.PlayerInventory; + +public class PlayerListener extends EventListener +{ + private final Backend backend = getBackend(); + private final CheckManager checkManager = getCheckManager(); + + @EventHandler + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) + { + Player player = event.getPlayer(); + if(checkManager.willCheck(player, CheckType.SPAM)) + { + backend.logChat(player); + } + } + + @EventHandler + public void onPlayerChat(PlayerChatEvent event) + { + Player player = event.getPlayer(); + if(checkManager.willCheck(player, CheckType.SPAM)) + { + backend.logChat(player); + if(backend.checkSpam(player, event.getMessage())) + { + event.setCancelled(true); + player.sendMessage(ChatColor.RED+"Please do not spam."); + } + } + } + + @EventHandler + public void onPlayerKick(PlayerKickEvent event) + { + backend.clearChatLevel(event.getPlayer()); + } + + @EventHandler + public void onPlayerToggleSprint(PlayerToggleSprintEvent event) + { + Player player = event.getPlayer(); + if(checkManager.willCheck(player, CheckType.SPRINT)) + { + if(backend.checkSprint(event)) + { + event.setCancelled(true); + log("tried to sprint while hungry.",player,CheckType.SPRINT); + } + else + { + decrease(player); + } + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) + { + Player player = event.getPlayer(); + PlayerInventory inv = player.getInventory(); + if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + Material m = inv.getItemInHand().getType(); + if(m == Material.BOW) + { + backend.logBowWindUp(player); + } + else if(Utilities.isFood(m)) + { + backend.logEatingStart(player); + } + } + } + + @EventHandler + public void onPlayerDropItem(PlayerDropItemEvent event) + { + Player player = event.getPlayer(); + if(checkManager.willCheck(player, CheckType.ITEM_SPAM)) + { + if(backend.justDroppedItem(player)) + { + event.setCancelled(true); + } + else + { + backend.logDroppedItem(player); + } + } + } + + @EventHandler + public void onPlayerEnterBed(PlayerBedEnterEvent event) + { + backend.logEnterExit(event.getPlayer()); + } + + @EventHandler + public void onPlayerExitBed(PlayerBedLeaveEvent event) + { + backend.logEnterExit(event.getPlayer()); + } + + @EventHandler + public void onPlayerAnimation(PlayerAnimationEvent event) + { + Player player = event.getPlayer(); + backend.logAnimation(player); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + if(checkManager.willCheck(player, CheckType.ZOMBE_FLY)) + { + player.sendMessage("§f §f §1 §0 §2 §4"); + } + if(checkManager.willCheck(player, CheckType.ZOMBE_CHEAT)) + { + player.sendMessage("§f §f §2 §0 §4 §8"); + } + if(checkManager.willCheck(player, CheckType.ZOMBE_NOCLIP)) + { + player.sendMessage("§f §f §4 §0 §9 §6"); + } + backend.logJoin(event.getPlayer()); + if(!getPlayerManager().hasLevel(player)) + { + getPlayerManager().setLevel(player, getManager().getConfiguration().getLevel(player.getName())); + } + } + + @EventHandler(priority = EventPriority.LOW) + public void checkExploit(PlayerMoveEvent event) + { + Player player = event.getPlayer(); + Location from = event.getFrom(); + Location to = event.getTo(); + Distance distance = new Distance(from, to); + double x = distance.getXDifference(); + double y = distance.getYDifference(); + double z = distance.getZDifference(); + if(checkManager.willCheck(player, CheckType.FLY) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && backend.checkFlight(player, from.getY(), to.getY())) + { + from.setX(from.getX()-1); + from.setY(from.getY()-1); + from.setZ(from.getZ()-1); + event.setTo(from); + //Lets really give this flyer a real pushdown. + Location newLocation = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY()-2, player.getLocation().getZ()); + Block newBlock = newLocation.getBlock(); + if(newBlock.getTypeId() != 0) + { + event.setTo(newLocation); + } + log("tried to fly.",player,CheckType.FLY); + } + if(checkManager.willCheck(player, CheckType.SPEED) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && checkManager.willCheck(player, CheckType.FLY)) + { + if(event.getFrom().getY() < event.getTo().getY() && backend.checkYSpeed(player, y)) + { + event.setTo(from); + log("tried to ascend to fast.",player,CheckType.SPEED); + } + if(backend.checkXZSpeed(player,x,z)) + { + event.setTo(from); + log("tried to move too fast.",player,CheckType.SPEED); + } + } + if(checkManager.willCheck(player, CheckType.NOFALL) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && checkManager.willCheck(player, CheckType.FLY) && event.getFrom().getY() > event.getTo().getY() && backend.checkNoFall(player, y)) + { + event.setTo(from); + log("tried avoid fall damage.",player,CheckType.NOFALL); + } + } + @EventHandler + public void checkDirSpeed(PlayerMoveEvent event) + { + Player player = event.getPlayer(); + Location from = event.getFrom(); + Location to = event.getTo(); + Distance distance = new Distance(from, to); + double x = distance.getXDifference(); + double y = distance.getYDifference(); + double z = distance.getZDifference(); + if(checkManager.willCheck(player, CheckType.WATER_WALK) && backend.checkWaterWalk(player,x,z)) + { + event.setTo(from); + log("tried to walk on water.",player,CheckType.WATER_WALK); + } + if(checkManager.willCheck(player, CheckType.SNEAK) && backend.checkSneak(player,x,z)) + { + event.setTo(from); + player.setSneaking(false); + log("tried to sneak too fast.",player,CheckType.SNEAK); + } + if(checkManager.willCheck(player, CheckType.SPIDER) && backend.checkSpider(player, y)) + { + event.setTo(from); + log("tried to climb a wall.",player,CheckType.SPIDER); + } + } } \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/event/VehicleListener.java b/src/main/java/net/h31ix/anticheat/event/VehicleListener.java index 2959399..879e818 100644 --- a/src/main/java/net/h31ix/anticheat/event/VehicleListener.java +++ b/src/main/java/net/h31ix/anticheat/event/VehicleListener.java @@ -1,48 +1,48 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.event; - -import net.h31ix.anticheat.manage.Backend; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.vehicle.VehicleEnterEvent; -import org.bukkit.event.vehicle.VehicleExitEvent; - -public class VehicleListener extends EventListener -{ - private final Backend backend = getBackend(); - - @EventHandler - public void onVehicleEnter(VehicleEnterEvent event) - { - if(event.getEntered() instanceof Player) - { - backend.logEnterExit((Player)event.getEntered()); - } - } - - @EventHandler - public void onVehicleExit(VehicleExitEvent event) - { - if(event.getExited() instanceof Player) - { - backend.logEnterExit((Player)event.getExited()); - } - } +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.event; + +import net.h31ix.anticheat.manage.Backend; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.vehicle.VehicleEnterEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; + +public class VehicleListener extends EventListener +{ + private final Backend backend = getBackend(); + + @EventHandler + public void onVehicleEnter(VehicleEnterEvent event) + { + if(event.getEntered() instanceof Player) + { + backend.logEnterExit((Player)event.getEntered()); + } + } + + @EventHandler + public void onVehicleExit(VehicleExitEvent event) + { + if(event.getExited() instanceof Player) + { + backend.logEnterExit((Player)event.getExited()); + } + } } \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java index 5d29f84..0f32c1e 100644 --- a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java @@ -1,89 +1,89 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.manage; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import net.h31ix.anticheat.Anticheat; -import net.h31ix.anticheat.Configuration; -import net.h31ix.anticheat.xray.XRayTracker; - -/** - *

- * The internal hub for all managers. - */ - -public class AnticheatManager -{ - private Anticheat plugin = null; - private Configuration CONFIGURATION = null; - private XRayTracker XRAY_TRACKER = null; - private PlayerManager PLAYER_MANAGER = null; - private CheckManager CHECK_MANAGER = null; - private Backend BACKEND = null; - private Logger LOGGER = null; - - public AnticheatManager(Anticheat instance) - { - plugin = instance; - // now load all the others!!!!! - CONFIGURATION = new Configuration(this); - XRAY_TRACKER = new XRayTracker(); - PLAYER_MANAGER = new PlayerManager(this); - CHECK_MANAGER = new CheckManager(this); - BACKEND = new Backend(this); - LOGGER = Logger.getLogger("Minecraft"); - } - - public void log(String message) - { - LOGGER.log(Level.WARNING,"[AC] ".concat(message)); - } - - public Anticheat getPlugin() - { - return plugin; - } - - public Configuration getConfiguration() - { - return CONFIGURATION; - } - - public XRayTracker getXRayTracker() - { - return XRAY_TRACKER; - } - - public PlayerManager getPlayerManager() - { - return PLAYER_MANAGER; - } - - public CheckManager getCheckManager() - { - return CHECK_MANAGER; - } - - public Backend getBackend() - { - return BACKEND; - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.manage; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.h31ix.anticheat.Anticheat; +import net.h31ix.anticheat.Configuration; +import net.h31ix.anticheat.xray.XRayTracker; + +/** + *

+ * The internal hub for all managers. + */ + +public class AnticheatManager +{ + private Anticheat plugin = null; + private Configuration CONFIGURATION = null; + private XRayTracker XRAY_TRACKER = null; + private PlayerManager PLAYER_MANAGER = null; + private CheckManager CHECK_MANAGER = null; + private Backend BACKEND = null; + private Logger LOGGER = null; + + public AnticheatManager(Anticheat instance) + { + plugin = instance; + // now load all the others!!!!! + CONFIGURATION = new Configuration(this); + XRAY_TRACKER = new XRayTracker(); + PLAYER_MANAGER = new PlayerManager(this); + CHECK_MANAGER = new CheckManager(this); + BACKEND = new Backend(this); + LOGGER = Logger.getLogger("Minecraft"); + } + + public void log(String message) + { + LOGGER.log(Level.WARNING,"[AC] ".concat(message)); + } + + public Anticheat getPlugin() + { + return plugin; + } + + public Configuration getConfiguration() + { + return CONFIGURATION; + } + + public XRayTracker getXRayTracker() + { + return XRAY_TRACKER; + } + + public PlayerManager getPlayerManager() + { + return PLAYER_MANAGER; + } + + public CheckManager getCheckManager() + { + return CHECK_MANAGER; + } + + public Backend getBackend() + { + return BACKEND; + } +} diff --git a/src/main/java/net/h31ix/anticheat/manage/Backend.java b/src/main/java/net/h31ix/anticheat/manage/Backend.java index aa80dc2..1e69d41 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Backend.java +++ b/src/main/java/net/h31ix/anticheat/manage/Backend.java @@ -1,625 +1,625 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.manage; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerToggleSprintEvent; - -public class Backend -{ - public static final int ENTERED_EXTITED_TIME = 20; - public static final int INSTANT_BREAK_TIME = 20; - public static final int JOIN_TIME = 40; - public static final int DROPPED_ITEM_TIME = 2; - public static final int DAMAGE_TIME = 50; - public static final int KNOCKBACK_DAMAGE_TIME = 50; - - public static final int FASTBREAK_LIMIT = 3; - public static final int FASTBREAK_TIMEMAX = 500; - public static final int FASTBREAK_MAXVIOLATIONS = 2; - public static final int FASTBREAK_MAXVIOLATIONTIME = 10000; - public static final int FASTPLACE_LIMIT = 2; - public static final int FASTPLACE_ZEROLIMIT = 3; - public static final int FASTPLACE_TIMEMAX = 100; - public static final int FASTPLACE_MAXVIOLATIONS = 2; - public static final int FASTPLACE_MAXVIOLATIONTIME = 10000; - - private static final int CHAT_WARN_LEVEL = 7; - private static final int CHAT_KICK_LEVEL = 10; - private static final int CHAT_BAN_LEVEL = 3; - - public static final int FLIGHT_LIMIT = 4; - public static final int NOFALL_LIMIT = 5; - - public static final int SPRINT_FOOD_MIN = 6; - public static final int EAT_MIN = 20; - public static final int HEAL_MIN = 35; - public static final int ANIMATION_MIN = 60; - public static final int CHAT_MIN = 100; - public static final int BOW_MIN = 2; - public static final int SPRINT_MIN = 2; - public static final int BLOCK_BREAK_MIN = 1; - public static final long BLOCK_PLACE_MIN = 1/3; - - public static final double BLOCK_MAX_DISTANCE = 6.0; - public static final double ENTITY_MAX_DISTANCE = 5.5; - - public static final double LADDER_Y_MAX = 0.11761; - public static final double LADDER_Y_MIN = 0.11759; - - public static final double Y_SPEED_MAX = 0.5; - public static final double XZ_SPEED_MAX = 0.4; - public static final double XZ_SPEED_MAX_SPRINT = 0.65; - public static final double XZ_SPEED_MAX_SNEAK = 0.2; - public static final double XZ_SPEED_MAX_WATER = 0.19; - public static final double XZ_SPEED_MAX_WATER_SPRINT = 0.3; - - private AnticheatManager micromanage = null; - private List droppedItem = new ArrayList(); - private List animated = new ArrayList(); - private List movingExempt = new ArrayList(); - private List brokenBlock = new ArrayList(); - private List placedBlock = new ArrayList(); - private List bowWindUp = new ArrayList(); - private List startEat = new ArrayList(); - private List healed = new ArrayList(); - private List sprinted = new ArrayList(); - private List instantBreakExempt = new ArrayList(); - private Map oldMessage = new HashMap(); - private Map lastMessage = new HashMap(); - private Map flightViolation = new HashMap(); - private Map chatLevel = new HashMap(); - private Map chatKicks = new HashMap(); - private Map nofallViolation = new HashMap(); - private Map fastBreakViolation = new HashMap(); - private Map blocksBroken = new HashMap(); - private Map lastBlockBroken = new HashMap(); - private Map fastPlaceViolation = new HashMap(); - private Map lastZeroHitPlace = new HashMap(); - private Map lastBlockPlaced = new HashMap(); - private Map lastBlockPlaceTime = new HashMap(); - - public Backend(AnticheatManager instance) - { - micromanage = instance; - } - - public boolean checkLongReachBlock(double x,double y,double z) - { - return x >= BLOCK_MAX_DISTANCE || y > BLOCK_MAX_DISTANCE || z > BLOCK_MAX_DISTANCE; - } - - public boolean checkLongReachDamage(double x,double y,double z) - { - return x >= ENTITY_MAX_DISTANCE || y > ENTITY_MAX_DISTANCE || z > ENTITY_MAX_DISTANCE; - } - - public boolean checkSpider(Player player,double y) - { - if(y <= LADDER_Y_MAX && y >= LADDER_Y_MIN && player.getLocation().getBlock().getType() != Material.VINE && player.getLocation().getBlock().getType() != Material.LADDER) - { - return true; - } - return false; - } - - public boolean checkYSpeed(Player player,double y) - { - if(!player.isFlying() && player.getVehicle() == null && y > Y_SPEED_MAX) - { - return true; - } - return false; - } - - public boolean checkNoFall(Player player, double y) - { - String name = player.getName(); - if(player.getGameMode() != GameMode.CREATIVE && player.getVehicle() == null && !isMovingExempt(player)) - { - if(player.getFallDistance() == 0) - { - if(nofallViolation.get(name) == null) - { - nofallViolation.put(name,1); - } - else - { - nofallViolation.put(name,nofallViolation.get(player.getName())+1); - } - - if(nofallViolation.get(name) >= NOFALL_LIMIT) - { - nofallViolation.put(player.getName(),1); - return true; - } - else - { - return false; - } - } - else - { - nofallViolation.put(name,0); - return false; - } - } - return false; - } - - public boolean checkXZSpeed(Player player,double x,double z) - { - if(!isMovingExempt(player) && player.getVehicle() == null) - { - if(!player.isSprinting()) - { - return x > XZ_SPEED_MAX || z > XZ_SPEED_MAX; - } - else - { - return x > XZ_SPEED_MAX_SPRINT || z > XZ_SPEED_MAX_SPRINT; - } - } - else - { - return false; - } - } - - public boolean checkSneak(Player player,double x,double z) - { - if(player.isSneaking()) - { - return x > XZ_SPEED_MAX_SNEAK || z > XZ_SPEED_MAX_SNEAK; - } - else - { - return false; - } - } - - public boolean checkSprint(PlayerToggleSprintEvent event) - { - Player player = event.getPlayer(); - if(event.isSprinting()) - { - return player.getFoodLevel() <= SPRINT_FOOD_MIN && player.getGameMode() != GameMode.CREATIVE; - } - else - { - return false; - } - } - - public boolean checkWaterWalk(Player player, double x, double z) - { - Block block = player.getLocation().getBlock(); - if(block.isLiquid() && player.getVehicle() == null) - { - if(x > XZ_SPEED_MAX_WATER || z > XZ_SPEED_MAX_WATER && !Utilities.sprintFly(player) && player.getNearbyEntities(1, 1, 1).isEmpty()) - { - return true; - } - else if(x > XZ_SPEED_MAX_WATER_SPRINT || z > XZ_SPEED_MAX_WATER_SPRINT) - { - return true; - } - } - return false; - } - - public boolean checkFlight(Player player, double y1, double y2) - { - Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN); - if(y1 == y2 && !isMovingExempt(player) && player.getVehicle() == null && player.getFallDistance() == 0 && !Utilities.isOnLilyPad(player)) - { - String name = player.getName(); - if(Utilities.cantStandAt(block) && !Utilities.isOnLilyPad(player) && !Utilities.canStand(player.getLocation().getBlock())) - { - int violation = 1; - if(!flightViolation.containsKey(name)) - { - flightViolation.put(name, violation); - } - else - { - violation = flightViolation.get(name)+1; - flightViolation.put(name, violation); - } - if(violation >= FLIGHT_LIMIT) - { - System.out.println("yep"); - flightViolation.put(name, 1); - return true; - } - //Start Fly bypass patch. - if(flightViolation.containsKey(name) && flightViolation.get(name) > 0) - { - for(int i= 5;i>0;i--) - { - System.out.println(i); - Location newLocation = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY()-i, player.getLocation().getZ()); - Block lower = newLocation.getBlock(); - if(lower.getTypeId() == 0) - { - player.teleport(newLocation); - break; - } - } - } - //End Fly bypass patch. - } - } - return false; - } - - public boolean checkSwing(Player player) - { - return !justAnimated(player); - } - - public boolean checkFastBreak(Player player, Block block) - { - String name = player.getName(); - if(!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !Utilities.isInstantBreak(block.getType()) && !isInstantBreakExempt(player) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES && player.getGameMode() != GameMode.CREATIVE)) - { - if (!fastBreakViolation.containsKey(name)) - { - fastBreakViolation.put(name, 0); - } - else - { - Long math = System.currentTimeMillis() - lastBlockBroken.get(name); - if(fastBreakViolation.get(name) > FASTBREAK_MAXVIOLATIONS && math < FASTBREAK_MAXVIOLATIONTIME) - { - lastBlockBroken.put(name, System.currentTimeMillis()); - player.sendMessage(ChatColor.RED + "[AntiCheat] Fastbreaking detected. Please wait 10 seconds before breaking blocks."); - return true; - } - else if(fastBreakViolation.get(name) > 0 && math > FASTBREAK_MAXVIOLATIONTIME) - { - fastBreakViolation.put(name, 0); - } - } - if (!blocksBroken.containsKey(name) || !lastBlockBroken.containsKey(name)) - { - if(!lastBlockBroken.containsKey(name)) - { - lastBlockBroken.put(name, System.currentTimeMillis()); - } - blocksBroken.put(name, 0); - } - else - { - blocksBroken.put(name, blocksBroken.get(name)+1); - Long math = System.currentTimeMillis() - lastBlockBroken.get(name); - if(blocksBroken.get(name) > FASTBREAK_LIMIT && math < FASTBREAK_TIMEMAX) - { - blocksBroken.put(name, 0); - lastBlockBroken.put(name, System.currentTimeMillis()); - fastBreakViolation.put(name, fastBreakViolation.get(name)+1); - return true; - } - else if(blocksBroken.get(name) > FASTBREAK_LIMIT) - { - lastBlockBroken.put(name, System.currentTimeMillis()); - blocksBroken.put(name, 0); - } - } - } - return false; - } - - public boolean checkFastPlace(Player player) - { - long time = System.currentTimeMillis(); - String name = player.getName(); - if(!lastBlockPlaceTime.containsKey(name) || !fastPlaceViolation.containsKey(name)) - { - lastBlockPlaceTime.put(name, Long.parseLong("0")); - if(!fastPlaceViolation.containsKey(name)) - { - fastPlaceViolation.put(name, 0); - } - } - else if(fastPlaceViolation.containsKey(name) && fastPlaceViolation.get(name) > FASTPLACE_MAXVIOLATIONS) - { - Long math = System.currentTimeMillis() - lastBlockPlaced.get(name); - if(lastBlockPlaced.get(name) > 0 && math < FASTPLACE_MAXVIOLATIONTIME) - { - lastBlockPlaced.put(name, time); - player.sendMessage(ChatColor.RED + "[AntiCheat] Fastplacing detected. Please wait 10 seconds before placing blocks."); - return true; - } - else if (lastBlockPlaced.get(name) > 0 && math > FASTPLACE_MAXVIOLATIONTIME) - { - fastPlaceViolation.put(name, 0); - } - } - else if(lastBlockPlaced.containsKey(name)) - { - long last = lastBlockPlaced.get(name); - long lastTime = lastBlockPlaceTime.get(name); - long thisTime = time-last; - boolean nocheck = thisTime < 1 || lastTime < 1; - if(!lastZeroHitPlace.containsKey(name)) - { - lastZeroHitPlace.put(name, 0); - } - if(nocheck) - { - if(!lastZeroHitPlace.containsKey(name)) - { - lastZeroHitPlace.put(name, 1); - } - else - { - lastZeroHitPlace.put(name, lastZeroHitPlace.get(name)+1); - } - } - if(!nocheck && thisTime < FASTPLACE_TIMEMAX && lastTime < FASTPLACE_TIMEMAX - && lastZeroHitPlace.get(name) > FASTPLACE_ZEROLIMIT) - { - lastBlockPlaceTime.put(name, (time-last)); - lastBlockPlaced.put(name, time); - fastPlaceViolation.put(name, fastPlaceViolation.get(name)+1); - return true; - } - lastBlockPlaceTime.put(name, (time-last)); - } - lastBlockPlaced.put(name, time); - return false; - } - - public void logBowWindUp(Player player) - { - logEvent(bowWindUp,player,BOW_MIN); - } - - public boolean justWoundUp(Player player) - { - return bowWindUp.contains(player.getName()); - } - - public void logEatingStart(Player player) - { - logEvent(startEat,player,EAT_MIN); - } - - public boolean justStartedEating(Player player) - { - return startEat.contains(player.getName()); - } - - public void logHeal(Player player) - { - logEvent(healed,player,HEAL_MIN); - } - - public boolean justHealed(Player player) - { - return healed.contains(player.getName()); - } - - public void logChat(Player player) - { - String name = player.getName(); - if(chatLevel.get(name) == null) - { - logEvent(chatLevel,player,1,CHAT_MIN); - } - else - { - int amount = chatLevel.get(name)+1; - chatLevel.put(name, amount); - checkChatLevel(player, amount); - } - } - - public boolean checkSpam(Player player, String msg) - { - String name = player.getName(); - if(lastMessage.get(name) == null) - { - lastMessage.put(name, msg); - } - else - { - if(oldMessage.get(name) != null && lastMessage.get(name).equals(msg) && oldMessage.get(name).equals(msg)) - { - return true; - } - else - { - oldMessage.put(name, lastMessage.get(name)); - lastMessage.put(name, msg); - return false; - } - } - return false; - } - - public void clearChatLevel(Player player) - { - chatLevel.remove(player.getName()); - } - - public void logInstantBreak(final Player player) - { - logEvent(instantBreakExempt,player,INSTANT_BREAK_TIME); - } - - public boolean isInstantBreakExempt(Player player) - { - return instantBreakExempt.contains(player.getName()); - } - - public void logSprint(final Player player) - { - logEvent(sprinted,player,SPRINT_MIN); - } - - public boolean justSprinted(Player player) - { - return sprinted.contains(player.getName()); - } - - public void logBlockBreak(final Player player) - { - logEvent(brokenBlock,player,BLOCK_BREAK_MIN); - } - - public boolean justBroke(Player player) - { - return brokenBlock.contains(player.getName()); - } - - public void logBlockPlace(final Player player) - { - logEvent(placedBlock,player,BLOCK_PLACE_MIN); - } - - public boolean justPlaced(Player player) - { - return placedBlock.contains(player.getName()); - } - - public void logAnimation(final Player player) - { - logEvent(animated,player,ANIMATION_MIN); - } - - public void resetAnimation(final Player player) - { - animated.remove(player.getName()); - } - - public boolean justAnimated(Player player) - { - return animated.contains(player.getName()); - } - - public void logDamage(final Player player) - { - int time = DAMAGE_TIME; - if(player.getInventory().getItemInHand().getEnchantments().containsKey(Enchantment.KNOCKBACK)) - { - time = KNOCKBACK_DAMAGE_TIME; - } - logEvent(movingExempt,player,time); - } - - public void logEnterExit(final Player player) - { - logEvent(movingExempt,player,ENTERED_EXTITED_TIME); - } - - public void logJoin(final Player player) - { - logEvent(movingExempt,player,JOIN_TIME); - } - - public boolean isMovingExempt(Player player) - { - return movingExempt.contains(player.getName()) || player.isFlying(); - } - - public void logDroppedItem(final Player player) - { - logEvent(droppedItem,player,DROPPED_ITEM_TIME); - } - - public boolean justDroppedItem(Player player) - { - return droppedItem.contains(player.getName()); - } - - @SuppressWarnings("unchecked") - private void logEvent(@SuppressWarnings("rawtypes") final List list, final Player player, long time) - { - list.add(player.getName()); - micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable() - { - @Override - public void run() - { - list.remove(player.getName()); - } - }, time); - } - - @SuppressWarnings("unchecked") - private void logEvent(@SuppressWarnings("rawtypes") final Map map, final Player player, final Object obj, long time) - { - map.put(player,obj); - micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable() - { - @Override - public void run() - { - map.remove(player); - } - }, time); - } - private void checkChatLevel(Player player, int amount) - { - if(amount >= CHAT_WARN_LEVEL) - { - player.sendMessage(ChatColor.RED+"Please stop flooding the server!"); - } - if (amount >= CHAT_KICK_LEVEL) - { - String name = player.getName(); - int kick = 0; - if(chatKicks.get(name) == null || chatKicks.get(name) == 0) - { - kick = 1; - chatKicks.put(name, 1); - } - else - { - kick = (int)chatKicks.get(name)+1; - chatKicks.put(name, kick); - } - - if(chatKicks.get(name) <= CHAT_BAN_LEVEL) - { - player.kickPlayer(ChatColor.RED+"Spamming, kick "+kick+"/3"); - micromanage.getPlugin().getServer().broadcastMessage(ChatColor.RED+player.getName()+" was kicked for spamming."); - } - else - { - player.kickPlayer(ChatColor.RED+"Banned for spamming."); - player.setBanned(true); - micromanage.getPlugin().getServer().broadcastMessage(ChatColor.RED+player.getName()+" was banned for spamming."); - } - } - } +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.manage; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerToggleSprintEvent; + +public class Backend +{ + public static final int ENTERED_EXTITED_TIME = 20; + public static final int INSTANT_BREAK_TIME = 20; + public static final int JOIN_TIME = 40; + public static final int DROPPED_ITEM_TIME = 2; + public static final int DAMAGE_TIME = 50; + public static final int KNOCKBACK_DAMAGE_TIME = 50; + + public static final int FASTBREAK_LIMIT = 3; + public static final int FASTBREAK_TIMEMAX = 500; + public static final int FASTBREAK_MAXVIOLATIONS = 2; + public static final int FASTBREAK_MAXVIOLATIONTIME = 10000; + public static final int FASTPLACE_LIMIT = 2; + public static final int FASTPLACE_ZEROLIMIT = 3; + public static final int FASTPLACE_TIMEMAX = 100; + public static final int FASTPLACE_MAXVIOLATIONS = 2; + public static final int FASTPLACE_MAXVIOLATIONTIME = 10000; + + private static final int CHAT_WARN_LEVEL = 7; + private static final int CHAT_KICK_LEVEL = 10; + private static final int CHAT_BAN_LEVEL = 3; + + public static final int FLIGHT_LIMIT = 4; + public static final int NOFALL_LIMIT = 5; + + public static final int SPRINT_FOOD_MIN = 6; + public static final int EAT_MIN = 20; + public static final int HEAL_MIN = 35; + public static final int ANIMATION_MIN = 60; + public static final int CHAT_MIN = 100; + public static final int BOW_MIN = 2; + public static final int SPRINT_MIN = 2; + public static final int BLOCK_BREAK_MIN = 1; + public static final long BLOCK_PLACE_MIN = 1/3; + + public static final double BLOCK_MAX_DISTANCE = 6.0; + public static final double ENTITY_MAX_DISTANCE = 5.5; + + public static final double LADDER_Y_MAX = 0.11761; + public static final double LADDER_Y_MIN = 0.11759; + + public static final double Y_SPEED_MAX = 0.5; + public static final double XZ_SPEED_MAX = 0.4; + public static final double XZ_SPEED_MAX_SPRINT = 0.65; + public static final double XZ_SPEED_MAX_SNEAK = 0.2; + public static final double XZ_SPEED_MAX_WATER = 0.19; + public static final double XZ_SPEED_MAX_WATER_SPRINT = 0.3; + + private AnticheatManager micromanage = null; + private List droppedItem = new ArrayList(); + private List animated = new ArrayList(); + private List movingExempt = new ArrayList(); + private List brokenBlock = new ArrayList(); + private List placedBlock = new ArrayList(); + private List bowWindUp = new ArrayList(); + private List startEat = new ArrayList(); + private List healed = new ArrayList(); + private List sprinted = new ArrayList(); + private List instantBreakExempt = new ArrayList(); + private Map oldMessage = new HashMap(); + private Map lastMessage = new HashMap(); + private Map flightViolation = new HashMap(); + private Map chatLevel = new HashMap(); + private Map chatKicks = new HashMap(); + private Map nofallViolation = new HashMap(); + private Map fastBreakViolation = new HashMap(); + private Map blocksBroken = new HashMap(); + private Map lastBlockBroken = new HashMap(); + private Map fastPlaceViolation = new HashMap(); + private Map lastZeroHitPlace = new HashMap(); + private Map lastBlockPlaced = new HashMap(); + private Map lastBlockPlaceTime = new HashMap(); + + public Backend(AnticheatManager instance) + { + micromanage = instance; + } + + public boolean checkLongReachBlock(double x,double y,double z) + { + return x >= BLOCK_MAX_DISTANCE || y > BLOCK_MAX_DISTANCE || z > BLOCK_MAX_DISTANCE; + } + + public boolean checkLongReachDamage(double x,double y,double z) + { + return x >= ENTITY_MAX_DISTANCE || y > ENTITY_MAX_DISTANCE || z > ENTITY_MAX_DISTANCE; + } + + public boolean checkSpider(Player player,double y) + { + if(y <= LADDER_Y_MAX && y >= LADDER_Y_MIN && player.getLocation().getBlock().getType() != Material.VINE && player.getLocation().getBlock().getType() != Material.LADDER) + { + return true; + } + return false; + } + + public boolean checkYSpeed(Player player,double y) + { + if(!player.isFlying() && player.getVehicle() == null && y > Y_SPEED_MAX) + { + return true; + } + return false; + } + + public boolean checkNoFall(Player player, double y) + { + String name = player.getName(); + if(player.getGameMode() != GameMode.CREATIVE && player.getVehicle() == null && !isMovingExempt(player)) + { + if(player.getFallDistance() == 0) + { + if(nofallViolation.get(name) == null) + { + nofallViolation.put(name,1); + } + else + { + nofallViolation.put(name,nofallViolation.get(player.getName())+1); + } + + if(nofallViolation.get(name) >= NOFALL_LIMIT) + { + nofallViolation.put(player.getName(),1); + return true; + } + else + { + return false; + } + } + else + { + nofallViolation.put(name,0); + return false; + } + } + return false; + } + + public boolean checkXZSpeed(Player player,double x,double z) + { + if(!isMovingExempt(player) && player.getVehicle() == null) + { + if(!player.isSprinting()) + { + return x > XZ_SPEED_MAX || z > XZ_SPEED_MAX; + } + else + { + return x > XZ_SPEED_MAX_SPRINT || z > XZ_SPEED_MAX_SPRINT; + } + } + else + { + return false; + } + } + + public boolean checkSneak(Player player,double x,double z) + { + if(player.isSneaking()) + { + return x > XZ_SPEED_MAX_SNEAK || z > XZ_SPEED_MAX_SNEAK; + } + else + { + return false; + } + } + + public boolean checkSprint(PlayerToggleSprintEvent event) + { + Player player = event.getPlayer(); + if(event.isSprinting()) + { + return player.getFoodLevel() <= SPRINT_FOOD_MIN && player.getGameMode() != GameMode.CREATIVE; + } + else + { + return false; + } + } + + public boolean checkWaterWalk(Player player, double x, double z) + { + Block block = player.getLocation().getBlock(); + if(block.isLiquid() && player.getVehicle() == null) + { + if(x > XZ_SPEED_MAX_WATER || z > XZ_SPEED_MAX_WATER && !Utilities.sprintFly(player) && player.getNearbyEntities(1, 1, 1).isEmpty()) + { + return true; + } + else if(x > XZ_SPEED_MAX_WATER_SPRINT || z > XZ_SPEED_MAX_WATER_SPRINT) + { + return true; + } + } + return false; + } + + public boolean checkFlight(Player player, double y1, double y2) + { + Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN); + if(y1 == y2 && !isMovingExempt(player) && player.getVehicle() == null && player.getFallDistance() == 0 && !Utilities.isOnLilyPad(player)) + { + String name = player.getName(); + if(Utilities.cantStandAt(block) && !Utilities.isOnLilyPad(player) && !Utilities.canStand(player.getLocation().getBlock())) + { + int violation = 1; + if(!flightViolation.containsKey(name)) + { + flightViolation.put(name, violation); + } + else + { + violation = flightViolation.get(name)+1; + flightViolation.put(name, violation); + } + if(violation >= FLIGHT_LIMIT) + { + System.out.println("yep"); + flightViolation.put(name, 1); + return true; + } + //Start Fly bypass patch. + if(flightViolation.containsKey(name) && flightViolation.get(name) > 0) + { + for(int i= 5;i>0;i--) + { + System.out.println(i); + Location newLocation = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY()-i, player.getLocation().getZ()); + Block lower = newLocation.getBlock(); + if(lower.getTypeId() == 0) + { + player.teleport(newLocation); + break; + } + } + } + //End Fly bypass patch. + } + } + return false; + } + + public boolean checkSwing(Player player) + { + return !justAnimated(player); + } + + public boolean checkFastBreak(Player player, Block block) + { + String name = player.getName(); + if(!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !Utilities.isInstantBreak(block.getType()) && !isInstantBreakExempt(player) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES && player.getGameMode() != GameMode.CREATIVE)) + { + if (!fastBreakViolation.containsKey(name)) + { + fastBreakViolation.put(name, 0); + } + else + { + Long math = System.currentTimeMillis() - lastBlockBroken.get(name); + if(fastBreakViolation.get(name) > FASTBREAK_MAXVIOLATIONS && math < FASTBREAK_MAXVIOLATIONTIME) + { + lastBlockBroken.put(name, System.currentTimeMillis()); + player.sendMessage(ChatColor.RED + "[AntiCheat] Fastbreaking detected. Please wait 10 seconds before breaking blocks."); + return true; + } + else if(fastBreakViolation.get(name) > 0 && math > FASTBREAK_MAXVIOLATIONTIME) + { + fastBreakViolation.put(name, 0); + } + } + if (!blocksBroken.containsKey(name) || !lastBlockBroken.containsKey(name)) + { + if(!lastBlockBroken.containsKey(name)) + { + lastBlockBroken.put(name, System.currentTimeMillis()); + } + blocksBroken.put(name, 0); + } + else + { + blocksBroken.put(name, blocksBroken.get(name)+1); + Long math = System.currentTimeMillis() - lastBlockBroken.get(name); + if(blocksBroken.get(name) > FASTBREAK_LIMIT && math < FASTBREAK_TIMEMAX) + { + blocksBroken.put(name, 0); + lastBlockBroken.put(name, System.currentTimeMillis()); + fastBreakViolation.put(name, fastBreakViolation.get(name)+1); + return true; + } + else if(blocksBroken.get(name) > FASTBREAK_LIMIT) + { + lastBlockBroken.put(name, System.currentTimeMillis()); + blocksBroken.put(name, 0); + } + } + } + return false; + } + + public boolean checkFastPlace(Player player) + { + long time = System.currentTimeMillis(); + String name = player.getName(); + if(!lastBlockPlaceTime.containsKey(name) || !fastPlaceViolation.containsKey(name)) + { + lastBlockPlaceTime.put(name, Long.parseLong("0")); + if(!fastPlaceViolation.containsKey(name)) + { + fastPlaceViolation.put(name, 0); + } + } + else if(fastPlaceViolation.containsKey(name) && fastPlaceViolation.get(name) > FASTPLACE_MAXVIOLATIONS) + { + Long math = System.currentTimeMillis() - lastBlockPlaced.get(name); + if(lastBlockPlaced.get(name) > 0 && math < FASTPLACE_MAXVIOLATIONTIME) + { + lastBlockPlaced.put(name, time); + player.sendMessage(ChatColor.RED + "[AntiCheat] Fastplacing detected. Please wait 10 seconds before placing blocks."); + return true; + } + else if (lastBlockPlaced.get(name) > 0 && math > FASTPLACE_MAXVIOLATIONTIME) + { + fastPlaceViolation.put(name, 0); + } + } + else if(lastBlockPlaced.containsKey(name)) + { + long last = lastBlockPlaced.get(name); + long lastTime = lastBlockPlaceTime.get(name); + long thisTime = time-last; + boolean nocheck = thisTime < 1 || lastTime < 1; + if(!lastZeroHitPlace.containsKey(name)) + { + lastZeroHitPlace.put(name, 0); + } + if(nocheck) + { + if(!lastZeroHitPlace.containsKey(name)) + { + lastZeroHitPlace.put(name, 1); + } + else + { + lastZeroHitPlace.put(name, lastZeroHitPlace.get(name)+1); + } + } + if(!nocheck && thisTime < FASTPLACE_TIMEMAX && lastTime < FASTPLACE_TIMEMAX + && lastZeroHitPlace.get(name) > FASTPLACE_ZEROLIMIT) + { + lastBlockPlaceTime.put(name, (time-last)); + lastBlockPlaced.put(name, time); + fastPlaceViolation.put(name, fastPlaceViolation.get(name)+1); + return true; + } + lastBlockPlaceTime.put(name, (time-last)); + } + lastBlockPlaced.put(name, time); + return false; + } + + public void logBowWindUp(Player player) + { + logEvent(bowWindUp,player,BOW_MIN); + } + + public boolean justWoundUp(Player player) + { + return bowWindUp.contains(player.getName()); + } + + public void logEatingStart(Player player) + { + logEvent(startEat,player,EAT_MIN); + } + + public boolean justStartedEating(Player player) + { + return startEat.contains(player.getName()); + } + + public void logHeal(Player player) + { + logEvent(healed,player,HEAL_MIN); + } + + public boolean justHealed(Player player) + { + return healed.contains(player.getName()); + } + + public void logChat(Player player) + { + String name = player.getName(); + if(chatLevel.get(name) == null) + { + logEvent(chatLevel,player,1,CHAT_MIN); + } + else + { + int amount = chatLevel.get(name)+1; + chatLevel.put(name, amount); + checkChatLevel(player, amount); + } + } + + public boolean checkSpam(Player player, String msg) + { + String name = player.getName(); + if(lastMessage.get(name) == null) + { + lastMessage.put(name, msg); + } + else + { + if(oldMessage.get(name) != null && lastMessage.get(name).equals(msg) && oldMessage.get(name).equals(msg)) + { + return true; + } + else + { + oldMessage.put(name, lastMessage.get(name)); + lastMessage.put(name, msg); + return false; + } + } + return false; + } + + public void clearChatLevel(Player player) + { + chatLevel.remove(player.getName()); + } + + public void logInstantBreak(final Player player) + { + logEvent(instantBreakExempt,player,INSTANT_BREAK_TIME); + } + + public boolean isInstantBreakExempt(Player player) + { + return instantBreakExempt.contains(player.getName()); + } + + public void logSprint(final Player player) + { + logEvent(sprinted,player,SPRINT_MIN); + } + + public boolean justSprinted(Player player) + { + return sprinted.contains(player.getName()); + } + + public void logBlockBreak(final Player player) + { + logEvent(brokenBlock,player,BLOCK_BREAK_MIN); + } + + public boolean justBroke(Player player) + { + return brokenBlock.contains(player.getName()); + } + + public void logBlockPlace(final Player player) + { + logEvent(placedBlock,player,BLOCK_PLACE_MIN); + } + + public boolean justPlaced(Player player) + { + return placedBlock.contains(player.getName()); + } + + public void logAnimation(final Player player) + { + logEvent(animated,player,ANIMATION_MIN); + } + + public void resetAnimation(final Player player) + { + animated.remove(player.getName()); + } + + public boolean justAnimated(Player player) + { + return animated.contains(player.getName()); + } + + public void logDamage(final Player player) + { + int time = DAMAGE_TIME; + if(player.getInventory().getItemInHand().getEnchantments().containsKey(Enchantment.KNOCKBACK)) + { + time = KNOCKBACK_DAMAGE_TIME; + } + logEvent(movingExempt,player,time); + } + + public void logEnterExit(final Player player) + { + logEvent(movingExempt,player,ENTERED_EXTITED_TIME); + } + + public void logJoin(final Player player) + { + logEvent(movingExempt,player,JOIN_TIME); + } + + public boolean isMovingExempt(Player player) + { + return movingExempt.contains(player.getName()) || player.isFlying(); + } + + public void logDroppedItem(final Player player) + { + logEvent(droppedItem,player,DROPPED_ITEM_TIME); + } + + public boolean justDroppedItem(Player player) + { + return droppedItem.contains(player.getName()); + } + + @SuppressWarnings("unchecked") + private void logEvent(@SuppressWarnings("rawtypes") final List list, final Player player, long time) + { + list.add(player.getName()); + micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable() + { + @Override + public void run() + { + list.remove(player.getName()); + } + }, time); + } + + @SuppressWarnings("unchecked") + private void logEvent(@SuppressWarnings("rawtypes") final Map map, final Player player, final Object obj, long time) + { + map.put(player,obj); + micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable() + { + @Override + public void run() + { + map.remove(player); + } + }, time); + } + private void checkChatLevel(Player player, int amount) + { + if(amount >= CHAT_WARN_LEVEL) + { + player.sendMessage(ChatColor.RED+"Please stop flooding the server!"); + } + if (amount >= CHAT_KICK_LEVEL) + { + String name = player.getName(); + int kick = 0; + if(chatKicks.get(name) == null || chatKicks.get(name) == 0) + { + kick = 1; + chatKicks.put(name, 1); + } + else + { + kick = (int)chatKicks.get(name)+1; + chatKicks.put(name, kick); + } + + if(chatKicks.get(name) <= CHAT_BAN_LEVEL) + { + player.kickPlayer(ChatColor.RED+"Spamming, kick "+kick+"/3"); + micromanage.getPlugin().getServer().broadcastMessage(ChatColor.RED+player.getName()+" was kicked for spamming."); + } + else + { + player.kickPlayer(ChatColor.RED+"Banned for spamming."); + player.setBanned(true); + micromanage.getPlugin().getServer().broadcastMessage(ChatColor.RED+player.getName()+" was banned for spamming."); + } + } + } } \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/manage/CheckManager.java b/src/main/java/net/h31ix/anticheat/manage/CheckManager.java index c43be3f..233a9eb 100644 --- a/src/main/java/net/h31ix/anticheat/manage/CheckManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/CheckManager.java @@ -1,89 +1,89 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.manage; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.entity.Player; - -/** - *

- * The manager that AntiCheat will check with to see if it should watch certain checks and certain players. - */ - -public class CheckManager -{ - public AnticheatManager manager = null; - private static List checkIgnoreList = new ArrayList(); - private static Multimap exemptList = ArrayListMultimap.create(); - - public CheckManager(AnticheatManager instance) - { - manager = instance; - } - - public void activateCheck(CheckType type) - { - manager.log("The "+type.toString()+" check was activated."); - checkIgnoreList.remove(type); - } - - public void deactivateCheck(CheckType type) - { - manager.log("The "+type.toString()+" check was deactivated."); - checkIgnoreList.add(type); - } - - public boolean isActive(CheckType type) - { - return !checkIgnoreList.contains(type); - } - - public void exemptPlayer(Player player, CheckType type) - { - manager.log(player.getName()+" was exempted from the "+type.toString()+" check."); - exemptList.put(player,type); - } - - public void unexemptPlayer(Player player, CheckType type) - { - manager.log(player.getName()+" was re-added to the "+type.toString()+" check."); - exemptList.remove(type, type); - } - - public boolean isExempt(Player player, CheckType type) - { - return exemptList.containsEntry(player, type); - } - - private boolean hasPermission(Player player, String permission) - { - return player.hasPermission(permission); - } - - public boolean willCheck(Player player, CheckType type) - { - return isActive(type) - && manager.getConfiguration().checkInWorld(player.getWorld()) - && !isExempt(player, type) - && !hasPermission(player, type.getPermission()); - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.manage; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.entity.Player; + +/** + *

+ * The manager that AntiCheat will check with to see if it should watch certain checks and certain players. + */ + +public class CheckManager +{ + public AnticheatManager manager = null; + private static List checkIgnoreList = new ArrayList(); + private static Multimap exemptList = ArrayListMultimap.create(); + + public CheckManager(AnticheatManager instance) + { + manager = instance; + } + + public void activateCheck(CheckType type) + { + manager.log("The "+type.toString()+" check was activated."); + checkIgnoreList.remove(type); + } + + public void deactivateCheck(CheckType type) + { + manager.log("The "+type.toString()+" check was deactivated."); + checkIgnoreList.add(type); + } + + public boolean isActive(CheckType type) + { + return !checkIgnoreList.contains(type); + } + + public void exemptPlayer(Player player, CheckType type) + { + manager.log(player.getName()+" was exempted from the "+type.toString()+" check."); + exemptList.put(player,type); + } + + public void unexemptPlayer(Player player, CheckType type) + { + manager.log(player.getName()+" was re-added to the "+type.toString()+" check."); + exemptList.remove(type, type); + } + + public boolean isExempt(Player player, CheckType type) + { + return exemptList.containsEntry(player, type); + } + + private boolean hasPermission(Player player, String permission) + { + return player.hasPermission(permission); + } + + public boolean willCheck(Player player, CheckType type) + { + return isActive(type) + && manager.getConfiguration().checkInWorld(player.getWorld()) + && !isExempt(player, type) + && !hasPermission(player, type.getPermission()); + } +} diff --git a/src/main/java/net/h31ix/anticheat/manage/CheckType.java b/src/main/java/net/h31ix/anticheat/manage/CheckType.java index 6066993..ecb3bd7 100644 --- a/src/main/java/net/h31ix/anticheat/manage/CheckType.java +++ b/src/main/java/net/h31ix/anticheat/manage/CheckType.java @@ -1,63 +1,63 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.manage; - - -/** - *

- * All the types of checks and their corresponding permission nodes. - */ - - -public enum CheckType -{ - ZOMBE_FLY("anticheat.zombe.fly"), - ZOMBE_NOCLIP("anticheat.zombe.noclip"), - ZOMBE_CHEAT("anticheat.zombe.cheat"), - FLY("anticheat.fly"), - WATER_WALK("anticheat.waterwalk"), - NO_SWING("anticheat.noswing"), - FAST_BREAK("anticheat.fastbreak"), - FAST_PLACE("anticheat.fastplace"), - SPAM("anticheat.spam"), - SPRINT("anticheat.sprint"), - SNEAK("anticheat.sneak"), - SPEED("anticheat.speed"), - SPIDER("anticheat.spider"), - NOFALL("anticheat.nofall"), - FAST_BOW("anticheat.fastbow"), - FAST_EAT("anticheat.fasteat"), - FAST_HEAL("anticheat.fastheal"), - FORCEFIELD("anticheat.forcefield"), - XRAY("anticheat.xray"), - LONG_REACH("anticheat.longreach"), - ITEM_SPAM("anticheat.itemspam"); - - private final String permission; - - private CheckType(String permission) - { - this.permission = permission; - } - - public String getPermission() - { - return this.permission; - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.manage; + + +/** + *

+ * All the types of checks and their corresponding permission nodes. + */ + + +public enum CheckType +{ + ZOMBE_FLY("anticheat.zombe.fly"), + ZOMBE_NOCLIP("anticheat.zombe.noclip"), + ZOMBE_CHEAT("anticheat.zombe.cheat"), + FLY("anticheat.fly"), + WATER_WALK("anticheat.waterwalk"), + NO_SWING("anticheat.noswing"), + FAST_BREAK("anticheat.fastbreak"), + FAST_PLACE("anticheat.fastplace"), + SPAM("anticheat.spam"), + SPRINT("anticheat.sprint"), + SNEAK("anticheat.sneak"), + SPEED("anticheat.speed"), + SPIDER("anticheat.spider"), + NOFALL("anticheat.nofall"), + FAST_BOW("anticheat.fastbow"), + FAST_EAT("anticheat.fasteat"), + FAST_HEAL("anticheat.fastheal"), + FORCEFIELD("anticheat.forcefield"), + XRAY("anticheat.xray"), + LONG_REACH("anticheat.longreach"), + ITEM_SPAM("anticheat.itemspam"); + + private final String permission; + + private CheckType(String permission) + { + this.permission = permission; + } + + public String getPermission() + { + return this.permission; + } +} diff --git a/src/main/java/net/h31ix/anticheat/manage/Distance.java b/src/main/java/net/h31ix/anticheat/manage/Distance.java index d670471..082dac5 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Distance.java +++ b/src/main/java/net/h31ix/anticheat/manage/Distance.java @@ -1,47 +1,47 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.manage; - -import org.bukkit.Location; - -public class Distance -{ - private final Location l1,l2; - - public Distance(Location from, Location to) - { - l1 = to; - l2 = from; - } - - public double getXDifference() - { - return Math.abs(l1.getX()-l2.getX()); - } - - public double getZDifference() - { - return Math.abs(l1.getZ()-l2.getZ()); - } - - public double getYDifference() - { - return Math.abs(l1.getY()-l2.getY()); - } +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.manage; + +import org.bukkit.Location; + +public class Distance +{ + private final Location l1,l2; + + public Distance(Location from, Location to) + { + l1 = to; + l2 = from; + } + + public double getXDifference() + { + return Math.abs(l1.getX()-l2.getX()); + } + + public double getZDifference() + { + return Math.abs(l1.getZ()-l2.getZ()); + } + + public double getYDifference() + { + return Math.abs(l1.getY()-l2.getY()); + } } \ No newline at end of file diff --git a/src/main/java/net/h31ix/anticheat/manage/PlayerManager.java b/src/main/java/net/h31ix/anticheat/manage/PlayerManager.java index 98014c1..7f96aaa 100644 --- a/src/main/java/net/h31ix/anticheat/manage/PlayerManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/PlayerManager.java @@ -1,161 +1,161 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.manage; - -import java.util.HashMap; -import java.util.Map; - -import net.h31ix.anticheat.Configuration; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -/** - *

- * The manager that AntiCheat will use to monitor player's hack levels and to execute events that the admin has set - */ - -public class PlayerManager -{ - - private static Map level = new HashMap(); - private static Configuration config = null; - private static final int MED_THRESHOLD = 20; - private static final int HIGH_THRESHOLD = 50; - - public PlayerManager(AnticheatManager instance) { - config = instance.getConfiguration(); - } - - private static void reactMedium(Player player) - { - execute("Medium",player); - String [] alert = new String[2]; - alert[0] = ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.YELLOW+" has entered the MEDIUM hack level."; - alert[1] = ChatColor.YELLOW+"[ALERT] This means they may be using a hacked client or may have a bad connection!"; - Utilities.alert(alert); - } - private static void reactHigh(Player player) - { - execute("High",player); - String [] alert = new String[2]; - alert[0] = ChatColor.RED+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.RED+" has entered the HIGH hack level."; - alert[1] = ChatColor.RED+"[ALERT] This means they probably are hacking or are lagging out!"; - Utilities.alert(alert); - } - - public void increaseLevel(Player player) - { - final String name = player.getName(); - if(level.get(name) == null || level.get(name) == 0) - { - level.put(name,1); - } - else - { - final int playerLevel = level.get(name); - level.put(name, playerLevel+1); - if(playerLevel <= MED_THRESHOLD && playerLevel+1 > MED_THRESHOLD && playerLevel+1 <= HIGH_THRESHOLD) - { - reactMedium(player); - } - else if(playerLevel <= HIGH_THRESHOLD && playerLevel+1 > HIGH_THRESHOLD) - { - reactHigh(player); - level.put(player.getName(), MED_THRESHOLD+5); - } - else if (playerLevel > 60) - { - level.put(player.getName(), MED_THRESHOLD+5); - } - } - } - - public void decreaseLevel(Player player) - { - final String name = player.getName(); - if(level.get(name) != null && level.get(name) != 0) - { - int playerLevel = level.get(name)-1; - level.put(name, playerLevel); - } - } - - public int getLevel(Player player) - { - final String name = player.getName(); - if(level.get(name) != null) - { - return level.get(name); - } - else - { - return 0; - } - } - - public void setLevel(Player player, int x) - { - if(!(x > 60 && x < 0)) - { - level.put(player.getName(), x); - } - } - - public boolean hasLevel(Player player) - { - return level.containsKey(player.getName()); - } - - public void reset(Player player) - { - level.put(player.getName(),0); - } - - public Map getLevels() - { - return level; - } - - private static void execute(String level, Player player) - { - String result = config.getResult(level); - if(result.startsWith("COMMAND[")) - { - String command = result.replaceAll("COMMAND\\[", "").replaceAll("]", "").replaceAll("&player", player.getName()); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); - } - else if(result.equalsIgnoreCase("KICK")) - { - player.kickPlayer(ChatColor.RED+"Kicked by AntiCheat"); - player.getServer().broadcastMessage(ChatColor.RED+"[AntiCheat] "+player.getName()+" was kicked for hacking."); - } - else if(result.equalsIgnoreCase("WARN")) - { - player.sendMessage(ChatColor.RED+"[AntiCheat] Hacks are not allowed on this server."); - player.sendMessage(ChatColor.RED+"[AntiCheat] If you continue to use hacks, action will be taken."); - } - else if(result.equalsIgnoreCase("BAN")) - { - player.setBanned(true); - player.kickPlayer(ChatColor.RED+"Banned by AntiCheat"); - player.getServer().broadcastMessage(ChatColor.RED+"[AntiCheat] "+player.getName()+" was banned for hacking."); - } - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.manage; + +import java.util.HashMap; +import java.util.Map; + +import net.h31ix.anticheat.Configuration; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +/** + *

+ * The manager that AntiCheat will use to monitor player's hack levels and to execute events that the admin has set + */ + +public class PlayerManager +{ + + private static Map level = new HashMap(); + private static Configuration config = null; + private static final int MED_THRESHOLD = 20; + private static final int HIGH_THRESHOLD = 50; + + public PlayerManager(AnticheatManager instance) { + config = instance.getConfiguration(); + } + + private static void reactMedium(Player player) + { + execute("Medium",player); + String [] alert = new String[2]; + alert[0] = ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.YELLOW+" has entered the MEDIUM hack level."; + alert[1] = ChatColor.YELLOW+"[ALERT] This means they may be using a hacked client or may have a bad connection!"; + Utilities.alert(alert); + } + private static void reactHigh(Player player) + { + execute("High",player); + String [] alert = new String[2]; + alert[0] = ChatColor.RED+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.RED+" has entered the HIGH hack level."; + alert[1] = ChatColor.RED+"[ALERT] This means they probably are hacking or are lagging out!"; + Utilities.alert(alert); + } + + public void increaseLevel(Player player) + { + final String name = player.getName(); + if(level.get(name) == null || level.get(name) == 0) + { + level.put(name,1); + } + else + { + final int playerLevel = level.get(name); + level.put(name, playerLevel+1); + if(playerLevel <= MED_THRESHOLD && playerLevel+1 > MED_THRESHOLD && playerLevel+1 <= HIGH_THRESHOLD) + { + reactMedium(player); + } + else if(playerLevel <= HIGH_THRESHOLD && playerLevel+1 > HIGH_THRESHOLD) + { + reactHigh(player); + level.put(player.getName(), MED_THRESHOLD+5); + } + else if (playerLevel > 60) + { + level.put(player.getName(), MED_THRESHOLD+5); + } + } + } + + public void decreaseLevel(Player player) + { + final String name = player.getName(); + if(level.get(name) != null && level.get(name) != 0) + { + int playerLevel = level.get(name)-1; + level.put(name, playerLevel); + } + } + + public int getLevel(Player player) + { + final String name = player.getName(); + if(level.get(name) != null) + { + return level.get(name); + } + else + { + return 0; + } + } + + public void setLevel(Player player, int x) + { + if(!(x > 60 && x < 0)) + { + level.put(player.getName(), x); + } + } + + public boolean hasLevel(Player player) + { + return level.containsKey(player.getName()); + } + + public void reset(Player player) + { + level.put(player.getName(),0); + } + + public Map getLevels() + { + return level; + } + + private static void execute(String level, Player player) + { + String result = config.getResult(level); + if(result.startsWith("COMMAND[")) + { + String command = result.replaceAll("COMMAND\\[", "").replaceAll("]", "").replaceAll("&player", player.getName()); + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); + } + else if(result.equalsIgnoreCase("KICK")) + { + player.kickPlayer(ChatColor.RED+"Kicked by AntiCheat"); + player.getServer().broadcastMessage(ChatColor.RED+"[AntiCheat] "+player.getName()+" was kicked for hacking."); + } + else if(result.equalsIgnoreCase("WARN")) + { + player.sendMessage(ChatColor.RED+"[AntiCheat] Hacks are not allowed on this server."); + player.sendMessage(ChatColor.RED+"[AntiCheat] If you continue to use hacks, action will be taken."); + } + else if(result.equalsIgnoreCase("BAN")) + { + player.setBanned(true); + player.kickPlayer(ChatColor.RED+"Banned by AntiCheat"); + player.getServer().broadcastMessage(ChatColor.RED+"[AntiCheat] "+player.getName()+" was banned for hacking."); + } + } +} diff --git a/src/main/java/net/h31ix/anticheat/manage/Utilities.java b/src/main/java/net/h31ix/anticheat/manage/Utilities.java index 3e9d8b1..71e8339 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Utilities.java +++ b/src/main/java/net/h31ix/anticheat/manage/Utilities.java @@ -1,138 +1,138 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.manage; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import net.h31ix.anticheat.Anticheat; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; - -public final class Utilities -{ - private static final List INSTANT_BREAK = new ArrayList(); - private static final List FOOD = new ArrayList(); - - private Utilities() - { - - } - public static void alert(String [] message) - { - for(Player p : Bukkit.getServer().getOnlinePlayers()) - { - if(p.hasPermission("anticheat.alert") || p.hasPermission("anticheat.admin") || p.isOp()) - { - for(String msg : message) - { - p.sendMessage(msg); - } - } - } - if(Anticheat.getManager().getConfiguration().logConsole()) - { - Logger logger = Logger.getLogger("Minecraft"); - for(String msg : message) - { - logger.log(Level.INFO,ChatColor.stripColor(msg)); - } - } - } - public static boolean cantStandAt(Block block) - { - return !canStand(block) && cantStandClose(block) && cantStandFar(block); - } - private 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)); - } - private 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; - } - static - { - INSTANT_BREAK.add(Material.RED_MUSHROOM); - INSTANT_BREAK.add(Material.RED_ROSE); - INSTANT_BREAK.add(Material.BROWN_MUSHROOM); - INSTANT_BREAK.add(Material.YELLOW_FLOWER); - INSTANT_BREAK.add(Material.REDSTONE); - INSTANT_BREAK.add(Material.REDSTONE_TORCH_OFF); - INSTANT_BREAK.add(Material.REDSTONE_TORCH_ON); - INSTANT_BREAK.add(Material.REDSTONE_WIRE); - INSTANT_BREAK.add(Material.LONG_GRASS); - INSTANT_BREAK.add(Material.PAINTING); - INSTANT_BREAK.add(Material.WHEAT); - INSTANT_BREAK.add(Material.SUGAR_CANE); - INSTANT_BREAK.add(Material.SUGAR_CANE_BLOCK); - INSTANT_BREAK.add(Material.DIODE); - INSTANT_BREAK.add(Material.DIODE_BLOCK_OFF); - INSTANT_BREAK.add(Material.DIODE_BLOCK_ON); - INSTANT_BREAK.add(Material.SAPLING); - INSTANT_BREAK.add(Material.TORCH); - INSTANT_BREAK.add(Material.CROPS); - INSTANT_BREAK.add(Material.SNOW); - FOOD.add(Material.COOKED_BEEF); - FOOD.add(Material.COOKED_CHICKEN); - FOOD.add(Material.COOKED_FISH); - FOOD.add(Material.GRILLED_PORK); - FOOD.add(Material.PORK); - FOOD.add(Material.MUSHROOM_SOUP); - FOOD.add(Material.RAW_BEEF); - FOOD.add(Material.RAW_CHICKEN); - FOOD.add(Material.RAW_FISH); - FOOD.add(Material.APPLE); - FOOD.add(Material.GOLDEN_APPLE); - FOOD.add(Material.MELON); - FOOD.add(Material.COOKIE); - FOOD.add(Material.BREAD); - FOOD.add(Material.SPIDER_EYE); - FOOD.add(Material.ROTTEN_FLESH); - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.manage; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.h31ix.anticheat.Anticheat; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; + +public final class Utilities +{ + private static final List INSTANT_BREAK = new ArrayList(); + private static final List FOOD = new ArrayList(); + + private Utilities() + { + + } + public static void alert(String [] message) + { + for(Player p : Bukkit.getServer().getOnlinePlayers()) + { + if(p.hasPermission("anticheat.alert") || p.hasPermission("anticheat.admin") || p.isOp()) + { + for(String msg : message) + { + p.sendMessage(msg); + } + } + } + if(Anticheat.getManager().getConfiguration().logConsole()) + { + Logger logger = Logger.getLogger("Minecraft"); + for(String msg : message) + { + logger.log(Level.INFO,ChatColor.stripColor(msg)); + } + } + } + public static boolean cantStandAt(Block block) + { + return !canStand(block) && cantStandClose(block) && cantStandFar(block); + } + private 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)); + } + private 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; + } + static + { + INSTANT_BREAK.add(Material.RED_MUSHROOM); + INSTANT_BREAK.add(Material.RED_ROSE); + INSTANT_BREAK.add(Material.BROWN_MUSHROOM); + INSTANT_BREAK.add(Material.YELLOW_FLOWER); + INSTANT_BREAK.add(Material.REDSTONE); + INSTANT_BREAK.add(Material.REDSTONE_TORCH_OFF); + INSTANT_BREAK.add(Material.REDSTONE_TORCH_ON); + INSTANT_BREAK.add(Material.REDSTONE_WIRE); + INSTANT_BREAK.add(Material.LONG_GRASS); + INSTANT_BREAK.add(Material.PAINTING); + INSTANT_BREAK.add(Material.WHEAT); + INSTANT_BREAK.add(Material.SUGAR_CANE); + INSTANT_BREAK.add(Material.SUGAR_CANE_BLOCK); + INSTANT_BREAK.add(Material.DIODE); + INSTANT_BREAK.add(Material.DIODE_BLOCK_OFF); + INSTANT_BREAK.add(Material.DIODE_BLOCK_ON); + INSTANT_BREAK.add(Material.SAPLING); + INSTANT_BREAK.add(Material.TORCH); + INSTANT_BREAK.add(Material.CROPS); + INSTANT_BREAK.add(Material.SNOW); + FOOD.add(Material.COOKED_BEEF); + FOOD.add(Material.COOKED_CHICKEN); + FOOD.add(Material.COOKED_FISH); + FOOD.add(Material.GRILLED_PORK); + FOOD.add(Material.PORK); + FOOD.add(Material.MUSHROOM_SOUP); + FOOD.add(Material.RAW_BEEF); + FOOD.add(Material.RAW_CHICKEN); + FOOD.add(Material.RAW_FISH); + FOOD.add(Material.APPLE); + FOOD.add(Material.GOLDEN_APPLE); + FOOD.add(Material.MELON); + FOOD.add(Material.COOKIE); + FOOD.add(Material.BREAD); + FOOD.add(Material.SPIDER_EYE); + FOOD.add(Material.ROTTEN_FLESH); + } +} diff --git a/src/main/java/net/h31ix/anticheat/metrics/Metrics.java b/src/main/java/net/h31ix/anticheat/metrics/Metrics.java index a7834f6..108d87e 100644 --- a/src/main/java/net/h31ix/anticheat/metrics/Metrics.java +++ b/src/main/java/net/h31ix/anticheat/metrics/Metrics.java @@ -1,495 +1,495 @@ -package net.h31ix.anticheat.metrics; - -/* - * Copyright 2011 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: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and contributors and should not be interpreted as representing official policies, - * either expressed or implied, of anybody else. - */ - -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; - -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.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.UUID; - -/** - *

- * 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 start();
- *
- */ -public class Metrics { - - /** - * The current revision number - */ - private static final int REVISION = 5; - - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://metrics.griefcraft.com"; - - /** - * 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. - */ - 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; - - /** - * Unique server id - */ - private final String guid; - - public Metrics(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); - - // add some defaults - configuration.addDefault("opt-out", false); - configuration.addDefault("guid", UUID.randomUUID().toString()); - - // 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); - } - - // Load the guid then - guid = configuration.getString("guid"); - } - - /** - * 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 - */ - public Graph createGraph(String name) { - if (name == null) { - throw new IllegalArgumentException("Graph name cannot be null"); - } - - // Construct the graph object - Graph graph = new Graph(name); - - // Now we can add our graph - graphs.add(graph); - - // and return back - return graph; - } - - /** - * Adds a custom data plotter to the default graph - * - * @param plotter - */ - public void addCustomData(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. - */ - 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()); - } - } - }, 0, PING_INTERVAL * 1200); - } - - /** - * 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 - PluginDescriptionFile description = plugin.getDescription(); - - // Construct the post data - String data = encode("guid") + '=' + encode(guid) - + encodeDataPair("version", description.getVersion()) - + 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) { - 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) { - 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. - 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()); - - // The value to send, which for the foreseeable future is just the string - // value of plotter.getValue() - String value = Integer.toString(plotter.getValue()); - - // Add it to the http post data :) - data += encodeDataPair(key, value); - } - } - } - - // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, description.getName())); - - // 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()) { - connection = url.openConnection(Proxy.NO_PROXY); - } else { - connection = url.openConnection(); - } - - connection.setDoOutput(true); - - // Write the data - OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); - writer.write(data); - writer.flush(); - - // Now read the response - BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String response = reader.readLine(); - - // close resources - writer.close(); - reader.close(); - - if (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(); - - while (iter.hasNext()) { - Graph graph = iter.next(); - - for (Plotter plotter : graph.getPlotters()) { - plotter.reset(); - } - } - } - } - } - //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 - */ - private boolean isMineshafterPresent() { - try { - Class.forName("mineshafter.MineServer"); - return true; - } catch (Exception e) { - 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:

- * - * String httpData = encode("guid") + '=' + encode("1234") + encodeDataPair("authors") + ".."; - * - * - * @param key - * @param value - * @return - */ - private static String encodeDataPair(String key, String value) throws UnsupportedEncodingException { - return '&' + encode(key) + '=' + encode(value); - } - - /** - * Encode text as UTF-8 - * - * @param text - * @return - */ - 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 { - - /** - * 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) { - this.name = name; - } - - /** - * Gets the graph's name - * - * @return - */ - public String getName() { - return name; - } - - /** - * Add a plotter to the graph, which will be used to plot entries - * - * @param plotter - */ - public void addPlotter(Plotter plotter) { - plotters.add(plotter); - } - - /** - * Remove a plotter from the graph - * - * @param plotter - */ - public void removePlotter(Plotter plotter) { - plotters.remove(plotter); - } - - /** - * Gets an unmodifiable set of the plotter objects in the graph - * - * @return - */ - 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; - return graph.name.equals(name); - } - - } - - /** - * 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 - */ - public Plotter(String name) { - this.name = name; - } - - /** - * Get the current value for the plotted point - * - * @return - */ - 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(); - } - - @Override - public boolean equals(Object object) { - if (!(object instanceof Plotter)) { - return false; - } - - Plotter plotter = (Plotter) object; - return plotter.name.equals(name) && plotter.getValue() == getValue(); - } - - } - +package net.h31ix.anticheat.metrics; + +/* + * Copyright 2011 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: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and contributors and should not be interpreted as representing official policies, + * either expressed or implied, of anybody else. + */ + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; + +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.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.UUID; + +/** + *

+ * 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 start();
+ *
+ */ +public class Metrics { + + /** + * The current revision number + */ + private static final int REVISION = 5; + + /** + * The base url of the metrics domain + */ + private static final String BASE_URL = "http://metrics.griefcraft.com"; + + /** + * 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. + */ + 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; + + /** + * Unique server id + */ + private final String guid; + + public Metrics(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); + + // add some defaults + configuration.addDefault("opt-out", false); + configuration.addDefault("guid", UUID.randomUUID().toString()); + + // 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); + } + + // Load the guid then + guid = configuration.getString("guid"); + } + + /** + * 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 + */ + public Graph createGraph(String name) { + if (name == null) { + throw new IllegalArgumentException("Graph name cannot be null"); + } + + // Construct the graph object + Graph graph = new Graph(name); + + // Now we can add our graph + graphs.add(graph); + + // and return back + return graph; + } + + /** + * Adds a custom data plotter to the default graph + * + * @param plotter + */ + public void addCustomData(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. + */ + 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()); + } + } + }, 0, PING_INTERVAL * 1200); + } + + /** + * 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 + PluginDescriptionFile description = plugin.getDescription(); + + // Construct the post data + String data = encode("guid") + '=' + encode(guid) + + encodeDataPair("version", description.getVersion()) + + 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) { + 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) { + 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. + 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()); + + // The value to send, which for the foreseeable future is just the string + // value of plotter.getValue() + String value = Integer.toString(plotter.getValue()); + + // Add it to the http post data :) + data += encodeDataPair(key, value); + } + } + } + + // Create the url + URL url = new URL(BASE_URL + String.format(REPORT_URL, description.getName())); + + // 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()) { + connection = url.openConnection(Proxy.NO_PROXY); + } else { + connection = url.openConnection(); + } + + connection.setDoOutput(true); + + // Write the data + OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); + writer.write(data); + writer.flush(); + + // Now read the response + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String response = reader.readLine(); + + // close resources + writer.close(); + reader.close(); + + if (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(); + + while (iter.hasNext()) { + Graph graph = iter.next(); + + for (Plotter plotter : graph.getPlotters()) { + plotter.reset(); + } + } + } + } + } + //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 + */ + private boolean isMineshafterPresent() { + try { + Class.forName("mineshafter.MineServer"); + return true; + } catch (Exception e) { + 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:

+ * + * String httpData = encode("guid") + '=' + encode("1234") + encodeDataPair("authors") + ".."; + * + * + * @param key + * @param value + * @return + */ + private static String encodeDataPair(String key, String value) throws UnsupportedEncodingException { + return '&' + encode(key) + '=' + encode(value); + } + + /** + * Encode text as UTF-8 + * + * @param text + * @return + */ + 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 { + + /** + * 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) { + this.name = name; + } + + /** + * Gets the graph's name + * + * @return + */ + public String getName() { + return name; + } + + /** + * Add a plotter to the graph, which will be used to plot entries + * + * @param plotter + */ + public void addPlotter(Plotter plotter) { + plotters.add(plotter); + } + + /** + * Remove a plotter from the graph + * + * @param plotter + */ + public void removePlotter(Plotter plotter) { + plotters.remove(plotter); + } + + /** + * Gets an unmodifiable set of the plotter objects in the graph + * + * @return + */ + 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; + return graph.name.equals(name); + } + + } + + /** + * 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 + */ + public Plotter(String name) { + this.name = name; + } + + /** + * Get the current value for the plotted point + * + * @return + */ + 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(); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof Plotter)) { + return false; + } + + 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/xray/XRayListener.java b/src/main/java/net/h31ix/anticheat/xray/XRayListener.java index a7e4e42..02eac7c 100644 --- a/src/main/java/net/h31ix/anticheat/xray/XRayListener.java +++ b/src/main/java/net/h31ix/anticheat/xray/XRayListener.java @@ -1,82 +1,82 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.xray; - -import net.h31ix.anticheat.Anticheat; -import net.h31ix.anticheat.Configuration; -import net.h31ix.anticheat.manage.CheckManager; -import net.h31ix.anticheat.manage.CheckType; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; - -public class XRayListener implements Listener { - private XRayTracker tracker = Anticheat.getManager().getXRayTracker(); - private Configuration config = Anticheat.getManager().getConfiguration(); - private CheckManager checkManager = Anticheat.getManager().getCheckManager(); - - @EventHandler - public void onBlockBreak(BlockBreakEvent event) - { - if(config.logXRay()) - { - Player p = event.getPlayer(); - String player = p.getName(); - if(checkManager.willCheck(p, CheckType.XRAY)) - { - Material m = event.getBlock().getType(); - if(m == Material.DIAMOND_ORE) - { - tracker.addDiamond(player); - } - else if(m == Material.IRON_ORE) - { - tracker.addIron(player); - } - else if(m == Material.COAL_ORE) - { - tracker.addCoal(player); - } - else if(m == Material.GOLD_ORE) - { - tracker.addGold(player); - } - else if(m == Material.LAPIS_ORE) - { - tracker.addLapis(player); - } - else if(m == Material.REDSTONE_ORE) - { - tracker.addRedstone(player); - } - else if(m == Material.GOLD_ORE) - { - tracker.addGold(player); - } - else - { - tracker.addBlock(player); - } - tracker.addTotal(player); - } - } - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.xray; + +import net.h31ix.anticheat.Anticheat; +import net.h31ix.anticheat.Configuration; +import net.h31ix.anticheat.manage.CheckManager; +import net.h31ix.anticheat.manage.CheckType; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +public class XRayListener implements Listener { + private XRayTracker tracker = Anticheat.getManager().getXRayTracker(); + private Configuration config = Anticheat.getManager().getConfiguration(); + private CheckManager checkManager = Anticheat.getManager().getCheckManager(); + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + if(config.logXRay()) + { + Player p = event.getPlayer(); + String player = p.getName(); + if(checkManager.willCheck(p, CheckType.XRAY)) + { + Material m = event.getBlock().getType(); + if(m == Material.DIAMOND_ORE) + { + tracker.addDiamond(player); + } + else if(m == Material.IRON_ORE) + { + tracker.addIron(player); + } + else if(m == Material.COAL_ORE) + { + tracker.addCoal(player); + } + else if(m == Material.GOLD_ORE) + { + tracker.addGold(player); + } + else if(m == Material.LAPIS_ORE) + { + tracker.addLapis(player); + } + else if(m == Material.REDSTONE_ORE) + { + tracker.addRedstone(player); + } + else if(m == Material.GOLD_ORE) + { + tracker.addGold(player); + } + else + { + tracker.addBlock(player); + } + tracker.addTotal(player); + } + } + } +} diff --git a/src/main/java/net/h31ix/anticheat/xray/XRayStats.java b/src/main/java/net/h31ix/anticheat/xray/XRayStats.java index fd70633..abb6d25 100644 --- a/src/main/java/net/h31ix/anticheat/xray/XRayStats.java +++ b/src/main/java/net/h31ix/anticheat/xray/XRayStats.java @@ -1,109 +1,109 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.xray; - -import java.util.Map; - -public class XRayStats { - private static final int DIVISOR = 100; - private double t = 1; - private double d = 0; - private double g = 0; - private double i = 0; - private double c = 0; - private double l = 0; - private double r = 0; - private double o = 0; - - public XRayStats(String player,Map diamond,Map gold,Map iron,Map coal,Map lapis,Map redstone,Map other,Map total) - { - if(total.get(player) != null) - { - t = total.get(player); - } - if(diamond.get(player) != null) - { - d = (diamond.get(player)/t)*DIVISOR; - } - if(gold.get(player) != null) - { - g = (gold.get(player)/t)*DIVISOR; - } - if(iron.get(player) != null) - { - i = (iron.get(player)/t)*DIVISOR; - } - if(coal.get(player) != null) - { - c = (coal.get(player)/t)*DIVISOR; - } - if(lapis.get(player) != null) - { - l = (lapis.get(player)/t)*DIVISOR; - } - if(redstone.get(player) != null) - { - r = (redstone.get(player)/t)*DIVISOR; - } - if(other.get(player) != null) - { - o = (other.get(player)/t)*DIVISOR; - } - } - - public double getTotal() - { - return t; - } - - public double getDiamond() - { - return d; - } - - public double getGold() - { - return g; - } - - public double getIron() - { - return i; - } - - public double getCoal() - { - return c; - } - - public double getLapis() - { - return l; - } - - public double getRedstone() - { - return r; - } - - public double getOther() - { - return o; - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.xray; + +import java.util.Map; + +public class XRayStats { + private static final int DIVISOR = 100; + private double t = 1; + private double d = 0; + private double g = 0; + private double i = 0; + private double c = 0; + private double l = 0; + private double r = 0; + private double o = 0; + + public XRayStats(String player,Map diamond,Map gold,Map iron,Map coal,Map lapis,Map redstone,Map other,Map total) + { + if(total.get(player) != null) + { + t = total.get(player); + } + if(diamond.get(player) != null) + { + d = (diamond.get(player)/t)*DIVISOR; + } + if(gold.get(player) != null) + { + g = (gold.get(player)/t)*DIVISOR; + } + if(iron.get(player) != null) + { + i = (iron.get(player)/t)*DIVISOR; + } + if(coal.get(player) != null) + { + c = (coal.get(player)/t)*DIVISOR; + } + if(lapis.get(player) != null) + { + l = (lapis.get(player)/t)*DIVISOR; + } + if(redstone.get(player) != null) + { + r = (redstone.get(player)/t)*DIVISOR; + } + if(other.get(player) != null) + { + o = (other.get(player)/t)*DIVISOR; + } + } + + public double getTotal() + { + return t; + } + + public double getDiamond() + { + return d; + } + + public double getGold() + { + return g; + } + + public double getIron() + { + return i; + } + + public double getCoal() + { + return c; + } + + public double getLapis() + { + return l; + } + + public double getRedstone() + { + return r; + } + + public double getOther() + { + return o; + } +} diff --git a/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java b/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java index 95bbc93..aa03a4e 100644 --- a/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java +++ b/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java @@ -1,182 +1,182 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012 H31IX http://h31ix.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.xray; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -public class XRayTracker { - private Map diamond = new HashMap(); - private Map gold = new HashMap(); - private Map iron = new HashMap(); - private Map coal = new HashMap(); - private Map lapis = new HashMap(); - private Map redstone = new HashMap(); - private Map block = new HashMap(); - private Map totalblock = new HashMap(); - private List alerted = new ArrayList(); - private static final ChatColor GREEN = ChatColor.GREEN; - private static final ChatColor WHITE = ChatColor.WHITE; - private static final ChatColor RED = ChatColor.RED; - private static final ChatColor GRAY = ChatColor.GRAY; - private static final int RATIO_DIVISOR = 3; - private static final int POWER = 10; - private static final int MIN_BLOCK_COUNT = 100; - - public XRayTracker() - { - } - - public boolean sufficientData(String player) - { - return totalblock.get(player) != null && totalblock.get(player) >= MIN_BLOCK_COUNT; - } - - public void calculate(CommandSender cs, String player, double x, double b, String type) - { - ChatColor color = WHITE; - if(x >= b/RATIO_DIVISOR) - { - color = RED; - } - cs.sendMessage(GRAY+"Percent "+type+" ore: "+color+round(x)+"%"); - } - - public boolean calculate(String player, double x, double b) - { - return x >= b/RATIO_DIVISOR; - } - - public boolean hasAbnormal(String player) - { - XRayStats stats = new XRayStats(player,diamond,gold,iron,coal,lapis,redstone,block,totalblock); - double total = stats.getOther(); - return calculate(player,stats.getDiamond(),total) || calculate(player,stats.getGold(),total) || calculate(player,stats.getIron(),total) || calculate(player,stats.getCoal(),total) || calculate(player,stats.getLapis(),total) || calculate(player,stats.getRedstone(),total); - } - - public boolean hasAlerted(String player) - { - return alerted.contains(player); - } - - public void logAlert(String player) - { - alerted.add(player); - } - - public void sendStats(CommandSender cs, String player) - { - getStats(cs,player); - } - - public void getStats(CommandSender cs, String player) - { - XRayStats stats = new XRayStats(player,diamond,gold,iron,coal,lapis,redstone,block,totalblock); - double total = stats.getOther(); - cs.sendMessage("--------------------["+GREEN+"X-Ray Stats"+WHITE+"]---------------------"); - cs.sendMessage(GRAY+"Player: "+WHITE+player); - cs.sendMessage(GRAY+"Total blocks broken: "+WHITE+stats.getTotal()); - calculate(cs,player,stats.getDiamond(),total,"diamond"); - calculate(cs,player,stats.getGold(),total,"gold"); - calculate(cs,player,stats.getIron(),total,"iron"); - calculate(cs,player,stats.getCoal(),total,"coal"); - calculate(cs,player,stats.getLapis(),total,"lapis"); - calculate(cs,player,stats.getRedstone(),total,"redstone"); - cs.sendMessage(GRAY+"Percent all other blocks: "+WHITE+round(stats.getOther())+"%"); - cs.sendMessage("-----------------------------------------------------"); - } - - public void addDiamond(String player) - { - addOre(player,diamond); - } - - public void addGold(String player) - { - addOre(player,gold); - } - - public void addCoal(String player) - { - addOre(player,coal); - } - - public void addIron(String player) - { - addOre(player,iron); - } - - public void addLapis(String player) - { - addOre(player,lapis); - } - - public void addRedstone(String player) - { - addOre(player,redstone); - } - - public void addBlock(String player) - { - addOre(player,block); - } - - public void addTotal(String player) - { - addOre(player,totalblock); - } - - private void addOre(String player, Map map) - { - if(map.get(player) == null || map.get(player) == 0) - { - map.put(player,1); - } - else - { - int playerLevel = map.get(player); - map.put(player, playerLevel+1); - } - } - - private float round(double num) - { - double number = num; - float p = (float)Math.pow(POWER,1); - number*=p; - float tmp = Math.round(number); - return (float)tmp/p; - } - - public void reset(String player) - { - totalblock.put(player,1); - diamond.put(player,0); - iron.put(player,0); - gold.put(player,0); - coal.put(player,0); - redstone.put(player,0); - lapis.put(player,0); - totalblock.put(player,0); - } -} +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012 H31IX http://h31ix.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.xray; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +public class XRayTracker { + private Map diamond = new HashMap(); + private Map gold = new HashMap(); + private Map iron = new HashMap(); + private Map coal = new HashMap(); + private Map lapis = new HashMap(); + private Map redstone = new HashMap(); + private Map block = new HashMap(); + private Map totalblock = new HashMap(); + private List alerted = new ArrayList(); + private static final ChatColor GREEN = ChatColor.GREEN; + private static final ChatColor WHITE = ChatColor.WHITE; + private static final ChatColor RED = ChatColor.RED; + private static final ChatColor GRAY = ChatColor.GRAY; + private static final int RATIO_DIVISOR = 3; + private static final int POWER = 10; + private static final int MIN_BLOCK_COUNT = 100; + + public XRayTracker() + { + } + + public boolean sufficientData(String player) + { + return totalblock.get(player) != null && totalblock.get(player) >= MIN_BLOCK_COUNT; + } + + public void calculate(CommandSender cs, String player, double x, double b, String type) + { + ChatColor color = WHITE; + if(x >= b/RATIO_DIVISOR) + { + color = RED; + } + cs.sendMessage(GRAY+"Percent "+type+" ore: "+color+round(x)+"%"); + } + + public boolean calculate(String player, double x, double b) + { + return x >= b/RATIO_DIVISOR; + } + + public boolean hasAbnormal(String player) + { + XRayStats stats = new XRayStats(player,diamond,gold,iron,coal,lapis,redstone,block,totalblock); + double total = stats.getOther(); + return calculate(player,stats.getDiamond(),total) || calculate(player,stats.getGold(),total) || calculate(player,stats.getIron(),total) || calculate(player,stats.getCoal(),total) || calculate(player,stats.getLapis(),total) || calculate(player,stats.getRedstone(),total); + } + + public boolean hasAlerted(String player) + { + return alerted.contains(player); + } + + public void logAlert(String player) + { + alerted.add(player); + } + + public void sendStats(CommandSender cs, String player) + { + getStats(cs,player); + } + + public void getStats(CommandSender cs, String player) + { + XRayStats stats = new XRayStats(player,diamond,gold,iron,coal,lapis,redstone,block,totalblock); + double total = stats.getOther(); + cs.sendMessage("--------------------["+GREEN+"X-Ray Stats"+WHITE+"]---------------------"); + cs.sendMessage(GRAY+"Player: "+WHITE+player); + cs.sendMessage(GRAY+"Total blocks broken: "+WHITE+stats.getTotal()); + calculate(cs,player,stats.getDiamond(),total,"diamond"); + calculate(cs,player,stats.getGold(),total,"gold"); + calculate(cs,player,stats.getIron(),total,"iron"); + calculate(cs,player,stats.getCoal(),total,"coal"); + calculate(cs,player,stats.getLapis(),total,"lapis"); + calculate(cs,player,stats.getRedstone(),total,"redstone"); + cs.sendMessage(GRAY+"Percent all other blocks: "+WHITE+round(stats.getOther())+"%"); + cs.sendMessage("-----------------------------------------------------"); + } + + public void addDiamond(String player) + { + addOre(player,diamond); + } + + public void addGold(String player) + { + addOre(player,gold); + } + + public void addCoal(String player) + { + addOre(player,coal); + } + + public void addIron(String player) + { + addOre(player,iron); + } + + public void addLapis(String player) + { + addOre(player,lapis); + } + + public void addRedstone(String player) + { + addOre(player,redstone); + } + + public void addBlock(String player) + { + addOre(player,block); + } + + public void addTotal(String player) + { + addOre(player,totalblock); + } + + private void addOre(String player, Map map) + { + if(map.get(player) == null || map.get(player) == 0) + { + map.put(player,1); + } + else + { + int playerLevel = map.get(player); + map.put(player, playerLevel+1); + } + } + + private float round(double num) + { + double number = num; + float p = (float)Math.pow(POWER,1); + number*=p; + float tmp = Math.round(number); + return (float)tmp/p; + } + + public void reset(String player) + { + totalblock.put(player,1); + diamond.put(player,0); + iron.put(player,0); + gold.put(player,0); + coal.put(player,0); + redstone.put(player,0); + lapis.put(player,0); + totalblock.put(player,0); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2390cb6..fb51f35 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,19 +1,19 @@ -#AntiCheat configuration file -#Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/ -XRay: - Log xray stats: true - Alert when xray is found: false - -Events: - #Valid events = NONE,WARN,KICK,BAN,COMMAND[command] - #Use commands like so: COMMAND[ban &player 30] or COMMAND[kick &player hacking] or COMMAND[jail &player 10] - #&player will be replaced with player's name, and any command on your server can be used. - Level Medium: WARN - Level High: KICK - -System: - #Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so. - #AntiCheat will never bother you about updates if this is on, but if you turn it off you will have to manually update. - Auto update: true - Log to console: false +#AntiCheat configuration file +#Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/ +XRay: + Log xray stats: true + Alert when xray is found: false + +Events: + #Valid events = NONE,WARN,KICK,BAN,COMMAND[command] + #Use commands like so: COMMAND[ban &player 30] or COMMAND[kick &player hacking] or COMMAND[jail &player 10] + #&player will be replaced with player's name, and any command on your server can be used. + Level Medium: WARN + Level High: KICK + +System: + #Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so. + #AntiCheat will never bother you about updates if this is on, but if you turn it off you will have to manually update. + Auto update: true + Log to console: false Verbose startup: false \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8c01701..b3c9b35 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,13 +1,13 @@ -author: H31IX -database: false -description: Prevention of hacks and other malicious tinkering on a Minecraft server. -main: net.h31ix.anticheat.Anticheat -name: AntiCheat -softdepend: [AntiCheat] -startup: postworld -url: http://H31IX.NET/ -version: '1.1-PRE' -commands: - anticheat: - description: Control and view info about AntiCheat +author: H31IX +database: false +description: Prevention of hacks and other malicious tinkering on a Minecraft server. +main: net.h31ix.anticheat.Anticheat +name: AntiCheat +softdepend: [AntiCheat] +startup: postworld +url: http://H31IX.NET/ +version: '1.1-PRE' +commands: + anticheat: + description: Control and view info about AntiCheat usage: /anticheat help \ No newline at end of file