mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Basics of the calibration system I have in mind. Will work on this, but it's going to take a while.
This commit is contained in:
1 parent
b5eaf0bfe8
commit
6c2c0ddb7c
4 files changed
+236
-19
No files matched your search
@@ -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<String> 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.");
|
||||
|
||||
@@ -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<longs.length;i++)
|
||||
{
|
||||
longs[i] = 0;
|
||||
}
|
||||
for(int i =0;i<doubles.length;i++)
|
||||
{
|
||||
doubles[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendStep()
|
||||
{
|
||||
step++;
|
||||
player.sendMessage(ChatColor.GREEN+"Step "+step+"/"+TOTAL);
|
||||
}
|
||||
|
||||
private void getAvgLong(long avg)
|
||||
{
|
||||
int count = getLongCount();
|
||||
if(count < 10)
|
||||
{
|
||||
if(lastLong == 0)
|
||||
{
|
||||
lastLong = System.currentTimeMillis();
|
||||
}
|
||||
else
|
||||
{
|
||||
longs[count] = System.currentTimeMillis()-lastLong;
|
||||
lastLong = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(long l : longs)
|
||||
{
|
||||
avg+=l;
|
||||
}
|
||||
lastLong = 0;
|
||||
clear();
|
||||
avg/=10;
|
||||
player.sendMessage(ChatColor.AQUA+"Done. Average calculated at "+ChatColor.WHITE+avg);
|
||||
sendStep();
|
||||
calibrate();
|
||||
}
|
||||
}
|
||||
|
||||
private void getMaxDouble(double max, double length)
|
||||
{
|
||||
int count = getDoubleCount();
|
||||
System.out.println(count);
|
||||
if(count < 10)
|
||||
{
|
||||
doubles[count] = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(double d : doubles)
|
||||
{
|
||||
if(max == 0 || d > 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ public enum Permission
|
||||
SYSTEM_UPDATE,
|
||||
SYSTEM_REPORT,
|
||||
SYSTEM_ALERT,
|
||||
SYSTEM_CALIBRATE,
|
||||
SYSTEM_RELOAD;
|
||||
|
||||
public boolean get(CommandSender cs)
|
||||
|
||||
Reference in new issue
Block a user