From 6c2c0ddb7c28a1c2bfda7e95e19f119270476bcf Mon Sep 17 00:00:00 2001 From: h31ix Date: Sun, 30 Sep 2012 19:51:47 -0400 Subject: [PATCH] Basics of the calibration system I have in mind. Will work on this, but it's going to take a while. --- .../net/h31ix/anticheat/CommandHandler.java | 60 ++++-- .../net/h31ix/anticheat/util/Calibrator.java | 187 ++++++++++++++++++ .../net/h31ix/anticheat/util/Permission.java | 1 + src/main/resources/plugin.yml | 7 +- 4 files changed, 236 insertions(+), 19 deletions(-) create mode 100644 src/main/java/net/h31ix/anticheat/util/Calibrator.java diff --git a/src/main/java/net/h31ix/anticheat/CommandHandler.java b/src/main/java/net/h31ix/anticheat/CommandHandler.java index 8323343..3741be0 100644 --- a/src/main/java/net/h31ix/anticheat/CommandHandler.java +++ b/src/main/java/net/h31ix/anticheat/CommandHandler.java @@ -20,6 +20,7 @@ package net.h31ix.anticheat; import java.util.ArrayList; import java.util.List; +import net.h31ix.anticheat.util.Calibrator; import net.h31ix.anticheat.manage.CheckType; import net.h31ix.anticheat.manage.User; import net.h31ix.anticheat.manage.UserManager; @@ -310,6 +311,27 @@ public class CommandHandler implements CommandExecutor } } + public void handleCalibrate(CommandSender cs) + { + if(cs instanceof Player) + { + if (Permission.SYSTEM_CALIBRATE.get(cs)) + { + Calibrator c = new Calibrator((Player)cs); + SERVER.getPluginManager().registerEvents(c, Anticheat.getPlugin()); + c.calibrate(); + } + else + { + cs.sendMessage(PERMISSIONS_ERROR); + } + } + else + { + cs.sendMessage(RED + "Sorry, but you cannot calibrate from console."); + } + } + public void handleReport(CommandSender cs, String[] args) { if (Permission.SYSTEM_REPORT.get(cs)) @@ -319,7 +341,7 @@ public class CommandHandler implements CommandExecutor { String group = args[1]; if(group.equalsIgnoreCase("low")) - { + { int num = getReportPageNum(args); if (num > 0) { @@ -328,7 +350,7 @@ public class CommandHandler implements CommandExecutor else { cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]); - } + } } else if(group.equalsIgnoreCase("medium")) { @@ -340,8 +362,8 @@ public class CommandHandler implements CommandExecutor else { cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]); - } - } + } + } if(group.equalsIgnoreCase("high")) { int num = getReportPageNum(args); @@ -352,7 +374,7 @@ public class CommandHandler implements CommandExecutor else { cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]); - } + } } } } @@ -361,7 +383,7 @@ public class CommandHandler implements CommandExecutor cs.sendMessage(PERMISSIONS_ERROR); } } - + public int getReportPageNum(String [] args) { if (args.length == 2) @@ -375,12 +397,12 @@ public class CommandHandler implements CommandExecutor else { return -1; - } + } } - + public void sendReport(CommandSender cs, List players, String group, ChatColor color, int page) { - int pages = (int)Math.ceil(((float)players.size())/7); + int pages = (int)Math.ceil(((float)players.size())/7); if(page <= pages && page > 0) { cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/"+pages+"]" + WHITE + "]---------------------"); @@ -401,8 +423,8 @@ public class CommandHandler implements CommandExecutor if(pages == 0) { cs.sendMessage("--------------------[" + GREEN + "REPORT[1/1]" + WHITE + "]---------------------"); - cs.sendMessage(GRAY + "Group: " + color + group); - cs.sendMessage(GRAY + "There are no users in this group."); + cs.sendMessage(GRAY + "Group: " + color + group); + cs.sendMessage(GRAY + "There are no users in this group."); cs.sendMessage("-----------------------------------------------------"); } else @@ -410,7 +432,7 @@ public class CommandHandler implements CommandExecutor cs.sendMessage(RED+"Page not found. Requested "+WHITE+page+RED+", Max "+WHITE+pages); } } - } + } public void handlePlayerReport(CommandSender cs, String[] args) { @@ -477,7 +499,7 @@ public class CommandHandler implements CommandExecutor else if (level >= config.highThreshold()) { levelString = RED + "High"; - } + } if(page <= pages && page > 0) { cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/"+pages+"]" + WHITE + "]---------------------"); @@ -509,8 +531,8 @@ public class CommandHandler implements CommandExecutor { cs.sendMessage("--------------------[" + GREEN + "REPORT[1/1]" + WHITE + "]---------------------"); cs.sendMessage(GRAY + "Player: " + WHITE + name); - cs.sendMessage(GRAY + "Level: " + levelString); - cs.sendMessage(GRAY + "This user has not failed any checks."); + cs.sendMessage(GRAY + "Level: " + levelString); + cs.sendMessage(GRAY + "This user has not failed any checks."); cs.sendMessage("-----------------------------------------------------"); } else @@ -576,7 +598,7 @@ public class CommandHandler implements CommandExecutor } else { - handlePlayerReport(cs, args); + handlePlayerReport(cs, args); } } else @@ -602,7 +624,7 @@ public class CommandHandler implements CommandExecutor cs.sendMessage(ChatColor.GREEN+"To see the report of an AntiCheat group, type it's name, like so:"); cs.sendMessage(ChatColor.WHITE+"/anticheat report [low/medium/high]"); cs.sendMessage(ChatColor.GRAY+" - This will allow you to see which players are good, and which could be hacking."); - } + } else if (args[0].equalsIgnoreCase("reload")) { handleReload(cs); @@ -611,6 +633,10 @@ public class CommandHandler implements CommandExecutor { handleUpdate(cs); } + else if (args[0].equalsIgnoreCase("calibrate")) + { + handleCalibrate(cs); + } else { cs.sendMessage(RED + "Unrecognized command."); diff --git a/src/main/java/net/h31ix/anticheat/util/Calibrator.java b/src/main/java/net/h31ix/anticheat/util/Calibrator.java new file mode 100644 index 0000000..ef3db0e --- /dev/null +++ b/src/main/java/net/h31ix/anticheat/util/Calibrator.java @@ -0,0 +1,187 @@ +package net.h31ix.anticheat.util; + +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Calibrator implements Listener +{ + private final Player player; + private int step = 0; + private static final int TOTAL = 30; + private long lastLong; + private int lastInt; + private int lastDouble; + private long [] longs = new long[10]; + private double [] doubles = new double[10]; + private int [] ints = new int[10]; + + // Value-specific calculations + private long punchAvg; + private double blockBreakMax; + private double blockPlaceMax; + + public Calibrator(Player player) + { + this.player = player; + player.sendMessage(ChatColor.GREEN+"----You have entered calibration mode.----"); + // Wait for listener to be registered and calibrate method called. + } + + public void calibrate() + { + switch(step) + { + case 0: + sendStep(); + player.sendMessage("Spam the left mouse button as fast as possible."); + break; + case 2: + player.setGameMode(GameMode.CREATIVE); + player.sendMessage("Break blocks from as far away as you can possibly get from them."); + break; + case 3: + player.sendMessage("Place blocks from as far away as you can possibly get from them."); + break; + } + + } + + private int getLongCount() + { + int fill = 0; + for(long l : longs) + { + if(l != 0) + { + fill++; + } + } + return fill; + } + + private int getDoubleCount() + { + int fill = 0; + for(double d : doubles) + { + if(d != 0) + { + fill++; + } + } + return fill; + } + + private void clear() + { + for(int i =0;i max) + { + max = d; + } + } + clear(); + player.sendMessage(ChatColor.AQUA+"Done. Maximum calculated at "+ChatColor.WHITE+max); + sendStep(); + calibrate(); + } + } + + + + // Begin event listeners + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) + { + if(step == 1) + { + getAvgLong(punchAvg); + } + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + if(step == 2) + { + double lengthX = Math.abs(event.getBlock().getX()-event.getPlayer().getLocation().getX()); + double lengthZ = Math.abs(event.getBlock().getZ()-event.getPlayer().getLocation().getZ()); + getMaxDouble(blockBreakMax, lengthX >= lengthZ ? lengthX : lengthZ); + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) + { + if(step == 3) + { + double lengthX = Math.abs(event.getBlock().getX()-event.getPlayer().getLocation().getX()); + double lengthZ = Math.abs(event.getBlock().getZ()-event.getPlayer().getLocation().getZ()); + getMaxDouble(blockPlaceMax, lengthX >= lengthZ ? lengthX : lengthZ); + } + } +} diff --git a/src/main/java/net/h31ix/anticheat/util/Permission.java b/src/main/java/net/h31ix/anticheat/util/Permission.java index 604cc1c..462b6ea 100644 --- a/src/main/java/net/h31ix/anticheat/util/Permission.java +++ b/src/main/java/net/h31ix/anticheat/util/Permission.java @@ -57,6 +57,7 @@ public enum Permission SYSTEM_UPDATE, SYSTEM_REPORT, SYSTEM_ALERT, + SYSTEM_CALIBRATE, SYSTEM_RELOAD; public boolean get(CommandSender cs) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7d5b414..47909a2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -23,6 +23,8 @@ permissions: description: Spy system access anticheat.system.xray: description: XRay info access + anticheat.system.calibrate: + description: Calibrate info access anticheat.mod: description: Mod helper perm children: @@ -47,6 +49,7 @@ permissions: anticheat.system.reload: true anticheat.system.reset: true anticheat.system.update: true + anticheat.system.calibrate: true anticheat.check.zombe.fly: description: Allow players to use zombe flymod default: false @@ -115,10 +118,10 @@ permissions: default: false anticheat.check.visual: description: Allow players to interact with objects out of their view - default: false + default: false anticheat.check.vclip: description: Allow players to become slimeballs and clip down through blocks - default: false + default: false anticheat.check.exempt: description: Total exemption from checks default: false