mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
A bit of cleaning up and explaining, moved javadocs to AnticheatAPI.java
This commit is contained in:
1 parent
51557c20a6
commit
a50a57353a
5 files changed
+114
-65
No files matched your search
@@ -27,46 +27,105 @@ import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.PlayerManager;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Developer's interface for all things AntiCheat.
|
||||
*/
|
||||
|
||||
|
||||
public class AnticheatAPI
|
||||
{
|
||||
private static CheckManager chk = Anticheat.getManager().getCheckManager();
|
||||
private static PlayerManager pmr = Anticheat.getManager().getPlayerManager();
|
||||
private static XRayTracker xtracker = Anticheat.getManager().getXRayTracker();
|
||||
|
||||
//CheckManager API.
|
||||
|
||||
|
||||
//CheckManager API
|
||||
|
||||
/**
|
||||
* Start running a certain check
|
||||
*
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
public static void activateCheck(CheckType type)
|
||||
{
|
||||
chk.activateCheck(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop running a certain check
|
||||
*
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void deactivateCheck(CheckType type)
|
||||
{
|
||||
chk.deactivateCheck(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 static boolean isActive(CheckType type)
|
||||
{
|
||||
return chk.isActive(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow a player to skip a certain check
|
||||
*
|
||||
* @param player Player to stop watching
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void exemptPlayer(Player player, CheckType type)
|
||||
{
|
||||
chk.exemptPlayer(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 static void unexemptPlayer(Player player, CheckType type)
|
||||
{
|
||||
chk.unexemptPlayer(player, 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 static boolean isExempt(Player player, CheckType type)
|
||||
{
|
||||
return chk.isExempt(player, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 chk.willCheck(player, type);
|
||||
}
|
||||
|
||||
//PlayerManager API
|
||||
|
||||
/**
|
||||
* Get a player's integer hack level (0-19 = Low, 20-49 = Medium, 50-60 = High)
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return player's hack level
|
||||
*/
|
||||
public static int getLevel(Player player)
|
||||
{
|
||||
if(!pmr.hasLevel(player))
|
||||
@@ -76,13 +135,25 @@ public class AnticheatAPI
|
||||
return pmr.getLevel(player);
|
||||
}
|
||||
|
||||
public static void setLevel(Player player, int x)
|
||||
/**
|
||||
* Set a player's hack level (Min = 0, Max = 60)
|
||||
*
|
||||
* @param player Player to set
|
||||
* @param level Level to set to
|
||||
*/
|
||||
public static void setLevel(Player player, int level)
|
||||
{
|
||||
pmr.setLevel(player, x);
|
||||
pmr.setLevel(player, level);
|
||||
}
|
||||
|
||||
//XrayTracker API
|
||||
|
||||
/**
|
||||
* Find out if a player is detected as using xray hacks (on any ore)
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player has any xray anomalies.
|
||||
*/
|
||||
public static boolean isXrayer(Player player)
|
||||
{
|
||||
String name = player.getName();
|
||||
@@ -94,7 +165,12 @@ public class AnticheatAPI
|
||||
}
|
||||
|
||||
//Advanced Users Only API.
|
||||
|
||||
|
||||
/**
|
||||
* Get access to all the other managers, advanced users ONLY
|
||||
*
|
||||
* @return the AntiCheat Manager
|
||||
*/
|
||||
public static AnticheatManager getManager()
|
||||
{
|
||||
return Anticheat.getManager();
|
||||
|
||||
@@ -25,6 +25,11 @@ import net.h31ix.anticheat.Anticheat;
|
||||
import net.h31ix.anticheat.Configuration;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The internal hub for all managers.
|
||||
*/
|
||||
|
||||
public class AnticheatManager
|
||||
{
|
||||
private Anticheat plugin = null;
|
||||
|
||||
@@ -98,7 +98,6 @@ public class Backend
|
||||
private Map<String,Integer> fastBreakViolation = new HashMap<String,Integer>();
|
||||
private Map<String,Integer> blocksBroken = new HashMap<String,Integer>();
|
||||
private Map<String,Long> lastBlockBroken = new HashMap<String,Long>();
|
||||
private Map<String,Integer> fastPlaceViolation = new HashMap<String,Integer>();
|
||||
private Map<String,Long> lastBlockPlaced = new HashMap<String,Long>();
|
||||
private Map<String,Long> lastBlockPlaceTime = new HashMap<String,Long>();
|
||||
|
||||
@@ -336,20 +335,26 @@ public class Backend
|
||||
String name = player.getName();
|
||||
if(!lastBlockPlaceTime.containsKey(name))
|
||||
{
|
||||
//Make sure we have the last record for this player
|
||||
lastBlockPlaceTime.put(name, Long.parseLong("0"));
|
||||
}
|
||||
else if(lastBlockPlaced.containsKey(name))
|
||||
{
|
||||
//If we do, continue on to math
|
||||
long last = lastBlockPlaced.get(name);
|
||||
long lastTime = lastBlockPlaceTime.get(name);
|
||||
//Check if the time between the last block they placed and this block is high enough
|
||||
//If it is, also check if their last place was in violation of this limit as well
|
||||
if(last != 0 && (time-last) < FASTPLACE_TIMEMAX && lastTime != 0 && lastTime < FASTPLACE_TIMEMAX)
|
||||
{
|
||||
//It was a fastplace
|
||||
lastBlockPlaceTime.put(name, (time-last));
|
||||
lastBlockPlaced.put(name, time);
|
||||
return true;
|
||||
}
|
||||
lastBlockPlaceTime.put(name, (time-last));
|
||||
}
|
||||
//It was not fastplacing (at least not yet), store the data and wait for the next check.
|
||||
lastBlockPlaced.put(name, time);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,80 +35,40 @@ public class CheckManager
|
||||
private static List<CheckType> checkIgnoreList = new ArrayList<CheckType>();
|
||||
private static Multimap<Player,CheckType> exemptList = ArrayListMultimap.create();
|
||||
|
||||
/**
|
||||
* Initialize the class.
|
||||
*
|
||||
* @param instance The AntiCheat Manager
|
||||
*/
|
||||
public CheckManager(AnticheatManager instance)
|
||||
{
|
||||
manager = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start running a certain check
|
||||
*
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
|
||||
public void activateCheck(CheckType type)
|
||||
{
|
||||
manager.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)
|
||||
{
|
||||
manager.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)
|
||||
{
|
||||
manager.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)
|
||||
{
|
||||
manager.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);
|
||||
@@ -118,14 +78,7 @@ public class CheckManager
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -26,7 +26,14 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerManager {
|
||||
/**
|
||||
* <p>
|
||||
* The manager that AntiCheat will use to monitor player's hack levels and to execute events that the admin has set
|
||||
*/
|
||||
|
||||
public class PlayerManager
|
||||
{
|
||||
|
||||
private static Map<String,Integer> level = new HashMap<String,Integer>();
|
||||
private static Configuration config = null;
|
||||
private static final int MED_THRESHOLD = 20;
|
||||
@@ -73,7 +80,7 @@ public class PlayerManager {
|
||||
reactHigh(player);
|
||||
level.put(player.getName(), MED_THRESHOLD+5);
|
||||
}
|
||||
else if (playerLevel > HIGH_THRESHOLD)
|
||||
else if (playerLevel > 60)
|
||||
{
|
||||
level.put(player.getName(), MED_THRESHOLD+5);
|
||||
}
|
||||
@@ -105,7 +112,10 @@ public class PlayerManager {
|
||||
|
||||
public void setLevel(Player player, int x)
|
||||
{
|
||||
level.put(player.getName(), x);
|
||||
if(!(x > 60 && x < 0))
|
||||
{
|
||||
level.put(player.getName(), x);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasLevel(Player player)
|
||||
|
||||
Reference in new issue
Block a user