diff --git a/nbactions.xml b/nbactions.xml
new file mode 100644
index 0000000..a8f44cb
--- /dev/null
+++ b/nbactions.xml
@@ -0,0 +1,10 @@
+
+
+
+ CUSTOM-sonar
+ sonar
+
+ sonar:sonar
+
+
+
diff --git a/src/main/java/net/h31ix/anticheat/Anticheat.java b/src/main/java/net/h31ix/anticheat/Anticheat.java
index 11ef4a2..2fe0d24 100644
--- a/src/main/java/net/h31ix/anticheat/Anticheat.java
+++ b/src/main/java/net/h31ix/anticheat/Anticheat.java
@@ -8,14 +8,13 @@ import java.util.logging.Logger;
import net.h31ix.anticheat.command.CommandManager;
import net.h31ix.anticheat.event.*;
import net.h31ix.anticheat.xray.*;
-import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Anticheat extends JavaPlugin {
//Define and initialize managers, used for various checks and tasks in the listeners.
public ChatManager cm = new ChatManager(this);
- public AnimationManager am = new AnimationManager(this);
+ public AnimationManager am = new AnimationManager();
public ExemptManager ex = new ExemptManager(this);
public ItemManager im = new ItemManager(this);
public BowManager bm = new BowManager(this);
@@ -26,31 +25,42 @@ public class Anticheat extends JavaPlugin {
public BlockManager blm = new BlockManager(this);
//End Managers
- public Configuration config;
- public PlayerTracker tracker; //PlayerTracker for monitoring levels
- public XRayTracker xtracker; //XRay tracker for monitoring ores
- private static final Logger l = Logger.getLogger("Minecraft");
- private long lastTime = System.currentTimeMillis();
- private long time = 0;
- public boolean lagged = false;
- public boolean logConsole;
- public FileConfiguration log;
+ private Configuration config;
+ private PlayerTracker tracker; //PlayerTracker for monitoring levels
+ private XRayTracker xtracker; //XRay tracker for monitoring ores
+ private static final Logger logger = Logger.getLogger("Minecraft");
private List worlds;
- @Override
- public void onDisable() {
+ public Configuration getConfiguration()
+ {
+ return config;
}
-
+
+ public PlayerTracker getPlayerTracker()
+ {
+ return tracker;
+ }
+
+ public XRayTracker getXRayTracker()
+ {
+ return xtracker;
+ }
+
+ @Override
+ public void onDisable()
+ {
+
+ }
+
@Override
public void onEnable() {
if(!new File(this.getDataFolder()+"\\config.yml").exists())
{
this.saveDefaultConfig();
}
- config = new Configuration(this);
+ config = new Configuration();
tracker = new PlayerTracker(this);
xtracker = new XRayTracker();
- logConsole = config.logConsole;
worlds = config.getWorlds();
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(new BlockListener(this), this);
@@ -59,27 +69,15 @@ public class Anticheat extends JavaPlugin {
getCommand("anticheat").setExecutor(new CommandManager(this));
- getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
- {
- @Override
- public void run()
- {
- long l = System.currentTimeMillis();
- time = l-lastTime;
- lastTime = l;
- time = time/10;
- lagged = time > 1500;
- }
- }, 200L, 200L);
- l.log(Level.INFO,"--[Thanks for using a DEV build of AntiCheat!]--");
- l.log(Level.INFO,"If you notice any bugs, PLEASE report them on BukkitDev!");
+ logger.log(Level.INFO,"--[Thanks for using a DEV build of AntiCheat!]--");
+ logger.log(Level.INFO,"If you notice any bugs, PLEASE report them on BukkitDev!");
}
public void log(String s)
{
- if(this.logConsole)
+ if(config.logConsole())
{
- l.log(Level.WARNING,"[AntiCheat] "+s);
+ logger.log(Level.WARNING, (new StringBuilder("[AntiCheat]")).append(s).toString());
}
}
@@ -97,11 +95,5 @@ public class Anticheat extends JavaPlugin {
}
return check;
}
-
- //Avoid catching our own teleportations
- public void logTeleport()
- {
-
- }
}
diff --git a/src/main/java/net/h31ix/anticheat/Configuration.java b/src/main/java/net/h31ix/anticheat/Configuration.java
index 33ed7f6..d642dd3 100644
--- a/src/main/java/net/h31ix/anticheat/Configuration.java
+++ b/src/main/java/net/h31ix/anticheat/Configuration.java
@@ -14,13 +14,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
public class Configuration {
private File configFile = new File("plugins/AntiCheat/config.yml");
private FileConfiguration config;
- private Anticheat plugin;
- public boolean logConsole;
+ private boolean logConsole;
+ private boolean logXRay;
private List worlds = new ArrayList();
- public Configuration(Anticheat plugin)
+ public Configuration()
{
- this.plugin = plugin;
load();
}
@@ -33,7 +32,17 @@ public class Configuration {
}
}
- public void load()
+ public boolean logConsole()
+ {
+ return logConsole;
+ }
+
+ public boolean logXRay()
+ {
+ return logXRay;
+ }
+
+ public final void load()
{
config = YamlConfiguration.loadConfiguration(configFile);
logConsole = config.getBoolean("Logging.Log to console");
@@ -47,7 +56,13 @@ public class Configuration {
config.set("Enable in", w);
save();
}
- worlds = (List)(config.getList("Enable in"));
+ worlds = (List)(config.getList("Enable in"));
+ if(config.getString("XRay.Log xray stats") == null)
+ {
+ config.set("XRay.Log xray stats", true);
+ save();
+ }
+ logXRay = config.getBoolean("XRay.Log xray stats");
}
public String getResult(String event)
@@ -59,7 +74,6 @@ public class Configuration {
{
config.set("Logging.Log to console", b);
this.logConsole = b;
- plugin.logConsole = b;
try {
config.save(configFile);
} catch (IOException ex) {
diff --git a/src/main/java/net/h31ix/anticheat/PlayerTracker.java b/src/main/java/net/h31ix/anticheat/PlayerTracker.java
index 189513a..d690fd3 100644
--- a/src/main/java/net/h31ix/anticheat/PlayerTracker.java
+++ b/src/main/java/net/h31ix/anticheat/PlayerTracker.java
@@ -6,14 +6,14 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class PlayerTracker {
- public Map level = new HashMap();
- Anticheat plugin;
- Configuration config;
+ private Map level = new HashMap();
+ private Configuration config;
+ private static final int MED_THRESHOLD = 10;
+ private static final int HIGH_THRESHOLD = 40;
public PlayerTracker(Anticheat plugin)
{
- this.plugin = plugin;
- this.config = plugin.config;
+ this.config = plugin.getConfiguration();
}
public void increaseLevel(Player player, int i)
@@ -26,7 +26,7 @@ public class PlayerTracker {
{
int playerLevel = level.get(player);
level.put(player, playerLevel+i);
- if(playerLevel <= 10 && playerLevel+i > 10 && playerLevel+1 <= 40)
+ if(playerLevel <= MED_THRESHOLD && playerLevel+i > MED_THRESHOLD && playerLevel+1 <= HIGH_THRESHOLD)
{
execute("Medium",player);
for(Player p : player.getServer().getOnlinePlayers())
@@ -38,7 +38,7 @@ public class PlayerTracker {
}
}
}
- if(playerLevel <= 40 && playerLevel+i > 40)
+ if(playerLevel <= HIGH_THRESHOLD && playerLevel+i > HIGH_THRESHOLD)
{
execute("High",player);
for(Player p : player.getServer().getOnlinePlayers())
diff --git a/src/main/java/net/h31ix/anticheat/checks/EyeCheck.java b/src/main/java/net/h31ix/anticheat/checks/EyeCheck.java
index 5ed692c..6c77506 100644
--- a/src/main/java/net/h31ix/anticheat/checks/EyeCheck.java
+++ b/src/main/java/net/h31ix/anticheat/checks/EyeCheck.java
@@ -6,15 +6,17 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class EyeCheck {
+ private static final int EYE_DISTANCE = 20;
public EyeCheck()
{
+
}
public boolean canSee(Player player, Block block)
{
//TODO: The logic here is NOT concrete, especially when looking down at an angle.
- List blocks = player.getLineOfSight(null, 20);
+ List blocks = player.getLineOfSight(null, EYE_DISTANCE);
Location bloc = block.getLocation();
boolean see = false;
for(Block b : blocks)
@@ -26,13 +28,6 @@ public class EyeCheck {
see = true;
}
}
- if(see)
- {
- return true;
- }
- else
- {
- return false;
- }
+ return see;
}
}
diff --git a/src/main/java/net/h31ix/anticheat/checks/LengthCheck.java b/src/main/java/net/h31ix/anticheat/checks/LengthCheck.java
index 95dcaad..1c3bb19 100644
--- a/src/main/java/net/h31ix/anticheat/checks/LengthCheck.java
+++ b/src/main/java/net/h31ix/anticheat/checks/LengthCheck.java
@@ -3,8 +3,8 @@ package net.h31ix.anticheat.checks;
import org.bukkit.Location;
public class LengthCheck {
- Location l1, l2;
- //Used for checking how far a player travels on an event and how far they are from another location
+ private Location l1, l2;
+
public LengthCheck(Location l1, Location l2)
{
this.l1 = l1;
@@ -13,26 +13,17 @@ public class LengthCheck {
public double getXDifference()
{
- double bx = l1.getX();
- double px = l2.getX();
- double xdiff = Math.abs(bx-px);
- return xdiff;
+ return Math.abs(l1.getX()-l2.getX());
}
public double getZDifference()
{
- double bz = l1.getZ();
- double pz = l2.getZ();
- double zdiff = Math.abs(bz-pz);
- return zdiff;
+ return Math.abs(l1.getZ()-l2.getZ());
}
public double getYDifference()
{
- double by = l1.getY();
- double py = l2.getY();
- double ydiff = Math.abs(by-py);
- return ydiff;
+ return Math.abs(l1.getY()-l2.getY());
}
}
diff --git a/src/main/java/net/h31ix/anticheat/command/CommandManager.java b/src/main/java/net/h31ix/anticheat/command/CommandManager.java
index b113818..9a2c660 100644
--- a/src/main/java/net/h31ix/anticheat/command/CommandManager.java
+++ b/src/main/java/net/h31ix/anticheat/command/CommandManager.java
@@ -3,6 +3,7 @@ package net.h31ix.anticheat.command;
import java.util.ArrayList;
import java.util.List;
import net.h31ix.anticheat.Anticheat;
+import net.h31ix.anticheat.Configuration;
import net.h31ix.anticheat.PlayerTracker;
import net.h31ix.anticheat.xray.XRayTracker;
import org.bukkit.Bukkit;
@@ -14,23 +15,23 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandManager implements CommandExecutor {
- Anticheat plugin;
- PlayerTracker tracker;
- XRayTracker xtracker;
- ChatColor red = ChatColor.RED;
- ChatColor yellow = ChatColor.YELLOW;
- ChatColor green = ChatColor.GREEN;
- ChatColor white = ChatColor.WHITE;
- List high = new ArrayList();
- List med = new ArrayList();
- List low = new ArrayList();
- Server server = Bukkit.getServer();
+ private Configuration config;
+ private PlayerTracker tracker;
+ private XRayTracker xtracker;
+ private static final ChatColor red = ChatColor.RED;
+ private static final ChatColor yellow = ChatColor.YELLOW;
+ private static final ChatColor green = ChatColor.GREEN;
+ private static final ChatColor white = ChatColor.WHITE;
+ private List high = new ArrayList();
+ private List med = new ArrayList();
+ private List low = new ArrayList();
+ private static final Server server = Bukkit.getServer();
public CommandManager(Anticheat plugin)
{
- this.plugin = plugin;
- this.tracker = plugin.tracker;
- this.xtracker = plugin.xtracker;
+ this.tracker = plugin.getPlayerTracker();
+ this.xtracker = plugin.getXRayTracker();
+ this.config = plugin.getConfiguration();
}
@Override
public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
@@ -42,9 +43,9 @@ public class CommandManager implements CommandExecutor {
{
if(args[1].equalsIgnoreCase("enable"))
{
- if(!plugin.config.logConsole)
+ if(!config.logConsole())
{
- plugin.config.setLog(true);
+ config.setLog(true);
cs.sendMessage(green+"Console logging enabled.");
}
else
@@ -54,9 +55,9 @@ public class CommandManager implements CommandExecutor {
}
else if(args[1].equalsIgnoreCase("disable"))
{
- if(plugin.config.logConsole)
+ if(config.logConsole())
{
- plugin.config.setLog(false);
+ config.setLog(false);
cs.sendMessage(green+"Console logging disabled.");
}
else
@@ -74,23 +75,30 @@ public class CommandManager implements CommandExecutor {
{
if(hasPermission("admin",cs))
{
- List list = server.matchPlayer(args[1]);
- if(list.size() == 1)
+ if(config.logXRay())
{
- Player player = list.get(0);
- xtracker.sendStats(cs, player);
- }
- else if(list.size() > 1)
- {
- cs.sendMessage(red+"Multiple players found by name: "+white+args[1]+red+".");
+ List list = server.matchPlayer(args[1]);
+ if(list.size() == 1)
+ {
+ Player player = list.get(0);
+ xtracker.sendStats(cs, player);
+ }
+ else if(list.size() > 1)
+ {
+ cs.sendMessage(red+"Multiple players found by name: "+white+args[1]+red+".");
+ }
+ else
+ {
+ cs.sendMessage(red+"Player: "+white+args[1]+red+" not found.");
+ }
}
else
{
- cs.sendMessage(red+"Player: "+white+args[1]+red+" not found.");
- }
+ cs.sendMessage(red+"XRay logging is off in the config.");
+ }
}
}
- else if(args[0].equalsIgnoreCase("pardon"))
+ else if(args[0].equalsIgnoreCase("reset"))
{
if(hasPermission("admin",cs))
{
@@ -108,6 +116,8 @@ public class CommandManager implements CommandExecutor {
tracker.reset(player);
cs.sendMessage(player.getName()+green+" has been reset to Low Level.");
}
+ xtracker.reset(player);
+ cs.sendMessage(player.getName()+green+"'s XRay stats have been reset.");
}
else if(list.size() > 1)
{
@@ -135,7 +145,7 @@ public class CommandManager implements CommandExecutor {
cs.sendMessage("/AntiCheat "+green+"report"+white+" - get a detailed cheat report");
cs.sendMessage("/AntiCheat "+green+"reload"+white+" - reload AntiCheat configuration");
cs.sendMessage("/AntiCheat "+green+"help"+white+" - access this page");
- cs.sendMessage("/AntiCheat "+green+"pardon [user]"+white+" - reset user's level");
+ cs.sendMessage("/AntiCheat "+green+"reset [user]"+white+" - reset user's hack level");
cs.sendMessage("/AntiCheat "+green+"xray [user]"+white+" - check user's xray levels");
cs.sendMessage("-----------------------------------------------------");
}
@@ -175,7 +185,7 @@ public class CommandManager implements CommandExecutor {
{
if(hasPermission("admin",cs))
{
- plugin.config.load();
+ config.load();
cs.sendMessage(green+"AntiCheat configuration reloaded.");
}
}
diff --git a/src/main/java/net/h31ix/anticheat/event/BlockListener.java b/src/main/java/net/h31ix/anticheat/event/BlockListener.java
index 889e881..877b5bc 100644
--- a/src/main/java/net/h31ix/anticheat/event/BlockListener.java
+++ b/src/main/java/net/h31ix/anticheat/event/BlockListener.java
@@ -14,17 +14,18 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockListener implements Listener {
- Anticheat plugin;
- AnimationManager am;
- PlayerTracker tracker;
- EyeCheck e = new EyeCheck();
- BlockManager blm;
+ private Anticheat plugin;
+ private AnimationManager am;
+ private PlayerTracker tracker;
+ private static final EyeCheck e = new EyeCheck();
+ private BlockManager blm;
+ private static final double BLOCK_MAX_DISTANCE = 6.0;
public BlockListener(Anticheat plugin)
{
this.plugin = plugin;
this.am = plugin.am;
- this.tracker = plugin.tracker;
+ this.tracker = plugin.getPlayerTracker();
this.blm = plugin.blm;
}
@@ -53,7 +54,7 @@ public class BlockListener implements Listener {
{
//If so, check the distance from the block. Is it too far away?
LengthCheck c = new LengthCheck(block.getLocation(),event.getPlayer().getLocation());
- if(c.getXDifference() > 6.0D || c.getZDifference() > 6.0D || c.getYDifference() > 6.0D)
+ if(c.getXDifference() > BLOCK_MAX_DISTANCE || c.getZDifference() > BLOCK_MAX_DISTANCE || c.getYDifference() > BLOCK_MAX_DISTANCE)
{
plugin.log(player.getName()+" tried to break a block too far away!");
tracker.increaseLevel(player,2);
@@ -113,21 +114,16 @@ public class BlockListener implements Listener {
{
if(plugin.check(player))
{
- if(block.getType() != Material.LADDER)
+ if(block.getType() != Material.LADDER && !e.canSee(player, block) && !player.getWorld().getBlockAt(player.getLocation()).isLiquid())
{
- //Check if the player can see the block they are placing
- //This is mostly used for preventing build/autobuild hacks (Logic not yet finished)
- if(!e.canSee(player, block) && !player.getWorld().getBlockAt(player.getLocation()).isLiquid())
- {
- plugin.log(player.getName()+" tried to place a block that they couldn't see!");
- event.setCancelled(true);
- }
+ plugin.log(player.getName()+" tried to place a block that they couldn't see!");
+ event.setCancelled(true);
}
if(!player.hasPermission("anticheat.longreach"))
{
//Is the player too far away?
LengthCheck c = new LengthCheck(block.getLocation(),event.getPlayer().getLocation());
- if(c.getXDifference() > 6.0D || c.getZDifference() > 6.0D || c.getYDifference() > 6.0D)
+ if(c.getXDifference() > BLOCK_MAX_DISTANCE || c.getZDifference() > BLOCK_MAX_DISTANCE || c.getYDifference() > BLOCK_MAX_DISTANCE)
{
tracker.increaseLevel(player,2);
plugin.log(player.getName()+" tried to place a block too far away!");
diff --git a/src/main/java/net/h31ix/anticheat/event/EntityListener.java b/src/main/java/net/h31ix/anticheat/event/EntityListener.java
index 0c94abd..b4b2672 100644
--- a/src/main/java/net/h31ix/anticheat/event/EntityListener.java
+++ b/src/main/java/net/h31ix/anticheat/event/EntityListener.java
@@ -2,7 +2,6 @@ package net.h31ix.anticheat.event;
import net.h31ix.anticheat.Anticheat;
import net.h31ix.anticheat.PlayerTracker;
-import net.h31ix.anticheat.checks.EyeCheck;
import net.h31ix.anticheat.checks.LengthCheck;
import net.h31ix.anticheat.manage.*;
import org.bukkit.enchantments.Enchantment;
@@ -17,23 +16,23 @@ import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
public class EntityListener implements Listener {
- Anticheat plugin;
- BowManager bm;
- ExemptManager ex;
- PlayerTracker tracker;
- HealthManager hm;
- FoodManager fom;
- AnimationManager am;
+ private Anticheat plugin;
+ private BowManager bm;
+ private ExemptManager ex;
+ private PlayerTracker tracker;
+ private HealthManager hm;
+ private FoodManager fom;
+ private static final double ENTITY_MAX_DISTANCE_XZ = 5.0;
+ private static final double ENTITY_MAX_DISTANCE_Y = 4.3;
public EntityListener(Anticheat plugin)
{
this.plugin = plugin;
this.bm = plugin.bm;
- this.tracker = plugin.tracker;
+ this.tracker = plugin.getPlayerTracker();
this.ex = plugin.ex;
this.hm = plugin.hm;
this.fom = plugin.fom;
- this.am = plugin.am;
}
@EventHandler
@@ -125,11 +124,7 @@ public class EntityListener implements Listener {
{
if (event instanceof EntityDamageByEntityEvent)
{
- EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
- if (e.getDamager() instanceof Player)
- {
- Player p = (Player) e.getDamager();
- }
+ EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
if(event.getEntity() instanceof Player)
{
Player player = (Player)event.getEntity();
@@ -151,7 +146,7 @@ public class EntityListener implements Listener {
{
//Make sure they are close enough to the entity to hit them
LengthCheck lc = new LengthCheck(event.getEntity().getLocation(),p.getLocation());
- if(lc.getXDifference() > 5.0D || lc.getZDifference() > 5.0D || lc.getYDifference() > 4.3D)
+ if(lc.getXDifference() > ENTITY_MAX_DISTANCE_XZ || lc.getZDifference() > ENTITY_MAX_DISTANCE_XZ || lc.getYDifference() > ENTITY_MAX_DISTANCE_Y)
{
tracker.increaseLevel(player,2);
plugin.log(player.getName()+" tried to hit an entity too far away!");
diff --git a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java
index 6a3d0f1..4e01871 100644
--- a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java
+++ b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java
@@ -28,16 +28,16 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffectType;
public class PlayerListener implements Listener {
- Anticheat plugin;
- AnimationManager am;
- ExemptManager ex;
- PlayerTracker tracker;
- ItemManager im;
- HealthManager hm;
- LoginManager lm;
- FlyManager fm;
- BowManager bm;
- FoodManager fom;
+ private Anticheat plugin;
+ private AnimationManager am;
+ private ExemptManager ex;
+ private PlayerTracker tracker;
+ private ItemManager im;
+ private HealthManager hm;
+ private LoginManager lm;
+ private FlyManager fm;
+ private BowManager bm;
+ private FoodManager fom;
public PlayerListener(Anticheat plugin)
{
@@ -45,7 +45,7 @@ public class PlayerListener implements Listener {
this.am = plugin.am;
this.ex = plugin.ex;
this.im = plugin.im;
- this.tracker = plugin.tracker;
+ this.tracker = plugin.getPlayerTracker();
this.hm = plugin.hm;
this.lm = plugin.lm;
this.fm = plugin.fm;
@@ -87,19 +87,16 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
if(plugin.check(player))
{
- if(!player.hasPermission("anticheat.spamdrop"))
+ if(!player.hasPermission("anticheat.spamdrop") && !im.hasDropped(player))
{
- if(!im.hasDropped(player))
- {
- //Make sure the player isn't spamming drops
- //For a normal user this is no big deal, but to hackers it gets rid of most of the items in their inventory
- im.logDrop(player);
- }
- else
- {
- plugin.log(player.getName()+" tried to drop blocks too fast!");
- event.setCancelled(true);
- }
+ //Make sure the player isn't spamming drops
+ //For a normal user this is no big deal, but to hackers it gets rid of most of the items in their inventory
+ im.logDrop(player);
+ }
+ else
+ {
+ plugin.log(player.getName()+" tried to drop blocks too fast!");
+ event.setCancelled(true);
}
}
}
@@ -129,12 +126,9 @@ public class PlayerListener implements Listener {
{
Player player = event.getPlayer();
if(!player.hasPermission("anticheat.spam"))
- {
- if(!plugin.lagged)
- {
- //Block command spamming (consider them chats)
- plugin.cm.addChat(event.getPlayer());
- }
+ {
+ //Block command spamming (consider them chats)
+ plugin.cm.addChat(event.getPlayer());
}
}
@@ -149,9 +143,9 @@ public class PlayerListener implements Listener {
//Make sure the player is not a potential spambot
event.setCancelled(true);
player.sendMessage("Please move from spawn before speaking.");
- }
- if(!plugin.lagged)
- {
+ }
+ else
+ {
//Block chat spamming
plugin.cm.addChat(player);
}
@@ -188,179 +182,146 @@ public class PlayerListener implements Listener {
public void onPlayerMove(PlayerMoveEvent event)
{
Player player = event.getPlayer();
- if(plugin.check(player))
+ if(plugin.check(player) && !ex.isHit(player))
{
- if(!plugin.lagged && !ex.isHit(player))
+ //Log the player's health level
+ hm.log(player);
+ //Get distances for hack checks.
+ LengthCheck c = new LengthCheck(event.getFrom(), event.getTo());
+ double xd = c.getXDifference();
+ double zd = c.getZDifference();
+ double yd = c.getYDifference();
+ String speed = "XSpeed="+xd+" ZSpeed="+zd;
+ Block p1 = player.getLocation().getWorld().getBlockAt(player.getLocation());
+ //Is the player in water?
+ if(p1.isLiquid())
{
- //Log the player's health level
- hm.log(player);
- //Get distances for hack checks.
- LengthCheck c = new LengthCheck(event.getFrom(), event.getTo());
- double xd = c.getXDifference();
- double zd = c.getZDifference();
- double yd = c.getYDifference();
- Block p1 = player.getLocation().getWorld().getBlockAt(player.getLocation());
- //Is the player in water?
- if(p1.isLiquid())
+ //Are they using a boat? If so give them a bit more leniency
+ if (player.getVehicle() != null)
{
- //Are they using a boat? If so give them a bit more leniency
- if (player.getVehicle() != null)
+ if(xd > 2.0D || zd > 2.0D)
{
- if(xd > 2.0D || zd > 2.0D)
+ tracker.increaseLevel(player,2);
+ plugin.log(player.getName()+" is using a boat too fast! "+speed);
+ }
+ }
+ else if(xd > 0.19D || zd > 0.19D)
+ {
+ if(!player.hasPermission("anticheat.waterwalk") && !player.isSprinting() && !player.isFlying() && player.getNearbyEntities(1, 1, 1).isEmpty())
+ {
+ tracker.increaseLevel(player,2);
+ plugin.log(player.getName()+" is walking too fast in water! "+speed);
+ event.setTo(event.getFrom().clone());
+ }
+ }
+ else
+ {
+ if(!player.hasPermission("anticheat.waterwalk") && xd > 0.3D || zd > 0.3D)
+ {
+ tracker.increaseLevel(player,2);
+ plugin.log(player.getName()+" is flying/sprinting too fast in water! "+speed);
+ event.setTo(event.getFrom().clone());
+ }
+ }
+ }
+ else
+ {
+ //Are they in a vehicle?
+ if (player.getVehicle() != null)
+ {
+ //Nothing to do
+ }
+ //Otherwise, are they sneaking?
+ else if(player.isSneaking() && !player.hasPermission("anticheat.sneakhack") && !player.isFlying() && xd > 0.2D || zd > 0.2D)
+ {
+ tracker.increaseLevel(player,2);
+ plugin.log(player.getName()+" is sneaking too fast! "+speed);
+ event.setTo(event.getFrom().clone());
+ //If they are, force them out of it.
+ player.setSneaking(false);
+ }
+ //Otherwise set a hardcoded limit to any other traveling
+ else if(xd > 0.4D || zd > 0.4D)
+ {
+ if(!player.hasPermission("anticheat.speedhack") && !player.isFlying() && !player.hasPotionEffect(PotionEffectType.SPEED))
+ {
+ if(!player.isSprinting())
{
tracker.increaseLevel(player,2);
- plugin.log(player.getName()+" is using a boat too fast! XSpeed="+xd+" ZSpeed="+zd);
- }
- }
- else if(xd > 0.19D || zd > 0.19D)
- {
- if(!player.hasPermission("anticheat.waterwalk"))
- {
- //Otherwise check for normal walking speeds, making sure they aren't using 'jesus' hacks
- if(!player.isSprinting() && !player.isFlying() && player.getNearbyEntities(1, 1, 1).isEmpty())
- {
- tracker.increaseLevel(player,2);
- plugin.log(player.getName()+" is walking too fast in water! XSpeed="+xd+" ZSpeed="+zd);
- event.setTo(event.getFrom().clone());
- }
- }
- }
- else
- {
- if(!player.hasPermission("anticheat.waterwalk"))
- {
- //If they are flying/sprinting give them a bit of slack
- if(xd > 0.3D || zd > 0.3D)
- {
- tracker.increaseLevel(player,2);
- plugin.log(player.getName()+" is flying/sprinting too fast in water! XSpeed="+xd+" ZSpeed="+zd);
- event.setTo(event.getFrom().clone());
- }
- }
- }
- }
- else
- {
- //Are they in a vehicle?
- if (player.getVehicle() != null)
- {
- //Nothing to do
- }
- //Otherwise, are they sneaking?
- else if(player.isSneaking())
- {
- if(!player.hasPermission("anticheat.sneakhack") && !player.isFlying())
- {
- //Make sure they are at normal sneak speeds. (not using sneak hacks)
- if(xd > 0.2D || zd > 0.2D)
- {
- tracker.increaseLevel(player,2);
- plugin.log(player.getName()+" is sneaking too fast! XSpeed="+xd+" ZSpeed="+zd);
- event.setTo(event.getFrom().clone());
- //If they are, force them out of it.
- player.setSneaking(false);
- }
- }
- }
- //Otherwise set a hardcoded limit to any other traveling
- else if(xd > 0.4D || zd > 0.4D)
- {
- if(!player.hasPermission("anticheat.speedhack"))
- {
- if(!player.isFlying() && !player.hasPotionEffect(PotionEffectType.SPEED))
- {
- if(!player.isSprinting())
- {
- tracker.increaseLevel(player,2);
- plugin.log(player.getName()+" is walking too fast! XSpeed="+xd+" ZSpeed="+zd);
- event.setTo(event.getFrom().clone());
- }
- else
- {
- //If they are sprinting or flying give slack
- if(xd > 0.7D || zd > 0.7D)
- {
- tracker.increaseLevel(player,2);
- plugin.log(player.getName()+" is sprinting too fast! XSpeed="+xd+" ZSpeed="+zd);
- event.setTo(event.getFrom().clone());
- }
- }
- }
- }
- }
- }
- //If the player is ascending
- if(event.getFrom().getY() < event.getTo().getY())
- {
- //TODO: This is a little hacky. Any better way to figure this out?
- //Are they climbing something?
- if(yd <= 0.11761 && yd >= 0.11759)
- {
- if(!player.hasPermission("anticheat.spider"))
- {
- if(player.getLocation().getBlock().getType() != Material.VINE && player.getLocation().getBlock().getType() != Material.LADDER)
- {
- //If it's not climbable, block it.
- plugin.log(player.getName()+" tried to climb a wall!");
- tracker.increaseLevel(player,3);
- event.setTo(event.getFrom().clone());
- }
- }
- }
- else if(!player.isFlying() && player.getVehicle() == null)
- {
- if(!player.hasPermission("anticheat.flyhack"))
- {
- //Otherwise check for fast ascension
- if(yd > 0.5D)
- {
- tracker.increaseLevel(player,2);
- plugin.log(player.getName()+" is ascending too fast! YSpeed="+yd);
- event.setTo(event.getFrom().clone());
- }
- }
- }
- }
- //If they are falling
- else if(event.getFrom().getY() > event.getTo().getY())
- {
- //Ignore players in creative or in vehicles, they give a fall distance of 0 naturally.
- if(player.getGameMode() != GameMode.CREATIVE && player.getVehicle() == null)
- {
- if(!player.hasPermission("anticheat.nofall"))
- {
- hm.log(player);
- //Log health (for nofall detection)
- if(hm.checkFall(player))
- {
- //If the player is falling but has a 0 fall distance
- plugin.log(player.getName()+" tried to avoid fall damage!");
- tracker.increaseLevel(player,2);
- }
- }
- }
- }
- //No change in Y
- else
- {
- if(!player.hasPermission("anticheat.flyhack") && !player.isFlying() && player.getVehicle() == null)
- {
- Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
- if(!canStand(block) && !canStand(block.getRelative(BlockFace.NORTH)) && !canStand(block.getRelative(BlockFace.EAST)) && !canStand(block.getRelative(BlockFace.SOUTH)) && !canStand(block.getRelative(BlockFace.WEST)) && !canStand(block.getRelative(BlockFace.NORTH_WEST)) && !canStand(block.getRelative(BlockFace.NORTH_EAST)) && !canStand(block.getRelative(BlockFace.SOUTH_WEST)) && !canStand(block.getRelative(BlockFace.SOUTH_EAST)))
+ plugin.log(player.getName()+" is walking too fast! "+speed);
+ event.setTo(event.getFrom().clone());
+ }
+ else
{
- if (fm.checkFly(player))
+ //If they are sprinting or flying give slack
+ if(xd > 0.7D || zd > 0.7D)
{
- event.setTo(event.getFrom().clone());
- plugin.log(player.getName()+" tried to fly!");
tracker.increaseLevel(player,2);
+ plugin.log(player.getName()+" is sprinting too fast! "+speed);
+ event.setTo(event.getFrom().clone());
}
- else
- {
- tracker.decreaseLevel(player);
- }
- }
+ }
}
}
+ }
+ //If the player is ascending
+ if(event.getFrom().getY() < event.getTo().getY())
+ {
+ //TODO: This is a little hacky. Any better way to figure this out?
+ //Are they climbing something?
+ if(yd <= 0.11761 && yd >= 0.11759)
+ {
+ if(!player.hasPermission("anticheat.spider") && player.getLocation().getBlock().getType() != Material.VINE && player.getLocation().getBlock().getType() != Material.LADDER)
+ {
+ //If it's not climbable, block it.
+ plugin.log(player.getName()+" tried to climb a wall!");
+ tracker.increaseLevel(player,3);
+ event.setTo(event.getFrom().clone());
+ }
+ }
+ else if(!player.isFlying() && player.getVehicle() == null && !player.hasPermission("anticheat.flyhack") && yd > 0.5D)
+ {
+ tracker.increaseLevel(player,2);
+ plugin.log(player.getName()+" is ascending too fast! YSpeed="+yd);
+ event.setTo(event.getFrom().clone());
+ }
+ }
+ //If they are falling
+ else if(event.getFrom().getY() > event.getTo().getY())
+ {
+ //Ignore players in creative or in vehicles, they give a fall distance of 0 naturally.
+ if(!player.hasPermission("anticheat.nofall") && player.getGameMode() != GameMode.CREATIVE && player.getVehicle() == null)
+ {
+ hm.log(player);
+ //Log health (for nofall detection)
+ if(hm.checkFall(player))
+ {
+ //If the player is falling but has a 0 fall distance
+ plugin.log(player.getName()+" tried to avoid fall damage!");
+ tracker.increaseLevel(player,2);
+ }
+ }
+ }
+ //No change in Y
+ else
+ {
+ if(!player.hasPermission("anticheat.flyhack") && !player.isFlying() && player.getVehicle() == null)
+ {
+ Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
+ if(!canStand(block) && !canStand(block.getRelative(BlockFace.NORTH)) && !canStand(block.getRelative(BlockFace.EAST)) && !canStand(block.getRelative(BlockFace.SOUTH)) && !canStand(block.getRelative(BlockFace.WEST)) && !canStand(block.getRelative(BlockFace.NORTH_WEST)) && !canStand(block.getRelative(BlockFace.NORTH_EAST)) && !canStand(block.getRelative(BlockFace.SOUTH_WEST)) && !canStand(block.getRelative(BlockFace.SOUTH_EAST)))
+ {
+ if (fm.checkFly(player))
+ {
+ event.setTo(event.getFrom().clone());
+ plugin.log(player.getName()+" tried to fly!");
+ tracker.increaseLevel(player,2);
+ }
+ else
+ {
+ tracker.decreaseLevel(player);
+ }
+ }
+ }
}
}
}
@@ -371,14 +332,6 @@ public class PlayerListener implements Listener {
{
return true;
}
- if(block.isLiquid())
- {
- return false;
- }
- else if (block.getType() == Material.AIR)
- {
- return false;
- }
else
{
return true;
diff --git a/src/main/java/net/h31ix/anticheat/manage/AnimationManager.java b/src/main/java/net/h31ix/anticheat/manage/AnimationManager.java
index 551c4af..9b01605 100644
--- a/src/main/java/net/h31ix/anticheat/manage/AnimationManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/AnimationManager.java
@@ -2,16 +2,15 @@ package net.h31ix.anticheat.manage;
import java.util.HashMap;
import java.util.Map;
-import net.h31ix.anticheat.Anticheat;
+
import org.bukkit.entity.Player;
public class AnimationManager {
- public Map animations = new HashMap();
- Anticheat plugin;
+ private Map animations = new HashMap();
- public AnimationManager(Anticheat plugin)
+ public AnimationManager()
{
- this.plugin = plugin;
+
}
public void logAnimation(final Player player)
@@ -21,13 +20,13 @@ public class AnimationManager {
public boolean swungArm(Player player)
{
- if(animations.get(player) == null || animations.get(player) == false)
+ if(animations.get(player) == null)
{
return false;
}
else
{
- return true;
+ return animations.get(player);
}
}
diff --git a/src/main/java/net/h31ix/anticheat/manage/BlockManager.java b/src/main/java/net/h31ix/anticheat/manage/BlockManager.java
index f79deee..e5c394a 100644
--- a/src/main/java/net/h31ix/anticheat/manage/BlockManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/BlockManager.java
@@ -3,15 +3,13 @@ package net.h31ix.anticheat.manage;
import java.util.HashMap;
import java.util.Map;
import net.h31ix.anticheat.Anticheat;
-import org.bukkit.Server;
import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitScheduler;
public class BlockManager
{
- public Map place = new HashMap();
- public Map broke = new HashMap();
- Anticheat plugin;
+ private Map place = new HashMap();
+ private Map broke = new HashMap();
+ private Anticheat plugin;
public BlockManager(Anticheat plugin)
{
@@ -26,7 +24,7 @@ public class BlockManager
@Override
public void run()
{
- place.put(player, Boolean.valueOf(false));
+ place.put(player, false);
}
}, 1/2L);
}
@@ -39,32 +37,32 @@ public class BlockManager
@Override
public void run()
{
- broke.put(player, Boolean.valueOf(false));
+ broke.put(player, false);
}
}, 2L);
}
public boolean justBroke(Player player)
{
- if(broke.get(player) == null || broke.get(player) == false)
+ if(broke.get(player) == null)
{
return false;
}
else
{
- return true;
+ return broke.get(player);
}
}
public boolean justPlaced(Player player)
{
- if(place.get(player) == null || place.get(player) == false)
+ if(place.get(player) == null)
{
return false;
}
else
{
- return true;
+ return place.get(player);
}
}
}
\ No newline at end of file
diff --git a/src/main/java/net/h31ix/anticheat/manage/BowManager.java b/src/main/java/net/h31ix/anticheat/manage/BowManager.java
index 231b05a..bdd4871 100644
--- a/src/main/java/net/h31ix/anticheat/manage/BowManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/BowManager.java
@@ -6,9 +6,9 @@ import net.h31ix.anticheat.Anticheat;
import org.bukkit.entity.Player;
public class BowManager {
- public Map shot = new HashMap();
- public Map wind = new HashMap();
- Anticheat plugin;
+ private Map shot = new HashMap();
+ private Map wind = new HashMap();
+ private Anticheat plugin;
public BowManager(Anticheat plugin)
{
@@ -44,13 +44,13 @@ public class BowManager {
public boolean hasShot(Player player)
{
//If the player has shot in the last .5 seconds
- if(shot.get(player) == null || shot.get(player) == false)
+ if(shot.get(player) == null)
{
return false;
}
else
{
- return true;
+ return shot.get(player);
}
}
diff --git a/src/main/java/net/h31ix/anticheat/manage/ChatManager.java b/src/main/java/net/h31ix/anticheat/manage/ChatManager.java
index 470a1fd..b6ddbbc 100644
--- a/src/main/java/net/h31ix/anticheat/manage/ChatManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/ChatManager.java
@@ -7,17 +7,19 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class ChatManager {
- Anticheat plugin;
- ChatColor red = ChatColor.RED;
+ private Anticheat plugin;
+ private static final ChatColor red = ChatColor.RED;
+ private Map chatLevel = new HashMap();
+ private Map kicks = new HashMap();
+ private static final int CHAT_WARN_LEVEL = 7;
+ private static final int CHAT_KICK_LEVEL = 10;
+ private static final int CHAT_BAN_LEVEL = 3;
public ChatManager(Anticheat plugin)
{
this.plugin = plugin;
}
- private Map chatLevel = new HashMap();
- private Map kicks = new HashMap();
-
public void addChat(final Player player)
{
if(chatLevel.get(player) == null || chatLevel.get(player) == 0)
@@ -25,6 +27,7 @@ public class ChatManager {
chatLevel.put(player, 1);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
{
+ @Override
public void run()
{
clear(player);
@@ -46,11 +49,11 @@ public class ChatManager {
public void check(Player player, int amount)
{
- if(amount >= 7)
+ if(amount >= CHAT_WARN_LEVEL)
{
player.sendMessage(red+"Please stop flooding the server!");
}
- if (amount >= 10)
+ if (amount >= CHAT_KICK_LEVEL)
{
int kick = 0;
if(kicks.get(player) == null || kicks.get(player) == 0)
@@ -64,7 +67,7 @@ public class ChatManager {
kicks.put(player, kick);
}
- if(kicks.get(player) <=3)
+ if(kicks.get(player) <= CHAT_BAN_LEVEL)
{
player.kickPlayer(red+"Spamming, kick "+kick+"/3");
plugin.getServer().broadcastMessage(red+player.getName()+" was kicked for spamming.");
diff --git a/src/main/java/net/h31ix/anticheat/manage/ExemptManager.java b/src/main/java/net/h31ix/anticheat/manage/ExemptManager.java
index 69cf24d..0a9ddc5 100644
--- a/src/main/java/net/h31ix/anticheat/manage/ExemptManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/ExemptManager.java
@@ -6,9 +6,9 @@ import net.h31ix.anticheat.Anticheat;
import org.bukkit.entity.Player;
public class ExemptManager {
- public Map enter = new HashMap();
- public Map hit = new HashMap();
- Anticheat plugin;
+ private Map enter = new HashMap();
+ private Map hit = new HashMap();
+ private Anticheat plugin;
public ExemptManager(Anticheat plugin)
{
@@ -31,13 +31,13 @@ public class ExemptManager {
public boolean isEntering(Player player)
{
- if(enter.get(player) == null || enter.get(player) == false)
+ if(enter.get(player) == null)
{
return false;
}
else
{
- return true;
+ return enter.get(player);
}
}
@@ -56,13 +56,13 @@ public class ExemptManager {
public boolean isHit(Player player)
{
- if(hit.get(player) == null || hit.get(player) == false)
+ if(hit.get(player) == null)
{
return false;
}
else
{
- return true;
+ return hit.get(player);
}
}
}
diff --git a/src/main/java/net/h31ix/anticheat/manage/FlyManager.java b/src/main/java/net/h31ix/anticheat/manage/FlyManager.java
index 480e79b..1501c4f 100644
--- a/src/main/java/net/h31ix/anticheat/manage/FlyManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/FlyManager.java
@@ -5,11 +5,12 @@ import java.util.Map;
import org.bukkit.entity.Player;
public class FlyManager {
- public Map y = new HashMap();
- public Map yvl = new HashMap();
+ private Map yvl = new HashMap();
+ private static final int FLY_LIMIT = 4;
public FlyManager()
{
+
}
public boolean checkFly(Player player)
@@ -24,7 +25,7 @@ public class FlyManager {
{
yvl.put(player,yvl.get(player)+1);
}
- if(yvl.get(player) >= 4)
+ if(yvl.get(player) >= FLY_LIMIT)
{
yvl.put(player,1);
return true;
diff --git a/src/main/java/net/h31ix/anticheat/manage/FoodManager.java b/src/main/java/net/h31ix/anticheat/manage/FoodManager.java
index 12cf429..0c783b9 100644
--- a/src/main/java/net/h31ix/anticheat/manage/FoodManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/FoodManager.java
@@ -6,8 +6,8 @@ import net.h31ix.anticheat.Anticheat;
import org.bukkit.entity.Player;
public class FoodManager {
- public Map start = new HashMap();
- Anticheat plugin;
+ private Map start = new HashMap();
+ private Anticheat plugin;
public FoodManager(Anticheat plugin)
{
@@ -29,13 +29,13 @@ public class FoodManager {
public boolean justStarted(Player player)
{
- if(start.get(player) == null || start.get(player) == false)
+ if(start.get(player) == null)
{
return false;
}
else
{
- return true;
+ return start.get(player);
}
}
}
diff --git a/src/main/java/net/h31ix/anticheat/manage/HealthManager.java b/src/main/java/net/h31ix/anticheat/manage/HealthManager.java
index 1ffc798..6f71c40 100644
--- a/src/main/java/net/h31ix/anticheat/manage/HealthManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/HealthManager.java
@@ -6,12 +6,11 @@ import net.h31ix.anticheat.Anticheat;
import org.bukkit.entity.Player;
public class HealthManager {
- Anticheat plugin;
-
- public Map fall = new HashMap();
- public Map healed = new HashMap();
- public Map health = new HashMap();
- public Map fallvl = new HashMap();
+ private Anticheat plugin;
+ private Map fall = new HashMap();
+ private Map healed = new HashMap();
+ private Map health = new HashMap();
+ private Map fallvl = new HashMap();
public HealthManager(Anticheat plugin)
{
diff --git a/src/main/java/net/h31ix/anticheat/manage/ItemManager.java b/src/main/java/net/h31ix/anticheat/manage/ItemManager.java
index 4d06530..0c7e4e9 100644
--- a/src/main/java/net/h31ix/anticheat/manage/ItemManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/ItemManager.java
@@ -6,8 +6,8 @@ import net.h31ix.anticheat.Anticheat;
import org.bukkit.entity.Player;
public class ItemManager {
- public Map drop = new HashMap();
- Anticheat plugin;
+ private Map drop = new HashMap();
+ private Anticheat plugin;
public ItemManager(Anticheat plugin)
{
diff --git a/src/main/java/net/h31ix/anticheat/manage/LoginManager.java b/src/main/java/net/h31ix/anticheat/manage/LoginManager.java
index 8c814bd..1f591b7 100644
--- a/src/main/java/net/h31ix/anticheat/manage/LoginManager.java
+++ b/src/main/java/net/h31ix/anticheat/manage/LoginManager.java
@@ -3,8 +3,8 @@ package net.h31ix.anticheat.manage;
import net.h31ix.anticheat.Anticheat;
public class LoginManager {
- Anticheat plugin;
- public boolean join;
+ private Anticheat plugin;
+ private boolean join;
public LoginManager(Anticheat plugin)
{
diff --git a/src/main/java/net/h31ix/anticheat/xray/XRayListener.java b/src/main/java/net/h31ix/anticheat/xray/XRayListener.java
index 4a355bf..f63d764 100644
--- a/src/main/java/net/h31ix/anticheat/xray/XRayListener.java
+++ b/src/main/java/net/h31ix/anticheat/xray/XRayListener.java
@@ -1,6 +1,7 @@
package net.h31ix.anticheat.xray;
import net.h31ix.anticheat.Anticheat;
+import net.h31ix.anticheat.Configuration;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -8,53 +9,58 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
public class XRayListener implements Listener {
- XRayTracker tracker;
+ private XRayTracker tracker;
+ private Configuration config;
public XRayListener(Anticheat plugin)
{
- tracker = plugin.xtracker;
+ tracker = plugin.getXRayTracker();
+ config = plugin.getConfiguration();
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
- Player player = event.getPlayer();
- if(!player.hasPermission("anticheat.xray"))
+ if(config.logXRay())
{
- Material m = event.getBlock().getType();
- if(m == Material.DIAMOND_ORE)
+ Player player = event.getPlayer();
+ if(!player.hasPermission("anticheat.xray"))
{
- tracker.addDiamond(player);
+ 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);
}
- 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
index 4ad2292..21384fe 100644
--- a/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java
+++ b/src/main/java/net/h31ix/anticheat/xray/XRayTracker.java
@@ -7,19 +7,21 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class XRayTracker {
- public Map diamond = new HashMap();
- public Map gold = new HashMap();
- public Map iron = new HashMap();
- public Map coal = new HashMap();
- public Map lapis = new HashMap();
- public Map redstone = new HashMap();
- public Map block = new HashMap();
- public Map totalblock = new HashMap();
- ChatColor green = ChatColor.GREEN;
- ChatColor white = ChatColor.WHITE;
- ChatColor red = ChatColor.RED;
- ChatColor yellow = ChatColor.YELLOW;
- ChatColor gray = ChatColor.GRAY;
+ 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 MIN_BLOCK_COUNT = 150;
public XRayTracker()
{
@@ -28,7 +30,7 @@ public class XRayTracker {
public void sendStats(CommandSender cs, Player player)
{
- double t = 1;
+ int t = 1;
double d = 0;
double g = 0;
double i = 0;
@@ -42,71 +44,72 @@ public class XRayTracker {
}
if(diamond.get(player) != null)
{
- d = (diamond.get(player)/t)*100;
+ d = (diamond.get(player)/t)*DIVISOR;
}
if(gold.get(player) != null)
{
- g = (gold.get(player)/t)*100;
+ g = (gold.get(player)/t)*DIVISOR;
}
if(iron.get(player) != null)
{
- i = (iron.get(player)/t)*100;
+ i = (iron.get(player)/t)*DIVISOR;
}
if(coal.get(player) != null)
{
- c = (coal.get(player)/t)*100;
+ c = (coal.get(player)/t)*DIVISOR;
}
if(lapis.get(player) != null)
{
- la = (lapis.get(player)/t)*100;
+ la = (lapis.get(player)/t)*DIVISOR;
}
if(redstone.get(player) != null)
{
- r = (redstone.get(player)/t)*100;
+ r = (redstone.get(player)/t)*DIVISOR;
}
if(block.get(player) != null)
{
- b = (block.get(player)/t)*100;
+ b = (block.get(player)/t)*DIVISOR;
}
cs.sendMessage("--------------------["+green+"X-Ray Stats"+white+"]---------------------");
- ChatColor color = ChatColor.WHITE;
- if(d >= b/3 && t > 50)
+ ChatColor color = white;
+ if(d >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
{
- color = ChatColor.RED;
+ color = red;
}
+ cs.sendMessage(gray+"Player: "+white+player.getName());
cs.sendMessage(gray+"Total blocks broken: "+white+t);
- cs.sendMessage(gray+"Percent diamond ore: "+color+round(d,1)+"%");
- color = ChatColor.WHITE;
- if(g >= b/3 && t > 50)
+ cs.sendMessage(gray+"Percent diamond ore: "+color+round(d)+"%");
+ color = white;
+ if(g >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
{
- color = ChatColor.RED;
+ color = red;
}
- cs.sendMessage(gray+"Percent gold ore: "+color+round(g,1)+"%");
- color = ChatColor.WHITE;
- if(i >= b/3 && t > 50)
+ cs.sendMessage(gray+"Percent gold ore: "+color+round(g)+"%");
+ color = white;
+ if(i >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
{
- color = ChatColor.RED;
+ color = red;
}
- cs.sendMessage(gray+"Percent iron ore: "+color+round(i,1)+"%");
- color = ChatColor.WHITE;
- if(c >= b/3 && t > 50)
+ cs.sendMessage(gray+"Percent iron ore: "+color+round(i)+"%");
+ color = white;
+ if(c >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
{
- color = ChatColor.RED;
+ color = red;
}
- cs.sendMessage(gray+"Percent coal ore: "+color+round(c,1)+"%");
- color = ChatColor.WHITE;
- if(la >= b/3 && t > 50)
+ cs.sendMessage(gray+"Percent coal ore: "+color+round(c)+"%");
+ color = white;
+ if(la >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
{
- color = ChatColor.RED;
+ color = red;
}
- cs.sendMessage(gray+"Percent lapis ore: "+color+round(la,1)+"%");
- color = ChatColor.WHITE;
- if(r >= b/3 && t > 50)
+ cs.sendMessage(gray+"Percent lapis ore: "+color+round(la)+"%");
+ color = white;
+ if(r >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
{
- color = ChatColor.RED;
+ color = red;
}
- cs.sendMessage(gray+"Percent redstone ore: "+color+round(r,1)+"%");
- cs.sendMessage(gray+"Percent all other blocks: "+white+round(b,1)+"%");
+ cs.sendMessage(gray+"Percent redstone ore: "+color+round(r)+"%");
+ cs.sendMessage(gray+"Percent all other blocks: "+white+round(b)+"%");
cs.sendMessage("-----------------------------------------------------");
}
@@ -163,11 +166,23 @@ public class XRayTracker {
}
}
- private float round(double Rval, int Rpl)
- {
- float p = (float)Math.pow(10,Rpl);
- Rval = Rval * p;
- float tmp = Math.round(Rval);
- return (float)tmp/p;
- }
+ private float round(double num)
+ {
+ float p = (float)Math.pow(10,1);
+ num*=p;
+ float tmp = Math.round(num);
+ return (float)tmp/p;
+ }
+
+ public void reset(Player player)
+ {
+ totalblock.put(player,1);
+ diamond.put(player,0);
+ iron.put(player,0);
+ gold.put(player,0);
+ coal.put(player,0);
+ redstone.put(player,0);
+ lapis.put(player,0);
+ totalblock.put(player,0);
+ }
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index c8d447d..efd5828 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -3,6 +3,9 @@
Logging:
Log to console: false
+
+XRay:
+ Log xray stats: true
Events:
#Valid events = NONE,WARN,KICK,BAN