();
+
+ 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)
+ {
+ if(player.getLocation().getBlock().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)
+ {
+ if(y1 == y2 && !isMovingExempt(player) && player.getVehicle() == null && player.getFallDistance() == 0)
+ {
+ String name = player.getName();
+ Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
+ if(Utilities.cantStandAt(block))
+ {
+ 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)
+ {
+ flightViolation.put(name, 1);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public boolean checkSwing(Player player)
+ {
+ return !justAnimated(player);
+ }
+
+ public boolean checkFastBreak(Player player, Block block)
+ {
+ if(player.getGameMode() != GameMode.CREATIVE && !player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !Utilities.isInstantBreak(block.getType()))
+ {
+ if (!justBroke(player))
+ {
+ logBlockBreak(player);
+ }
+ else
+ {
+ return true;
+ }
+ }
+ 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 void clearChatLevel(Player player)
+ {
+ chatLevel.remove(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 logEnteredVehicle(final Player player)
+ {
+ logEvent(movingExempt,player,ENTERED_VEHICLE_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());
+ }
+
+ private void logEvent(final List list, final Player player, long time)
+ {
+ list.add(player.getName());
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ list.remove(player.getName());
+ }
+ }, time);
+ }
+ private void logEvent(final Map map, final Player player, final Object obj, long time)
+ {
+ map.put(player,obj);
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, 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");
+ plugin.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.");
+ }
+ }
+ }
+}
diff --git a/src/main/java/net/h31ix/anticheat/manage/CheckManager.java b/src/main/java/net/h31ix/anticheat/manage/CheckManager.java
new file mode 100644
index 0000000..e8e42cc
--- /dev/null
+++ b/src/main/java/net/h31ix/anticheat/manage/CheckManager.java
@@ -0,0 +1,125 @@
+/*
+ * 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
+{
+ private static List checkIgnoreList = new ArrayList();
+ private static Multimap exemptList = ArrayListMultimap.create();
+
+ /**
+ * Start running a certain check
+ *
+ * @param type Check to start watching for
+ */
+ public void activateCheck(CheckType type)
+ {
+ AnticheatManager.log("The "+type.toString()+" check was activated.");
+ checkIgnoreList.remove(type);
+ }
+
+ /**
+ * Stop running a certain check
+ *
+ * @param type Check to stop watching for
+ */
+ public void deactivateCheck(CheckType type)
+ {
+ AnticheatManager.log("The "+type.toString()+" check was deactivated.");
+ checkIgnoreList.add(type);
+ }
+
+ /**
+ * Find out if a check is currently being watched for
+ *
+ * @param type Type to check
+ * @return true if plugin is watching for this check
+ */
+ public boolean isActive(CheckType type)
+ {
+ return !checkIgnoreList.contains(type);
+ }
+
+ /**
+ * Allow a player to skip a certain check
+ *
+ * @param player Player to stop watching
+ * @param type Check to stop watching for
+ */
+ public void exemptPlayer(Player player, CheckType type)
+ {
+ AnticheatManager.log(player.getName()+" was exempted from the "+type.toString()+" check.");
+ exemptList.put(player,type);
+ }
+
+ /**
+ * Stop allowing a player to skip a certain check
+ *
+ * @param player Player to start watching
+ * @param type Check to start watching for
+ */
+ public void unexemptPlayer(Player player, CheckType type)
+ {
+ AnticheatManager.log(player.getName()+" was re-added to the "+type.toString()+" check.");
+ exemptList.remove(type, type);
+ }
+
+ /**
+ * Find out if a player is currently exempt from a certain check
+ *
+ * @param player Player to check
+ * @param type Type to check
+ * @return true if plugin is ignoring this check on this player
+ */
+ public boolean isExempt(Player player, CheckType type)
+ {
+ return exemptList.containsEntry(player, type);
+ }
+
+ private boolean hasPermission(Player player, String permission)
+ {
+ return player.hasPermission(permission);
+ }
+
+ /**
+ * Find out if a check will occur for a player. This checks if they are being tracked, the check is active, the player isn't exempt from the check, and the player doesn't have override permission.
+ *
+ * @param player Player to check
+ * @param type Type to check
+ * @return true if plugin will check this player, and that all things allow it to happen.
+ */
+ public boolean willCheck(Player player, CheckType type)
+ {
+ return isActive(type)
+ && AnticheatManager.CONFIGURATION.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
new file mode 100644
index 0000000..7f35aca
--- /dev/null
+++ b/src/main/java/net/h31ix/anticheat/manage/CheckType.java
@@ -0,0 +1,79 @@
+/*
+ * 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.Maps;
+import java.util.Map;
+
+/**
+ *
+ * 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"),
+ SPAM("anticheat.spam"),
+ SPRINT("anticheat.sprint"),
+ SNEAK("anticheat.sneak"),
+ SPEED("anticheat.speed"),
+ SPIDER("anticheat.spider"),
+ NOFALL("anticheat.spider"),
+ 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 static final Map NAMES = Maps.newHashMap();
+
+ private CheckType(String permission)
+ {
+ this.permission = permission;
+ }
+
+ public String getPermission()
+ {
+ return this.permission;
+ }
+
+ public CheckType byName(String name)
+ {
+ return NAMES.get(name);
+ }
+
+ static
+ {
+ for (CheckType type : values())
+ {
+ NAMES.put(type.toString(), type);
+ }
+ }
+
+}
diff --git a/src/main/java/net/h31ix/anticheat/manage/Distance.java b/src/main/java/net/h31ix/anticheat/manage/Distance.java
new file mode 100644
index 0000000..082dac5
--- /dev/null
+++ b/src/main/java/net/h31ix/anticheat/manage/Distance.java
@@ -0,0 +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());
+ }
+}
\ 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
new file mode 100644
index 0000000..eba174f
--- /dev/null
+++ b/src/main/java/net/h31ix/anticheat/manage/PlayerManager.java
@@ -0,0 +1,131 @@
+/*
+ * 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;
+
+public class PlayerManager {
+ private Map level = new HashMap();
+ private Configuration config = AnticheatManager.CONFIGURATION;
+ private static final int MED_THRESHOLD = 20;
+ private static final int HIGH_THRESHOLD = 50;
+
+ public void reactMedium(Player player)
+ {
+ execute("Medium",player);
+ for(Player p : player.getServer().getOnlinePlayers())
+ {
+ if(p.hasPermission("anticheat.admin") || p.isOp())
+ {
+ p.sendMessage(ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.YELLOW+" has entered the MEDIUM hack level.");
+ p.sendMessage(ChatColor.YELLOW+"[ALERT] This means they may be using a hacked client or may have a bad connection!");
+ }
+ }
+ }
+ public void reactHigh(Player player)
+ {
+ execute("High",player);
+ for(Player p : player.getServer().getOnlinePlayers())
+ {
+ if(p.hasPermission("anticheat.admin") || p.isOp())
+ {
+ p.sendMessage(ChatColor.RED+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.RED+" has entered the HIGH hack level.");
+ p.sendMessage(ChatColor.RED+"[ALERT] This means they probably are hacking or are lagging out!");
+ }
+ }
+ }
+
+ public void increaseLevel(Player player)
+ {
+ if(level.get(player) == null || level.get(player) == 0)
+ {
+ level.put(player,1);
+ }
+ else
+ {
+ int playerLevel = level.get(player);
+ level.put(player, 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)
+ {
+ if(level.get(player) != null && level.get(player) != 0)
+ {
+ int playerLevel = level.get(player)-1;
+ level.put(player, playerLevel);
+ }
+ }
+
+ public int getLevel(Player player)
+ {
+ if(level.get(player) != null)
+ {
+ return level.get(player);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ public void reset(Player player)
+ {
+ level.put(player,0);
+ }
+
+ public 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
new file mode 100644
index 0000000..9f36cb2
--- /dev/null
+++ b/src/main/java/net/h31ix/anticheat/manage/Utilities.java
@@ -0,0 +1,100 @@
+/*
+ * 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 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()
+ {
+ 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.GRASS);
+ 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.SPIDER_EYE);
+ FOOD.add(Material.ROTTEN_FLESH);
+ }
+ 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();
+ }
+}
diff --git a/src/main/java/net/h31ix/anticheat/xray/XRayListener.java b/src/main/java/net/h31ix/anticheat/xray/XRayListener.java
new file mode 100644
index 0000000..623581a
--- /dev/null
+++ b/src/main/java/net/h31ix/anticheat/xray/XRayListener.java
@@ -0,0 +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.Configuration;
+import net.h31ix.anticheat.manage.AnticheatManager;
+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 = AnticheatManager.XRAY_TRACKER;
+ private Configuration config = AnticheatManager.CONFIGURATION;
+ private CheckManager checkManager = AnticheatManager.CHECK_MANAGER;
+
+ @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/XRayTracker.java b/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java
new file mode 100644
index 0000000..2ede78c
--- /dev/null
+++ b/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java
@@ -0,0 +1,201 @@
+/*
+ * 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.HashMap;
+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 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 DIVISOR = 100;
+ 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 void sendMessage(CommandSender cs, String player, double t, double d, double g, double i, double c, double la, double r, double b)
+ {
+ cs.sendMessage("--------------------["+GREEN+"X-Ray Stats"+WHITE+"]---------------------");
+ cs.sendMessage(GRAY+"Player: "+WHITE+player);
+ cs.sendMessage(GRAY+"Total blocks broken: "+WHITE+t);
+ calculate(cs,player,d,b,"diamond");
+ calculate(cs,player,g,b,"gold");
+ calculate(cs,player,i,b,"iron");
+ calculate(cs,player,c,b,"coal");
+ calculate(cs,player,la,b,"lapis");
+ calculate(cs,player,r,b,"redstone");
+ cs.sendMessage(GRAY+"Percent all other blocks: "+WHITE+round(b)+"%");
+ cs.sendMessage("-----------------------------------------------------");
+ }
+
+ public void sendStats(CommandSender cs, String player)
+ {
+ getStats(cs,player);
+ }
+
+ public void getStats(CommandSender cs, String player)
+ {
+ double t = 1;
+ double d = 0;
+ double g = 0;
+ double i = 0;
+ double c = 0;
+ double la = 0;
+ double r = 0;
+ double b = 0;
+ if(totalblock.get(player) != null)
+ {
+ t = totalblock.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)
+ {
+ la = (lapis.get(player)/t)*DIVISOR;
+ }
+ if(redstone.get(player) != null)
+ {
+ r = (redstone.get(player)/t)*DIVISOR;
+ }
+ if(block.get(player) != null)
+ {
+ b = (block.get(player)/t)*DIVISOR;
+ }
+ sendMessage(cs,player,t,d,g,i,c,la,r,b);
+ }
+
+ 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
new file mode 100644
index 0000000..9a6eaa5
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,17 @@
+#AntiCheat configuration file
+#Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/
+XRay:
+ Log xray stats: true
+
+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 manuall update.
+ Auto update: true
+ Log to console: false
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..8b4325d
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +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.0'
+commands:
+ anticheat:
+ description: Control and view info about AntiCheat
+ usage: /anticheat help
\ No newline at end of file