Major refactoring to fix runtime errors, better fastbreak and fly check, and a better API. Thanks a ton @SuperSpyTX

This commit is contained in:
Adam committed 2012-05-20 11:55:55 -04:00
1 parent d8dc8ed1e0
commit af91c8a541
17 files changed
+451 -177

No files matched your search

+3
View File
@@ -1 +1,4 @@
/target/ /target/
/bin/
/.settings/
/.*
View File
Whitespace-only changes.
+20 -2
View File
@@ -12,6 +12,7 @@
</repository> </repository>
</repositories> </repositories>
<build> <build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@@ -24,7 +25,18 @@
</plugin> </plugin>
</plugins> </plugins>
<finalName>AntiCheat</finalName> <finalName>AntiCheat</finalName>
</build> <resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
</resources>
</build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
@@ -41,11 +53,17 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>12.0</version> <version>12.0</version>
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
+111 -113
View File
@@ -47,7 +47,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Anticheat extends JavaPlugin public class Anticheat extends JavaPlugin
{ {
private static Anticheat plugin; private static AnticheatManager manager;
private final List<Listener> eventList = new ArrayList<Listener>(); private final List<Listener> eventList = new ArrayList<Listener>();
private static boolean update = false; private static boolean update = false;
private static final int BYTE_SIZE = 1024; private static final int BYTE_SIZE = 1024;
@@ -60,9 +60,9 @@ public class Anticheat extends JavaPlugin
@Override @Override
public void onDisable() public void onDisable()
{ {
Map<String,Integer> map = AnticheatManager.PLAYER_MANAGER.getLevels(); Map<String, Integer> map = manager.getPlayerManager().getLevels();
Iterator<String> set = map.keySet().iterator(); Iterator<String> set = map.keySet().iterator();
while(set.hasNext()) while (set.hasNext())
{ {
String player = set.next(); String player = set.next();
config.saveLevel(player, map.get(player)); config.saveLevel(player, map.get(player));
@@ -74,8 +74,8 @@ public class Anticheat extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
plugin = this; manager = new AnticheatManager(this);
config = AnticheatManager.CONFIGURATION; config = manager.getConfiguration();
checkConfig(); checkConfig();
verbose = config.verboseStartup(); verbose = config.verboseStartup();
updateFolder = config.updateFolder(); updateFolder = config.updateFolder();
@@ -84,55 +84,62 @@ public class Anticheat extends JavaPlugin
eventList.add(new BlockListener()); eventList.add(new BlockListener());
eventList.add(new EntityListener()); eventList.add(new EntityListener());
eventList.add(new VehicleListener()); eventList.add(new VehicleListener());
final XRayTracker xtracker = AnticheatManager.XRAY_TRACKER; final XRayTracker xtracker = manager.getXRayTracker();
if(config.logXRay()) if (config.logXRay())
{ {
eventList.add(new XRayListener()); eventList.add(new XRayListener());
if(config.alertXRay()) if (config.alertXRay())
{ {
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
{
@Override
public void run()
{ {
for(Player player : getServer().getOnlinePlayers()) @Override
{ public void run()
String name = player.getName();
if(!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name))
{ {
String [] alert = new String[2]; for (Player player : getServer().getOnlinePlayers())
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+"."; String name = player.getName();
Utilities.alert(alert); if (!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name))
xtracker.logAlert(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);
}
}, 1200L, 1200L);
} }
} }
for(Listener listener : eventList) for (Listener listener : eventList)
{ {
getServer().getPluginManager().registerEvents(listener, this); getServer().getPluginManager().registerEvents(listener, this);
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] Registered events for ".concat(listener.toString())); logger.log(Level.INFO, "[AC] Registered events for ".concat(listener.toString()));
} }
} }
getCommand("anticheat").setExecutor(new CommandHandler()); getCommand("anticheat").setExecutor(new CommandHandler());
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] Registered commands"); logger.log(Level.INFO, "[AC] Registered commands");
logger.log(Level.INFO,"[AC] Finished loading."); logger.log(Level.INFO, "[AC] Finished loading.");
} }
if(update && config.autoUpdate()) if (update && config.autoUpdate())
{ {
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] Downloading the new update..."); logger.log(Level.INFO, "[AC] Downloading the new update...");
} }
File file = new File("plugins/"+updateFolder); File file = new File("plugins/" + updateFolder);
if(!file.exists()) if (!file.exists())
{ {
try try
{ {
@@ -144,7 +151,7 @@ public class Anticheat extends JavaPlugin
} }
try try
{ {
saveFile(file.getCanonicalPath()+"/AntiCheat.jar", "http://dl.dropbox.com/u/38228324/AntiCheat.jar"); saveFile(file.getCanonicalPath() + "/AntiCheat.jar","http://dl.dropbox.com/u/38228324/AntiCheat.jar");
} }
catch (IOException ex) catch (IOException ex)
{ {
@@ -152,17 +159,13 @@ public class Anticheat extends JavaPlugin
} }
try try
{ {
if(verbose)
{
logger.log(Level.INFO,"[AC] Enabling metrics...");
}
metrics = new Metrics(this); metrics = new Metrics(this);
final EventListener listener = new EventListener(); final EventListener listener = new EventListener();
Graph graph = metrics.createGraph("Hacks blocked"); Graph graph = metrics.createGraph("Hacks blocked");
for(final CheckType type : CheckType.values()) for (final CheckType type : CheckType.values())
{ {
char [] chars = type.toString().replaceAll("_", " ").toLowerCase().toCharArray(); char[] chars = type.toString().replaceAll("_", " ").toLowerCase().toCharArray();
chars[0]= Character.toUpperCase(chars[0]); chars[0] = Character.toUpperCase(chars[0]);
graph.addPlotter(new Metrics.Plotter(new String(chars)) graph.addPlotter(new Metrics.Plotter(new String(chars))
{ {
@Override @Override
@@ -174,108 +177,99 @@ public class Anticheat extends JavaPlugin
listener.resetCheck(type); listener.resetCheck(type);
} }
metrics.start(); metrics.start();
if(verbose)
{
logger.log(Level.INFO,"[AC] Metrics started.");
}
} }
catch (IOException ex) catch (IOException ex)
{ {
} }
for(Player player : getServer().getOnlinePlayers()) for (Player player : getServer().getOnlinePlayers())
{ {
String name = player.getName(); String name = player.getName();
AnticheatManager.PLAYER_MANAGER.setLevel(player, config.getLevel(name)); manager.getPlayerManager().setLevel(player,config.getLevel(name));
}
if(verbose)
{
logger.log(Level.INFO,"[AC] Player's levels collected from storage and applied.");
} }
} }
private void saveFile(String file, String url) 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
{ {
BufferedInputStream in = null;
FileOutputStream fout = null;
try try
{ {
if (in != null) in = new BufferedInputStream(new URL(url).openStream());
{ fout = new FileOutputStream(file);
in.close();
} byte[] data = new byte[BYTE_SIZE];
if (fout != null) int count;
{ while ((count = in.read(data, 0, BYTE_SIZE)) != -1)
fout.close(); {
} fout.write(data, 0, count);
}
} }
catch(Exception ex) catch (Exception ex)
{ {
} }
if(verbose) finally
{ {
logger.log(Level.INFO,"[AC] AntiCheat update has been downloaded and will be installed on next launch."); 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 static void checkConfig() public void checkConfig()
{ {
if(!new File(plugin.getDataFolder()+"/config.yml").exists()) if (!new File(getDataFolder() + "/config.yml").exists())
{ {
plugin.saveDefaultConfig(); saveDefaultConfig();
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] Config file created"); logger.log(Level.INFO, "[AC] Config file created");
} }
} }
} }
private void checkForUpdate() private void checkForUpdate()
{ {
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] Checking for updates..."); logger.log(Level.INFO, "[AC] Checking for updates...");
} }
URL url = null; URL url = null;
URLConnection urlConn = null; URLConnection urlConn = null;
InputStreamReader inStream = null; InputStreamReader inStream = null;
BufferedReader buff = null; BufferedReader buff = null;
String v = ""; String v = "";
try try
{ {
url = new URL("http://dl.dropbox.com/u/38228324/anticheatVersion.txt"); url = new URL("http://dl.dropbox.com/u/38228324/anticheatVersion.txt");
urlConn = url.openConnection(); urlConn = url.openConnection();
inStream = new InputStreamReader(urlConn.getInputStream()); inStream = new InputStreamReader(urlConn.getInputStream());
} }
catch(Exception ex) catch (Exception ex)
{ {
} }
buff= new BufferedReader(inStream); buff = new BufferedReader(inStream);
try try
{ {
v =buff.readLine(); v = buff.readLine();
urlConn = null; urlConn = null;
inStream = null; inStream = null;
buff.close(); buff.close();
buff = null; buff = null;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -283,12 +277,12 @@ public class Anticheat extends JavaPlugin
if (!this.getDescription().getVersion().equalsIgnoreCase(v)) if (!this.getDescription().getVersion().equalsIgnoreCase(v))
{ {
String version = this.getDescription().getVersion(); String version = this.getDescription().getVersion();
if(version.endsWith("-PRE") || version.endsWith("-DEV")) if (version.endsWith("-PRE") || version.endsWith("-DEV"))
{ {
if(version.replaceAll("-PRE", "").replaceAll("-DEV", "").equalsIgnoreCase(v)) if (version.replaceAll("-PRE", "").replaceAll("-DEV", "").equalsIgnoreCase(v))
{ {
update = true; update = true;
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] Your dev build has been promoted to release. Downloading the update."); logger.log(Level.INFO,"[AC] Your dev build has been promoted to release. Downloading the update.");
} }
@@ -296,7 +290,7 @@ public class Anticheat extends JavaPlugin
else else
{ {
update = false; update = false;
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] Dev build detected, so skipping update checking until this version is released."); logger.log(Level.INFO,"[AC] Dev build detected, so skipping update checking until this version is released.");
} }
@@ -305,17 +299,17 @@ public class Anticheat extends JavaPlugin
else else
{ {
update = true; update = true;
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] An update was found."); logger.log(Level.INFO, "[AC] An update was found.");
} }
} }
} }
else else
{ {
if(verbose) if (verbose)
{ {
logger.log(Level.INFO,"[AC] No update found."); logger.log(Level.INFO, "[AC] No update found.");
} }
update = false; update = false;
} }
@@ -323,7 +317,12 @@ public class Anticheat extends JavaPlugin
public static Anticheat getPlugin() public static Anticheat getPlugin()
{ {
return plugin; return manager.getPlugin();
}
public static AnticheatManager getManager()
{
return manager;
} }
public static boolean isUpdated() public static boolean isUpdated()
@@ -333,7 +332,6 @@ public class Anticheat extends JavaPlugin
public static String getVersion() public static String getVersion()
{ {
return plugin.getDescription().getVersion(); return manager.getPlugin().getDescription().getVersion();
} }
} }
@@ -31,11 +31,11 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class CommandHandler implements CommandExecutor { public class CommandHandler implements CommandExecutor
{
private Configuration config = AnticheatManager.CONFIGURATION; private Configuration config = Anticheat.getManager().getConfiguration();
private PlayerManager playerManager = AnticheatManager.PLAYER_MANAGER; private PlayerManager playerManager = Anticheat.getManager().getPlayerManager();
private XRayTracker xtracker = AnticheatManager.XRAY_TRACKER; private XRayTracker xtracker = Anticheat.getManager().getXRayTracker();
private static final ChatColor RED = ChatColor.RED; private static final ChatColor RED = ChatColor.RED;
private static final ChatColor YELLOW = ChatColor.YELLOW; private static final ChatColor YELLOW = ChatColor.YELLOW;
private static final ChatColor GREEN = ChatColor.GREEN; private static final ChatColor GREEN = ChatColor.GREEN;
@@ -24,15 +24,20 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.h31ix.anticheat.manage.AnticheatManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
public class Configuration { public class Configuration
private File configFile = new File(Anticheat.getPlugin().getDataFolder()+"/config.yml"); {
private File levelFile = new File(Anticheat.getPlugin().getDataFolder()+"/data/level.yml"); private AnticheatManager micromanage = null; //like a boss!
private File bukkitFile = new File("bukkit.yml"); private File configFile = null;
private File levelFile = null;
private File bukkitFile = null;
private FileConfiguration config; private FileConfiguration config;
private FileConfiguration level; private FileConfiguration level;
private FileConfiguration bukkit; private FileConfiguration bukkit;
@@ -44,8 +49,12 @@ public class Configuration {
private String updateFolder; private String updateFolder;
private List<String> worlds = new ArrayList<String>(); private List<String> worlds = new ArrayList<String>();
public Configuration() 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(); load();
} }
@@ -93,7 +102,7 @@ public class Configuration {
public final void load() public final void load()
{ {
Anticheat.checkConfig(); micromanage.getPlugin().checkConfig();
config = YamlConfiguration.loadConfiguration(configFile); config = YamlConfiguration.loadConfiguration(configFile);
level = YamlConfiguration.loadConfiguration(levelFile); level = YamlConfiguration.loadConfiguration(levelFile);
bukkit = YamlConfiguration.loadConfiguration(bukkitFile); bukkit = YamlConfiguration.loadConfiguration(bukkitFile);
@@ -0,0 +1,84 @@
package net.h31ix.anticheat.api;
import org.bukkit.entity.Player;
import net.h31ix.anticheat.Anticheat;
import net.h31ix.anticheat.manage.AnticheatManager;
import net.h31ix.anticheat.manage.CheckManager;
import net.h31ix.anticheat.manage.CheckType;
import net.h31ix.anticheat.manage.PlayerManager;
import net.h31ix.anticheat.xray.XRayTracker;
public class AnticheatAPI
{
private static CheckManager chk = Anticheat.getManager().getCheckManager();
private static PlayerManager pmr = Anticheat.getManager().getPlayerManager();
private static XRayTracker xtracker = Anticheat.getManager().getXRayTracker();
//CheckManager API.
public static void activateCheck(CheckType type)
{
chk.activateCheck(type);
}
public static void deactivateCheck(CheckType type)
{
chk.deactivateCheck(type);
}
public static boolean isActive(CheckType type)
{
return chk.isActive(type);
}
public static void exemptPlayer(Player player, CheckType type)
{
chk.exemptPlayer(player, type);
}
public static void unexemptPlayer(Player player, CheckType type)
{
chk.unexemptPlayer(player, type);
}
public static boolean isExempt(Player player, CheckType type)
{
return chk.isExempt(player, type);
}
//PlayerManager API
public static int getLevel(Player player)
{
if(!pmr.hasLevel(player))
{
return 0;
}
return pmr.getLevel(player);
}
public static void setLevel(Player player, int x)
{
pmr.setLevel(player, x);
}
//XrayTracker API
public static boolean isXrayer(Player player)
{
String name = player.getName();
if (xtracker.sufficientData(name) && xtracker.hasAbnormal(name))
{
return true;
}
return false;
}
//Advanced Users Only API.
public static AnticheatManager getManager()
{
return Anticheat.getManager();
}
}
@@ -23,7 +23,6 @@ import net.h31ix.anticheat.manage.Backend;
import net.h31ix.anticheat.manage.CheckManager; import net.h31ix.anticheat.manage.CheckManager;
import net.h31ix.anticheat.manage.CheckType; import net.h31ix.anticheat.manage.CheckType;
import net.h31ix.anticheat.manage.Distance; import net.h31ix.anticheat.manage.Distance;
import org.bukkit.GameMode;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -51,11 +50,11 @@ public class BlockListener extends EventListener
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if(player != null && player.getGameMode() != GameMode.CREATIVE) if(player != null)
{ {
if(checkManager.willCheck(player, CheckType.FAST_PLACE)) if(checkManager.willCheck(player, CheckType.FAST_PLACE))
{ {
if(backend.justPlaced(player)) if(backend.checkFastPlace(player))
{ {
event.setCancelled(true); event.setCancelled(true);
log("tried to place a block of "+block.getType().name()+" too fast.",player,CheckType.FAST_PLACE); log("tried to place a block of "+block.getType().name()+" too fast.",player,CheckType.FAST_PLACE);
@@ -30,16 +30,16 @@ public class EventListener implements Listener
{ {
private static final Map<CheckType,Integer> usageList = new EnumMap<CheckType,Integer>(CheckType.class); private static final Map<CheckType,Integer> usageList = new EnumMap<CheckType,Integer>(CheckType.class);
private static final Map<String,Integer> decreaseList = new HashMap<String,Integer>(); private static final Map<String,Integer> decreaseList = new HashMap<String,Integer>();
private static final CheckManager CHECK_MANAGER = AnticheatManager.CHECK_MANAGER; private static final CheckManager CHECK_MANAGER = Anticheat.getManager().getCheckManager();
private static final Backend BACKEND = AnticheatManager.BACKEND; private static final Backend BACKEND = Anticheat.getManager().getBackend();
private static final Anticheat PLUGIN = Anticheat.getPlugin(); private static final Anticheat PLUGIN = Anticheat.getManager().getPlugin();
private static final PlayerManager PLAYER_MANAGER = AnticheatManager.PLAYER_MANAGER; private static final PlayerManager PLAYER_MANAGER = Anticheat.getManager().getPlayerManager();
public void log(String message,Player player, CheckType type) public void log(String message,Player player, CheckType type)
{ {
if(AnticheatManager.CONFIGURATION.logConsole()) if(Anticheat.getManager().getConfiguration().logConsole())
{ {
AnticheatManager.log(player.getName()+" "+message); Anticheat.getManager().log(player.getName()+" "+message);
} }
PLAYER_MANAGER.increaseLevel(player); PLAYER_MANAGER.increaseLevel(player);
removeDecrease(player); removeDecrease(player);
@@ -102,11 +102,19 @@ public class EventListener implements Listener
return CHECK_MANAGER; return CHECK_MANAGER;
} }
public static AnticheatManager getManager() {
return Anticheat.getManager();
}
public static Backend getBackend() public static Backend getBackend()
{ {
return BACKEND; return BACKEND;
} }
public static PlayerManager getPlayerManager() {
return PLAYER_MANAGER;
}
public static Anticheat getPlugin() public static Anticheat getPlugin()
{ {
return PLUGIN; return PLUGIN;
@@ -22,6 +22,7 @@ import net.h31ix.anticheat.manage.*;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@@ -154,20 +155,20 @@ public class PlayerListener extends EventListener
Player player = event.getPlayer(); Player player = event.getPlayer();
if(checkManager.willCheck(player, CheckType.ZOMBE_FLY)) if(checkManager.willCheck(player, CheckType.ZOMBE_FLY))
{ {
player.sendMessage("§f §f §1 §0 §2 §4"); player.sendMessage("§f §f §1 §0 §2 §4");
} }
if(checkManager.willCheck(player, CheckType.ZOMBE_CHEAT)) if(checkManager.willCheck(player, CheckType.ZOMBE_CHEAT))
{ {
player.sendMessage("§f §f §2 §0 §4 §8"); player.sendMessage("§f §f §2 §0 §4 §8");
} }
if(checkManager.willCheck(player, CheckType.ZOMBE_NOCLIP)) if(checkManager.willCheck(player, CheckType.ZOMBE_NOCLIP))
{ {
player.sendMessage("§f §f §4 §0 §9 §6"); player.sendMessage("§f §f §4 §0 §9 §6");
} }
backend.logJoin(event.getPlayer()); backend.logJoin(event.getPlayer());
if(!AnticheatManager.PLAYER_MANAGER.hasLevel(player)) if(!getPlayerManager().hasLevel(player))
{ {
AnticheatManager.PLAYER_MANAGER.setLevel(player, AnticheatManager.CONFIGURATION.getLevel(player.getName())); getPlayerManager().setLevel(player, getManager().getConfiguration().getLevel(player.getName()));
} }
} }
@@ -184,6 +185,17 @@ public class PlayerListener extends EventListener
if(checkManager.willCheck(player, CheckType.FLY) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && backend.checkFlight(player, from.getY(), to.getY())) if(checkManager.willCheck(player, CheckType.FLY) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && backend.checkFlight(player, from.getY(), to.getY()))
{ {
event.setTo(from); 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 whatever = newLocation.getBlock();
if(whatever.getTypeId() != 0)
{
event.setTo(newLocation);
}
/* else
{
downlow--;
}*/
log("tried to fly.",player,CheckType.FLY); 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(checkManager.willCheck(player, CheckType.SPEED) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && checkManager.willCheck(player, CheckType.FLY))
@@ -220,7 +232,7 @@ public class PlayerListener extends EventListener
event.setTo(from); event.setTo(from);
log("tried to walk on water.",player,CheckType.WATER_WALK); log("tried to walk on water.",player,CheckType.WATER_WALK);
} }
if(checkManager.willCheck(player, CheckType.SNEAK) && checkManager.willCheck(player, CheckType.FLY) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && backend.checkSneak(player,x,z)) if(checkManager.willCheck(player, CheckType.SNEAK) && backend.checkSneak(player,x,z))
{ {
event.setTo(from); event.setTo(from);
player.setSneaking(false); player.setSneaking(false);
@@ -20,25 +20,65 @@ package net.h31ix.anticheat.manage;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.h31ix.anticheat.Anticheat;
import net.h31ix.anticheat.Configuration; import net.h31ix.anticheat.Configuration;
import net.h31ix.anticheat.xray.XRayTracker; import net.h31ix.anticheat.xray.XRayTracker;
public final class AnticheatManager public class AnticheatManager
{ {
private 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 static final Configuration CONFIGURATION = new Configuration(); public void log(String message)
public static final XRayTracker XRAY_TRACKER = new XRayTracker();
public static final PlayerManager PLAYER_MANAGER = new PlayerManager();
public static final CheckManager CHECK_MANAGER = new CheckManager();
public static final Backend BACKEND = new Backend();
private static final Logger ANTICHEAT_LOGGER = Logger.getLogger("Minecraft");
public static void log(String message)
{ {
ANTICHEAT_LOGGER.log(Level.WARNING,"[AC] ".concat(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;
} }
} }
@@ -22,9 +22,9 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.h31ix.anticheat.Anticheat;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@@ -41,6 +41,15 @@ public class Backend
public static final int DAMAGE_TIME = 50; public static final int DAMAGE_TIME = 50;
public static final int KNOCKBACK_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_TIMEMAX = 20;
public static final int FASTPLACE_MAXVIOLATIONS = 1;
public static final int FASTPLACE_MAXVIOLATIONTIME = 10000;
private static final int CHAT_WARN_LEVEL = 7; private static final int CHAT_WARN_LEVEL = 7;
private static final int CHAT_KICK_LEVEL = 10; private static final int CHAT_KICK_LEVEL = 10;
private static final int CHAT_BAN_LEVEL = 3; private static final int CHAT_BAN_LEVEL = 3;
@@ -71,7 +80,7 @@ public class Backend
public static final double XZ_SPEED_MAX_WATER = 0.19; public static final double XZ_SPEED_MAX_WATER = 0.19;
public static final double XZ_SPEED_MAX_WATER_SPRINT = 0.3; public static final double XZ_SPEED_MAX_WATER_SPRINT = 0.3;
private Anticheat plugin = Anticheat.getPlugin(); private AnticheatManager micromanage = null;
private List<String> droppedItem = new ArrayList<String>(); private List<String> droppedItem = new ArrayList<String>();
private List<String> animated = new ArrayList<String>(); private List<String> animated = new ArrayList<String>();
private List<String> movingExempt = new ArrayList<String>(); private List<String> movingExempt = new ArrayList<String>();
@@ -88,6 +97,17 @@ public class Backend
private Map<String,Integer> chatLevel = new HashMap<String,Integer>(); private Map<String,Integer> chatLevel = new HashMap<String,Integer>();
private Map<String,Integer> chatKicks = new HashMap<String,Integer>(); private Map<String,Integer> chatKicks = new HashMap<String,Integer>();
private Map<String,Integer> nofallViolation = new HashMap<String,Integer>(); private Map<String,Integer> nofallViolation = new HashMap<String,Integer>();
private Map<String,Integer> fastBreakViolation = new HashMap<String,Integer>();
private Map<String,Integer> blocksBroken = new HashMap<String,Integer>();
private Map<String,Long> lastBlockBroken = new HashMap<String,Long>();
private Map<String,Integer> fastPlaceViolation = new HashMap<String,Integer>();
private Map<String,Integer> blocksPlaced = new HashMap<String,Integer>();
private Map<String,Long> lastBlockPlaced = new HashMap<String,Long>();
public Backend(AnticheatManager instance)
{
micromanage = instance;
}
public boolean checkLongReachBlock(double x,double y,double z) public boolean checkLongReachBlock(double x,double y,double z)
{ {
@@ -233,9 +253,26 @@ public class Backend
} }
if(violation >= FLIGHT_LIMIT) if(violation >= FLIGHT_LIMIT)
{ {
System.out.println("yep");
flightViolation.put(name, 1); flightViolation.put(name, 1);
return true; 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; return false;
@@ -248,20 +285,61 @@ public class Backend
public boolean checkFastBreak(Player player, Block block) public boolean checkFastBreak(Player player, Block block)
{ {
if(player.getGameMode() != GameMode.CREATIVE && !player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !Utilities.isInstantBreak(block.getType()) && !isInstantBreakExempt(player) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES)) 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 (!justBroke(player)) if (!fastBreakViolation.containsKey(name))
{ {
logBlockBreak(player); fastBreakViolation.put(name, 0);
} }
else else
{ {
return true; Long math = System.currentTimeMillis() - lastBlockBroken.get(name);
player.sendMessage(""+math);
if(fastBreakViolation.get(name) > FASTBREAK_MAXVIOLATIONS && math < FASTBREAK_MAXVIOLATIONTIME)
{
lastBlockBroken.put(name, System.currentTimeMillis());
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; return false;
} }
public boolean checkFastPlace(Player player)
{
return false;
}
public void logBowWindUp(Player player) public void logBowWindUp(Player player)
{ {
logEvent(bowWindUp,player,BOW_MIN); logEvent(bowWindUp,player,BOW_MIN);
@@ -425,10 +503,11 @@ public class Backend
return droppedItem.contains(player.getName()); return droppedItem.contains(player.getName());
} }
private void logEvent(final List list, final Player player, long time) @SuppressWarnings("unchecked")
private void logEvent(@SuppressWarnings("rawtypes") final List list, final Player player, long time)
{ {
list.add(player.getName()); list.add(player.getName());
Anticheat.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Anticheat.getPlugin(), new Runnable() micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable()
{ {
@Override @Override
public void run() public void run()
@@ -437,10 +516,11 @@ public class Backend
} }
}, time); }, time);
} }
private void logEvent(final Map map, final Player player, final Object obj, long time) @SuppressWarnings("unchecked")
private void logEvent(@SuppressWarnings("rawtypes") final Map map, final Player player, final Object obj, long time)
{ {
map.put(player,obj); map.put(player,obj);
Anticheat.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Anticheat.getPlugin(), new Runnable() micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable()
{ {
@Override @Override
public void run() public void run()
@@ -473,13 +553,13 @@ public class Backend
if(chatKicks.get(name) <= CHAT_BAN_LEVEL) if(chatKicks.get(name) <= CHAT_BAN_LEVEL)
{ {
player.kickPlayer(ChatColor.RED+"Spamming, kick "+kick+"/3"); player.kickPlayer(ChatColor.RED+"Spamming, kick "+kick+"/3");
plugin.getServer().broadcastMessage(ChatColor.RED+player.getName()+" was kicked for spamming."); micromanage.getPlugin().getServer().broadcastMessage(ChatColor.RED+player.getName()+" was kicked for spamming.");
} }
else else
{ {
player.kickPlayer(ChatColor.RED+"Banned for spamming."); player.kickPlayer(ChatColor.RED+"Banned for spamming.");
player.setBanned(true); player.setBanned(true);
plugin.getServer().broadcastMessage(ChatColor.RED+player.getName()+" was banned for spamming."); micromanage.getPlugin().getServer().broadcastMessage(ChatColor.RED+player.getName()+" was banned for spamming.");
} }
} }
} }
@@ -31,9 +31,20 @@ import org.bukkit.entity.Player;
public class CheckManager public class CheckManager
{ {
public AnticheatManager manager = null;
private static List<CheckType> checkIgnoreList = new ArrayList<CheckType>(); private static List<CheckType> checkIgnoreList = new ArrayList<CheckType>();
private static Multimap<Player,CheckType> exemptList = ArrayListMultimap.create(); private static Multimap<Player,CheckType> exemptList = ArrayListMultimap.create();
/**
* Initialize the class.
*
* @param instance The AntiCheat Manager
*/
public CheckManager(AnticheatManager instance)
{
manager = instance;
}
/** /**
* Start running a certain check * Start running a certain check
* *
@@ -41,7 +52,7 @@ public class CheckManager
*/ */
public void activateCheck(CheckType type) public void activateCheck(CheckType type)
{ {
AnticheatManager.log("The "+type.toString()+" check was activated."); manager.log("The "+type.toString()+" check was activated.");
checkIgnoreList.remove(type); checkIgnoreList.remove(type);
} }
@@ -52,7 +63,7 @@ public class CheckManager
*/ */
public void deactivateCheck(CheckType type) public void deactivateCheck(CheckType type)
{ {
AnticheatManager.log("The "+type.toString()+" check was deactivated."); manager.log("The "+type.toString()+" check was deactivated.");
checkIgnoreList.add(type); checkIgnoreList.add(type);
} }
@@ -75,7 +86,7 @@ public class CheckManager
*/ */
public void exemptPlayer(Player player, CheckType type) public void exemptPlayer(Player player, CheckType type)
{ {
AnticheatManager.log(player.getName()+" was exempted from the "+type.toString()+" check."); manager.log(player.getName()+" was exempted from the "+type.toString()+" check.");
exemptList.put(player,type); exemptList.put(player,type);
} }
@@ -87,7 +98,7 @@ public class CheckManager
*/ */
public void unexemptPlayer(Player player, CheckType type) public void unexemptPlayer(Player player, CheckType type)
{ {
AnticheatManager.log(player.getName()+" was re-added to the "+type.toString()+" check."); manager.log(player.getName()+" was re-added to the "+type.toString()+" check.");
exemptList.remove(type, type); exemptList.remove(type, type);
} }
@@ -118,7 +129,7 @@ public class CheckManager
public boolean willCheck(Player player, CheckType type) public boolean willCheck(Player player, CheckType type)
{ {
return isActive(type) return isActive(type)
&& AnticheatManager.CONFIGURATION.checkInWorld(player.getWorld()) && manager.getConfiguration().checkInWorld(player.getWorld())
&& !isExempt(player, type) && !isExempt(player, type)
&& !hasPermission(player, type.getPermission()); && !hasPermission(player, type.getPermission());
} }
@@ -20,6 +20,7 @@ package net.h31ix.anticheat.manage;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.h31ix.anticheat.Configuration; import net.h31ix.anticheat.Configuration;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@@ -27,10 +28,14 @@ import org.bukkit.entity.Player;
public class PlayerManager { public class PlayerManager {
private static Map<String,Integer> level = new HashMap<String,Integer>(); private static Map<String,Integer> level = new HashMap<String,Integer>();
private static Configuration config = AnticheatManager.CONFIGURATION; private static Configuration config = null;
private static final int MED_THRESHOLD = 20; private static final int MED_THRESHOLD = 20;
private static final int HIGH_THRESHOLD = 50; private static final int HIGH_THRESHOLD = 50;
public PlayerManager(AnticheatManager instance) {
config = instance.getConfiguration();
}
private static void reactMedium(Player player) private static void reactMedium(Player player)
{ {
execute("Medium",player); execute("Medium",player);
@@ -66,6 +71,11 @@ public class PlayerManager {
else if(playerLevel <= HIGH_THRESHOLD && playerLevel+1 > HIGH_THRESHOLD) else if(playerLevel <= HIGH_THRESHOLD && playerLevel+1 > HIGH_THRESHOLD)
{ {
reactHigh(player); reactHigh(player);
level.put(player.getName(), MED_THRESHOLD+5);
}
else if (playerLevel > HIGH_THRESHOLD)
{
level.put(player.getName(), MED_THRESHOLD+5);
} }
} }
} }
@@ -22,6 +22,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.h31ix.anticheat.Anticheat;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@@ -50,7 +53,7 @@ public final class Utilities
} }
} }
} }
if(AnticheatManager.CONFIGURATION.logConsole()) if(Anticheat.getManager().getConfiguration().logConsole())
{ {
Logger logger = Logger.getLogger("Minecraft"); Logger logger = Logger.getLogger("Minecraft");
for(String msg : message) for(String msg : message)
@@ -18,8 +18,8 @@
package net.h31ix.anticheat.xray; package net.h31ix.anticheat.xray;
import net.h31ix.anticheat.Anticheat;
import net.h31ix.anticheat.Configuration; import net.h31ix.anticheat.Configuration;
import net.h31ix.anticheat.manage.AnticheatManager;
import net.h31ix.anticheat.manage.CheckManager; import net.h31ix.anticheat.manage.CheckManager;
import net.h31ix.anticheat.manage.CheckType; import net.h31ix.anticheat.manage.CheckType;
import org.bukkit.Material; import org.bukkit.Material;
@@ -29,9 +29,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
public class XRayListener implements Listener { public class XRayListener implements Listener {
private XRayTracker tracker = AnticheatManager.XRAY_TRACKER; private XRayTracker tracker = Anticheat.getManager().getXRayTracker();
private Configuration config = AnticheatManager.CONFIGURATION; private Configuration config = Anticheat.getManager().getConfiguration();
private CheckManager checkManager = AnticheatManager.CHECK_MANAGER; private CheckManager checkManager = Anticheat.getManager().getCheckManager();
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event)
@@ -45,7 +45,6 @@ public class XRayTracker {
public XRayTracker() public XRayTracker()
{ {
} }
public boolean sufficientData(String player) public boolean sufficientData(String player)