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
22 files changed
+1478 -1204

No files matched your search

@@ -20,25 +20,65 @@ 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;
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 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)
public 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.List;
import java.util.Map;
import net.h31ix.anticheat.Anticheat;
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;
@@ -41,6 +41,15 @@ public class Backend
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_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_KICK_LEVEL = 10;
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_SPRINT = 0.3;
private Anticheat plugin = Anticheat.getPlugin();
private AnticheatManager micromanage = null;
private List<String> droppedItem = new ArrayList<String>();
private List<String> animated = 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> chatKicks = 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)
{
@@ -233,9 +253,26 @@ public class Backend
}
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;
@@ -248,19 +285,60 @@ public class Backend
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
{
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
{
return true;
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)
{
return false;
}
public void logBowWindUp(Player player)
{
@@ -425,10 +503,11 @@ public class Backend
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());
Anticheat.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Anticheat.getPlugin(), new Runnable()
micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable()
{
@Override
public void run()
@@ -437,10 +516,11 @@ public class Backend
}
}, 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);
Anticheat.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Anticheat.getPlugin(), new Runnable()
micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable()
{
@Override
public void run()
@@ -473,14 +553,14 @@ public class Backend
if(chatKicks.get(name) <= CHAT_BAN_LEVEL)
{
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
{
player.kickPlayer(ChatColor.RED+"Banned for spamming.");
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 AnticheatManager manager = null;
private static List<CheckType> checkIgnoreList = new ArrayList<CheckType>();
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
*
@@ -41,7 +52,7 @@ public class CheckManager
*/
public void activateCheck(CheckType type)
{
AnticheatManager.log("The "+type.toString()+" check was activated.");
manager.log("The "+type.toString()+" check was activated.");
checkIgnoreList.remove(type);
}
@@ -52,7 +63,7 @@ public class CheckManager
*/
public void deactivateCheck(CheckType type)
{
AnticheatManager.log("The "+type.toString()+" check was deactivated.");
manager.log("The "+type.toString()+" check was deactivated.");
checkIgnoreList.add(type);
}
@@ -75,7 +86,7 @@ public class CheckManager
*/
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);
}
@@ -87,7 +98,7 @@ public class CheckManager
*/
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);
}
@@ -118,7 +129,7 @@ public class CheckManager
public boolean willCheck(Player player, CheckType type)
{
return isActive(type)
&& AnticheatManager.CONFIGURATION.checkInWorld(player.getWorld())
&& manager.getConfiguration().checkInWorld(player.getWorld())
&& !isExempt(player, type)
&& !hasPermission(player, type.getPermission());
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
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 <http://www.gnu.org/licenses/>.
*/
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());
}
}
@@ -1,141 +1,151 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
public class PlayerManager {
private static Map<String,Integer> level = new HashMap<String,Integer>();
private static Configuration config = AnticheatManager.CONFIGURATION;
private static final int MED_THRESHOLD = 20;
private static final int HIGH_THRESHOLD = 50;
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);
}
}
}
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)
{
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<String,Integer> 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 <http://www.gnu.org/licenses/>.
*/
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;
public class PlayerManager {
private static Map<String,Integer> level = new HashMap<String,Integer>();
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 > HIGH_THRESHOLD)
{
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)
{
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<String,Integer> 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.");
}
}
}
@@ -22,6 +22,9 @@ 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;
@@ -50,7 +53,7 @@ public final class Utilities
}
}
}
if(AnticheatManager.CONFIGURATION.logConsole())
if(Anticheat.getManager().getConfiguration().logConsole())
{
Logger logger = Logger.getLogger("Minecraft");
for(String msg : message)