mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Make API logging / usage more sane.
This commit is contained in:
1 parent
aed44648eb
commit
732ac8c78e
2 files changed
+54
-14
No files matched your search
+46
-6
@@ -23,14 +23,17 @@ import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckManager;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.UserManager;
|
||||
import net.gravitydevelopment.anticheat.util.Group;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Developer's interface for all things AntiCheat.
|
||||
*/
|
||||
|
||||
public class AnticheatAPI {
|
||||
public class AntiCheatAPI {
|
||||
private static CheckManager chk = AntiCheat.getManager().getCheckManager();
|
||||
private static UserManager umr = AntiCheat.getManager().getUserManager();
|
||||
private static XRayTracker xtracker = AntiCheat.getManager().getXRayTracker();
|
||||
@@ -43,7 +46,7 @@ public class AnticheatAPI {
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
public static void activateCheck(CheckType type) {
|
||||
chk.activateCheck(type);
|
||||
chk.activateCheck(type, getCallingClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +55,7 @@ public class AnticheatAPI {
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void deactivateCheck(CheckType type) {
|
||||
chk.deactivateCheck(type);
|
||||
chk.deactivateCheck(type, getCallingClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +75,7 @@ public class AnticheatAPI {
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void exemptPlayer(Player player, CheckType type) {
|
||||
chk.exemptPlayer(player, type);
|
||||
chk.exemptPlayer(player, type, getCallingClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +85,7 @@ public class AnticheatAPI {
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
public static void unexemptPlayer(Player player, CheckType type) {
|
||||
chk.unexemptPlayer(player, type);
|
||||
chk.unexemptPlayer(player, type, getCallingClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,22 +117,55 @@ public class AnticheatAPI {
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return player's hack level
|
||||
* @deprecated see {@link #getGroup(org.bukkit.entity.Player)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getLevel(Player player) {
|
||||
return umr.safeGetLevel(player.getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a player's hack level (Min = 0, Max = 50)
|
||||
* Set a player's hack level
|
||||
*
|
||||
* @param player Player to set
|
||||
* @param level Group to set to
|
||||
* @deprecated see {@link #resetPlayer(org.bukkit.entity.Player)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void setLevel(Player player, int level) {
|
||||
umr.safeSetLevel(player.getName(), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a player's hack level to 0
|
||||
*
|
||||
* @param player Player to reset
|
||||
*/
|
||||
public static void resetPlayer(Player player) {
|
||||
umr.getUser(player.getName()).resetLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user's {@link net.gravitydevelopment.anticheat.util.Group}
|
||||
*
|
||||
* @param player Player whose group to find
|
||||
* @return The player's group
|
||||
*/
|
||||
public static Group getGroup(Player player) {
|
||||
return umr.getUser(player.getName()).getGroup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all configured Groups
|
||||
*
|
||||
* @return List of all groups
|
||||
* @see net.gravitydevelopment.anticheat.util.Group
|
||||
*/
|
||||
public static List<Group> getGroups() {
|
||||
return getManager().getConfiguration().getGroups().getGroups();
|
||||
}
|
||||
|
||||
// XrayTracker API
|
||||
|
||||
/**
|
||||
@@ -153,4 +189,8 @@ public class AnticheatAPI {
|
||||
public static AntiCheatManager getManager() {
|
||||
return AntiCheat.getManager();
|
||||
}
|
||||
|
||||
private static String getCallingClass() {
|
||||
return sun.reflect.Reflection.getCallerClass(2).getName();
|
||||
}
|
||||
}
|
||||
@@ -52,9 +52,9 @@ public class CheckManager {
|
||||
*
|
||||
* @param type The CheckType to enable
|
||||
*/
|
||||
public void activateCheck(CheckType type) {
|
||||
public void activateCheck(CheckType type, String className) {
|
||||
if (isActive(type)) {
|
||||
manager.log("The " + type.toString() + " check was activated.");
|
||||
manager.getLoggingManager().logToFile("The " + type.toString() + " check was activated by " + className + ".");
|
||||
checkIgnoreList.remove(type);
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,9 @@ public class CheckManager {
|
||||
*
|
||||
* @param type The CheckType to disable
|
||||
*/
|
||||
public void deactivateCheck(CheckType type) {
|
||||
public void deactivateCheck(CheckType type, String className) {
|
||||
if (!isActive(type)) {
|
||||
manager.log("The " + type.toString() + " check was deactivated.");
|
||||
manager.getLoggingManager().logToFile("The " + type.toString() + " check was deactivated by " + className + ".");
|
||||
checkIgnoreList.add(type);
|
||||
disabled++;
|
||||
}
|
||||
@@ -88,12 +88,12 @@ public class CheckManager {
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public void exemptPlayer(Player player, CheckType type) {
|
||||
public void exemptPlayer(Player player, CheckType type, String className) {
|
||||
if (!isExempt(player, type)) {
|
||||
if (!exemptList.containsKey(player.getName())) {
|
||||
exemptList.put(player.getName(), new ArrayList<CheckType>());
|
||||
}
|
||||
manager.log(player.getName() + " was exempted from the " + type.toString() + " check.");
|
||||
manager.getLoggingManager().logToFile(player.getName() + " was exempted from the " + type.toString() + " check by " + className + ".");
|
||||
exemptList.get(player.getName()).add(type);
|
||||
exempt++;
|
||||
}
|
||||
@@ -105,9 +105,9 @@ public class CheckManager {
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public void unexemptPlayer(Player player, CheckType type) {
|
||||
public void unexemptPlayer(Player player, CheckType type, String className) {
|
||||
if (isExempt(player, type)) {
|
||||
manager.log(player.getName() + " was re-added to the " + type.toString() + " check.");
|
||||
manager.getLoggingManager().logToFile(player.getName() + " was unexempted from the " + type.toString() + " check by " + className + ".");
|
||||
exemptList.get(player.getName()).remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user