Make API logging / usage more sane.

This commit is contained in:
gravitylow committed 2014-01-19 13:06:25 -05:00
1 parent aed44648eb
commit 732ac8c78e
2 files changed
+54 -14

No files matched your search

@@ -23,14 +23,17 @@ import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
import net.gravitydevelopment.anticheat.manage.CheckManager; import net.gravitydevelopment.anticheat.manage.CheckManager;
import net.gravitydevelopment.anticheat.check.CheckType; import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.manage.UserManager; import net.gravitydevelopment.anticheat.manage.UserManager;
import net.gravitydevelopment.anticheat.util.Group;
import net.gravitydevelopment.anticheat.xray.XRayTracker; import net.gravitydevelopment.anticheat.xray.XRayTracker;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
/** /**
* Developer's interface for all things AntiCheat. * Developer's interface for all things AntiCheat.
*/ */
public class AnticheatAPI { public class AntiCheatAPI {
private static CheckManager chk = AntiCheat.getManager().getCheckManager(); private static CheckManager chk = AntiCheat.getManager().getCheckManager();
private static UserManager umr = AntiCheat.getManager().getUserManager(); private static UserManager umr = AntiCheat.getManager().getUserManager();
private static XRayTracker xtracker = AntiCheat.getManager().getXRayTracker(); private static XRayTracker xtracker = AntiCheat.getManager().getXRayTracker();
@@ -43,7 +46,7 @@ public class AnticheatAPI {
* @param type Check to start watching for * @param type Check to start watching for
*/ */
public static void activateCheck(CheckType type) { 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 * @param type Check to stop watching for
*/ */
public static void deactivateCheck(CheckType type) { 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 * @param type Check to stop watching for
*/ */
public static void exemptPlayer(Player player, CheckType type) { 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 * @param type Check to start watching for
*/ */
public static void unexemptPlayer(Player player, CheckType type) { 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 * @param player Player to check
* @return player's hack level * @return player's hack level
* @deprecated see {@link #getGroup(org.bukkit.entity.Player)}
*/ */
@Deprecated
public static int getLevel(Player player) { public static int getLevel(Player player) {
return umr.safeGetLevel(player.getName()); 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 player Player to set
* @param level Group to set to * @param level Group to set to
* @deprecated see {@link #resetPlayer(org.bukkit.entity.Player)}
*/ */
@Deprecated
public static void setLevel(Player player, int level) { public static void setLevel(Player player, int level) {
umr.safeSetLevel(player.getName(), 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 // XrayTracker API
/** /**
@@ -153,4 +189,8 @@ public class AnticheatAPI {
public static AntiCheatManager getManager() { public static AntiCheatManager getManager() {
return AntiCheat.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 * @param type The CheckType to enable
*/ */
public void activateCheck(CheckType type) { public void activateCheck(CheckType type, String className) {
if (isActive(type)) { 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); checkIgnoreList.remove(type);
} }
} }
@@ -64,9 +64,9 @@ public class CheckManager {
* *
* @param type The CheckType to disable * @param type The CheckType to disable
*/ */
public void deactivateCheck(CheckType type) { public void deactivateCheck(CheckType type, String className) {
if (!isActive(type)) { 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); checkIgnoreList.add(type);
disabled++; disabled++;
} }
@@ -88,12 +88,12 @@ public class CheckManager {
* @param player The player * @param player The player
* @param type The check * @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 (!isExempt(player, type)) {
if (!exemptList.containsKey(player.getName())) { if (!exemptList.containsKey(player.getName())) {
exemptList.put(player.getName(), new ArrayList<CheckType>()); 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); exemptList.get(player.getName()).add(type);
exempt++; exempt++;
} }
@@ -105,9 +105,9 @@ public class CheckManager {
* @param player The player * @param player The player
* @param type The check * @param type The check
*/ */
public void unexemptPlayer(Player player, CheckType type) { public void unexemptPlayer(Player player, CheckType type, String className) {
if (isExempt(player, type)) { 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); exemptList.get(player.getName()).remove(type);
} }
} }