mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Refactor logging system
This commit is contained in:
1 parent
62dcdb5d4b
commit
aed44648eb
33 files changed
+311
-217
No files matched your search
@@ -21,9 +21,9 @@ package net.gravitydevelopment.anticheat;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.event.*;
|
||||
import net.gravitydevelopment.anticheat.manage.AnticheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.PacketManager;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayListener;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
@@ -41,7 +41,7 @@ import java.util.List;
|
||||
|
||||
public class AntiCheat extends JavaPlugin {
|
||||
|
||||
private static AnticheatManager manager;
|
||||
private static AntiCheatManager manager;
|
||||
private static AntiCheat plugin;
|
||||
private static List<Listener> eventList = new ArrayList<Listener>();
|
||||
private static boolean update = false;
|
||||
@@ -57,7 +57,7 @@ public class AntiCheat extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
loadTime = System.currentTimeMillis();
|
||||
manager = new AnticheatManager(this, getLogger());
|
||||
manager = new AntiCheatManager(this, getLogger());
|
||||
eventList.add(new PlayerListener());
|
||||
eventList.add(new BlockListener());
|
||||
eventList.add(new EntityListener());
|
||||
@@ -93,7 +93,7 @@ public class AntiCheat extends JavaPlugin {
|
||||
verboseLog("Saving user levels...");
|
||||
config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers());
|
||||
|
||||
AnticheatManager.close();
|
||||
AntiCheatManager.close();
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
cleanup();
|
||||
}
|
||||
@@ -191,7 +191,7 @@ public class AntiCheat extends JavaPlugin {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static AnticheatManager getManager() {
|
||||
public static AntiCheatManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
package net.gravitydevelopment.anticheat;
|
||||
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.manage.UserManager;
|
||||
import net.gravitydevelopment.anticheat.util.*;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
@@ -52,24 +53,36 @@ public class CommandHandler implements CommandExecutor {
|
||||
|
||||
public void handleLog(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_LOG)) {
|
||||
if (args[1].equalsIgnoreCase("enable")) {
|
||||
if (!CONFIG.getConfig().logToConsole.getValue()) {
|
||||
CONFIG.getConfig().logToConsole.setValue(true);
|
||||
cs.sendMessage(GREEN + "Console logging enabled.");
|
||||
CONFIG.getConfig().reload();
|
||||
} else {
|
||||
cs.sendMessage(GREEN + "Console logging is already enabled!");
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("disable")) {
|
||||
if (CONFIG.getConfig().logToConsole.getValue()) {
|
||||
CONFIG.getConfig().logToConsole.setValue(false);
|
||||
cs.sendMessage(GREEN + "Console logging disabled.");
|
||||
CONFIG.getConfig().reload();
|
||||
} else {
|
||||
cs.sendMessage(GREEN + "Console logging is already disabled!");
|
||||
}
|
||||
|
||||
ConfigurationFile.ConfigValue<Boolean> value;
|
||||
String name;
|
||||
if (args[1].equalsIgnoreCase("file")) {
|
||||
value = CONFIG.getConfig().logToFile;
|
||||
name = "File logging";
|
||||
} else if (args[1].equalsIgnoreCase("console")) {
|
||||
value = CONFIG.getConfig().logToConsole;
|
||||
name = "Console logging";
|
||||
} else {
|
||||
cs.sendMessage(RED + "Usage: /anticheat log [enable/disable]");
|
||||
cs.sendMessage(RED + "Usage: /anticheat log [file/console] [on/off]");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean newValue;
|
||||
if (args[2].equalsIgnoreCase("on") || args[2].equalsIgnoreCase("enable")) {
|
||||
newValue = true;
|
||||
} else if (args[2].equalsIgnoreCase("off") || args[2].equalsIgnoreCase("disable")) {
|
||||
newValue = false;
|
||||
} else {
|
||||
cs.sendMessage(RED + "Usage: /anticheat log [file/console] [on/off]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.getValue() == newValue) {
|
||||
cs.sendMessage(GREEN + name + " is already enabled!");
|
||||
} else {
|
||||
value.setValue(newValue);
|
||||
cs.sendMessage(GREEN + name + (newValue ? " enabled." : " disabled."));
|
||||
CONFIG.getConfig().reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +202,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
if (hasPermission(cs, Permission.SYSTEM_HELP)) {
|
||||
String base = "/AntiCheat ";
|
||||
String[] lines = {
|
||||
"log [Enable/Disable]" + WHITE + " - toggle logging",
|
||||
"log [file/console] [on/off]" + WHITE + " - toggle logging",
|
||||
"report [group]" + WHITE + " - show users in groups",
|
||||
"report [user]" + WHITE + " - get a player's cheat report",
|
||||
"reload" + WHITE + " - reload AntiCheat configuration",
|
||||
@@ -425,10 +438,11 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
handlePlayerReport(cs, args);
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("log")) {
|
||||
handleLog(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("xray")) {
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("xray")) {
|
||||
handleXRay(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("debug")) {
|
||||
handleDebug(cs, Bukkit.getPlayer(args[1]));
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
package net.gravitydevelopment.anticheat.api;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.AnticheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.UserManager;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -150,7 +150,7 @@ public class AnticheatAPI {
|
||||
*
|
||||
* @return the AntiCheat Manager
|
||||
*/
|
||||
public static AnticheatManager getManager() {
|
||||
public static AntiCheatManager getManager() {
|
||||
return AntiCheat.getManager();
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package net.gravitydevelopment.anticheat.api;
|
||||
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@@ -40,18 +40,18 @@ public class CheckFailEvent extends Event {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link net.gravitydevelopment.anticheat.manage.User} who failed the check
|
||||
* Get the {@link net.gravitydevelopment.anticheat.util.User} who failed the check
|
||||
*
|
||||
* @return a {@link net.gravitydevelopment.anticheat.manage.User}
|
||||
* @return a {@link net.gravitydevelopment.anticheat.util.User}
|
||||
*/
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link net.gravitydevelopment.anticheat.manage.CheckType} failed
|
||||
* Get the {@link net.gravitydevelopment.anticheat.check.CheckType} failed
|
||||
*
|
||||
* @return a {@link net.gravitydevelopment.anticheat.manage.CheckType}
|
||||
* @return a {@link net.gravitydevelopment.anticheat.check.CheckType}
|
||||
*/
|
||||
public CheckType getCheck() {
|
||||
return type;
|
||||
|
||||
+43
-43
@@ -16,13 +16,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
package net.gravitydevelopment.anticheat.check;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.files.Lang;
|
||||
import net.gravitydevelopment.anticheat.config.files.Magic;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult.Result;
|
||||
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.util.Distance;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -88,11 +88,11 @@ public class Backend {
|
||||
private Map<String, Long> lastFallPacket = new HashMap<String, Long>();
|
||||
|
||||
private Magic magic;
|
||||
private AnticheatManager manager = null;
|
||||
private AntiCheatManager manager = null;
|
||||
private Lang lang = null;
|
||||
private static final CheckResult PASS = new CheckResult(Result.PASSED);
|
||||
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
|
||||
|
||||
public Backend(AnticheatManager instance) {
|
||||
public Backend(AntiCheatManager instance) {
|
||||
magic = instance.getConfiguration().getMagic();
|
||||
manager = instance;
|
||||
lang = manager.getConfiguration().getLang();
|
||||
@@ -178,7 +178,7 @@ public class Backend {
|
||||
f = (f * f + f * 2.0F) / 3.0F;
|
||||
f = f > 1.0F ? 1.0F : f;
|
||||
if (Math.abs(force - f) > magic.BOW_ERROR) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " fired their bow too fast (actual force=" + force + ", calculated force=" + f + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " fired their bow too fast (actual force=" + force + ", calculated force=" + f + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -188,13 +188,13 @@ public class Backend {
|
||||
increment(player, projectilesShot, 10);
|
||||
if (!projectileTime.containsKey(player.getName())) {
|
||||
projectileTime.put(player.getName(), System.currentTimeMillis());
|
||||
return new CheckResult(Result.PASSED);
|
||||
return new CheckResult(CheckResult.Result.PASSED);
|
||||
} else if (projectilesShot.get(player.getName()) == magic.PROJECTILE_CHECK) {
|
||||
long time = System.currentTimeMillis() - projectileTime.get(player.getName());
|
||||
projectileTime.remove(player.getName());
|
||||
projectilesShot.remove(player.getName());
|
||||
if (time < magic.PROJECTILE_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " wound up a bow too fast (actual time=" + time + ", min time=" + magic.PROJECTILE_TIME_MIN + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " wound up a bow too fast (actual time=" + time + ", min time=" + magic.PROJECTILE_TIME_MIN + ")");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -204,13 +204,13 @@ public class Backend {
|
||||
increment(player, blocksDropped, 10);
|
||||
if (!blockTime.containsKey(player.getName())) {
|
||||
blockTime.put(player.getName(), System.currentTimeMillis());
|
||||
return new CheckResult(Result.PASSED);
|
||||
return new CheckResult(CheckResult.Result.PASSED);
|
||||
} else if (blocksDropped.get(player.getName()) == magic.DROP_CHECK) {
|
||||
long time = System.currentTimeMillis() - blockTime.get(player.getName());
|
||||
blockTime.remove(player.getName());
|
||||
blocksDropped.remove(player.getName());
|
||||
if (time < magic.DROP_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " dropped an item too fast (actual time=" + time + ", min time=" + magic.DROP_TIME_MIN + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " dropped an item too fast (actual time=" + time + ", min time=" + magic.DROP_TIME_MIN + ")");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -218,7 +218,7 @@ public class Backend {
|
||||
|
||||
public CheckResult checkLongReachBlock(Player player, double x, double y, double z) {
|
||||
if (isInstantBreakExempt(player)) {
|
||||
return new CheckResult(Result.PASSED);
|
||||
return new CheckResult(CheckResult.Result.PASSED);
|
||||
} else {
|
||||
String string = player.getName() + " reached too far for a block";
|
||||
double distance =
|
||||
@@ -227,7 +227,7 @@ public class Backend {
|
||||
: magic.BLOCK_MAX_DISTANCE;
|
||||
double i = x >= distance ? x : y > distance ? y : z > distance ? z : -1;
|
||||
if (i != -1) {
|
||||
return new CheckResult(Result.FAILED, string + " (distance=" + i + ", max=" + magic.BLOCK_MAX_DISTANCE + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, string + " (distance=" + i + ", max=" + magic.BLOCK_MAX_DISTANCE + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ public class Backend {
|
||||
String string = player.getName() + " reached too far for an entity";
|
||||
double i = x >= magic.ENTITY_MAX_DISTANCE ? x : y > magic.ENTITY_MAX_DISTANCE ? y : z > magic.ENTITY_MAX_DISTANCE ? z : -1;
|
||||
if (i != -1) {
|
||||
return new CheckResult(Result.FAILED, string + " (distance=" + i + ", max=" + magic.ENTITY_MAX_DISTANCE + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, string + " (distance=" + i + ", max=" + magic.ENTITY_MAX_DISTANCE + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public class Backend {
|
||||
|
||||
public CheckResult checkSpider(Player player, double y) {
|
||||
if (y <= magic.LADDER_Y_MAX && y >= magic.LADDER_Y_MIN && !Utilities.isClimbableBlock(player.getLocation().getBlock())) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to climb a non-ladder (" + player.getLocation().getBlock().getType() + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to climb a non-ladder (" + player.getLocation().getBlock().getType() + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -254,7 +254,7 @@ public class Backend {
|
||||
|
||||
public CheckResult checkYSpeed(Player player, double y) {
|
||||
if (!isMovingExempt(player) && !player.isInsideVehicle() && !player.isSleeping() && y > magic.Y_SPEED_MAX && !isDoing(player, velocitized, magic.VELOCITY_TIME) && !player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + "'s y speed was too high (speed=" + y + ", max=" + magic.Y_SPEED_MAX + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + "'s y speed was too high (speed=" + y + ", max=" + magic.Y_SPEED_MAX + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ public class Backend {
|
||||
int i = nofallViolation.get(name);
|
||||
if (i >= magic.NOFALL_LIMIT) {
|
||||
nofallViolation.put(player.getName(), 1);
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to avoid fall damage (fall distance = 0 " + i + " times in a row, max=" + magic.NOFALL_LIMIT + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to avoid fall damage (fall distance = 0 " + i + " times in a row, max=" + magic.NOFALL_LIMIT + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -322,7 +322,7 @@ public class Backend {
|
||||
if (x > max || z > max) {
|
||||
int num = this.increment(player, speedViolation, magic.SPEED_MAX);
|
||||
if (num >= magic.SPEED_MAX) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + "'s speed was too high " + reason + num + " times in a row (max=" + magic.SPEED_MAX + ", speed=" + (x > z ? x : z) + ", max speed=" + max + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + "'s speed was too high " + reason + num + " times in a row (max=" + magic.SPEED_MAX + ", speed=" + (x > z ? x : z) + ", max speed=" + max + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -339,7 +339,7 @@ public class Backend {
|
||||
if (player.isSneaking() && !player.isFlying() && !isMovingExempt(player) && !player.isInsideVehicle()) {
|
||||
double i = x > magic.XZ_SPEED_MAX_SNEAK ? x : z > magic.XZ_SPEED_MAX_SNEAK ? z : -1;
|
||||
if (i != -1) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " was sneaking too fast (speed=" + i + ", max=" + magic.XZ_SPEED_MAX_SNEAK + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " was sneaking too fast (speed=" + i + ", max=" + magic.XZ_SPEED_MAX_SNEAK + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -351,7 +351,7 @@ public class Backend {
|
||||
public CheckResult checkSprintHungry(PlayerToggleSprintEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.isSprinting() && player.getGameMode() != GameMode.CREATIVE && player.getFoodLevel() <= magic.SPRINT_FOOD_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " sprinted while hungry (food=" + player.getFoodLevel() + ", min=" + magic.SPRINT_FOOD_MIN + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " sprinted while hungry (food=" + player.getFoodLevel() + ", min=" + magic.SPRINT_FOOD_MIN + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -386,7 +386,7 @@ public class Backend {
|
||||
int v = waterSpeedViolation.get(player.getName());
|
||||
if (v >= magic.WATER_SPEED_VIOLATION_MAX) {
|
||||
waterSpeedViolation.put(player.getName(), 0);
|
||||
return new CheckResult(Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
|
||||
} else {
|
||||
waterSpeedViolation.put(player.getName(), v + 1);
|
||||
}
|
||||
@@ -411,7 +411,7 @@ public class Backend {
|
||||
} else {
|
||||
waterAscensionViolation.put(player.getName(), v + 1);
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
|
||||
} else {
|
||||
waterAscensionViolation.put(player.getName(), 1);
|
||||
}
|
||||
@@ -434,7 +434,7 @@ public class Backend {
|
||||
for (int i = 0; i < (Math.round(distance.getYDifference())) + 1; i++) {
|
||||
Block block = new Location(player.getWorld(), player.getLocation().getX(), to + i, player.getLocation().getZ()).getBlock();
|
||||
if (block.getType() != Material.AIR && block.getType().isSolid()) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to move through a solid block", (int) from + 3);
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to move through a solid block", (int) from + 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ public class Backend {
|
||||
player.teleport(g);
|
||||
}
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to fly on y-axis " + yAxisViolations.get(name) + " times (max =" + magic.Y_MAXVIOLATIONS + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis " + yAxisViolations.get(name) + " times (max =" + magic.Y_MAXVIOLATIONS + ")");
|
||||
} else {
|
||||
if (yAxisViolations.get(name) > magic.Y_MAXVIOLATIONS && (System.currentTimeMillis() - yAxisLastViolation.get(name)) > magic.Y_MAXVIOTIME) {
|
||||
yAxisViolations.put(name, 0);
|
||||
@@ -485,7 +485,7 @@ public class Backend {
|
||||
player.teleport(g);
|
||||
}
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + magic.Y_TIME + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + magic.Y_TIME + ")");
|
||||
} else {
|
||||
if ((y1 - lastYcoord.get(name)) > magic.Y_MAXDIFF + 1 || (System.currentTimeMillis() - lastYtime.get(name)) > magic.Y_TIME) {
|
||||
lastYtime.put(name, System.currentTimeMillis());
|
||||
@@ -512,7 +512,7 @@ public class Backend {
|
||||
long time = System.currentTimeMillis() - stepTime.get(name);
|
||||
steps.put(name, 0);
|
||||
if (time < magic.TIMER_TIMEMIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to alter their timer, took " + step + " steps in " + time + " ms (min = " + magic.TIMER_TIMEMIN + " ms)");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to alter their timer, took " + step + " steps in " + time + " ms (min = " + magic.TIMER_TIMEMIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -575,7 +575,7 @@ public class Backend {
|
||||
}
|
||||
|
||||
if (blocksOverFlight.get(name) > magic.FLIGHT_BLOCK_LIMIT && (y1 <= y2)) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " flew over " + blocksOverFlight.get(name) + " blocks (max=" + magic.FLIGHT_BLOCK_LIMIT + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " flew over " + blocksOverFlight.get(name) + " blocks (max=" + magic.FLIGHT_BLOCK_LIMIT + ")");
|
||||
}
|
||||
} else {
|
||||
blocksOverFlight.put(name, 0D);
|
||||
@@ -607,7 +607,7 @@ public class Backend {
|
||||
if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid() && !block.getRelative(BlockFace.EAST).isLiquid() && !block.getRelative(BlockFace.WEST).isLiquid()) {
|
||||
increment(player, ascensionCount, max);
|
||||
if (ascensionCount.get(name) >= max) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " ascended " + ascensionCount.get(name) + " times in a row (max = " + max + string + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " ascended " + ascensionCount.get(name) + " times in a row (max = " + max + string + ")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -624,7 +624,7 @@ public class Backend {
|
||||
if (blockPunches.get(name) != null && player.getGameMode() != GameMode.CREATIVE) {
|
||||
int i = blockPunches.get(name);
|
||||
if (i < magic.BLOCK_PUNCH_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to break a block of " + block.getType() + " after only " + i + " punches (min=" + magic.BLOCK_PUNCH_MIN + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to break a block of " + block.getType() + " after only " + i + " punches (min=" + magic.BLOCK_PUNCH_MIN + ")");
|
||||
} else {
|
||||
blockPunches.put(name, 0); // it should reset after EACH block break.
|
||||
}
|
||||
@@ -652,7 +652,7 @@ public class Backend {
|
||||
if (!silentMode()) {
|
||||
player.sendMessage(ChatColor.RED + "[AntiCheat] Fastbreaking detected. Please wait 10 seconds before breaking blocks.");
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName() + " broke blocks too fast " + i + " times in a row (max=" + violations + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " broke blocks too fast " + i + " times in a row (max=" + violations + ")");
|
||||
} else if (fastBreakViolation.get(name) > 0 && math > magic.FASTBREAK_MAXVIOLATIONTIME) {
|
||||
fastBreakViolation.put(name, 0);
|
||||
}
|
||||
@@ -679,7 +679,7 @@ public class Backend {
|
||||
int i = fastBreaks.get(name);
|
||||
fastBreaks.put(name, 0);
|
||||
fastBreakViolation.put(name, fastBreakViolation.get(name) + 1);
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to break " + i + " blocks in " + math + " ms (max=" + magic.FASTBREAK_LIMIT + " in " + timemax + " ms)");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to break " + i + " blocks in " + math + " ms (max=" + magic.FASTBREAK_LIMIT + " in " + timemax + " ms)");
|
||||
} else if (fastBreaks.get(name) >= magic.FASTBREAK_LIMIT || fastBreakViolation.get(name) > 0) {
|
||||
if (!blockBreakHolder.containsKey(name) || !blockBreakHolder.get(name)) {
|
||||
blockBreakHolder.put(name, true);
|
||||
@@ -716,7 +716,7 @@ public class Backend {
|
||||
if (!silentMode()) {
|
||||
player.sendMessage(ChatColor.RED + "[AntiCheat] Fastplacing detected. Please wait 10 seconds before placing blocks.");
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName() + " placed blocks too fast " + fastBreakViolation.get(name) + " times in a row (max=" + violations + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " placed blocks too fast " + fastBreakViolation.get(name) + " times in a row (max=" + violations + ")");
|
||||
} else if (lastBlockPlaced.get(name) > 0 && math > magic.FASTPLACE_MAXVIOLATIONTIME) {
|
||||
AntiCheat.debugLog("Reset facePlaceViolation for " + name);
|
||||
fastPlaceViolation.put(name, 0);
|
||||
@@ -730,7 +730,7 @@ public class Backend {
|
||||
lastBlockPlaceTime.put(name, (time - last));
|
||||
lastBlockPlaced.put(name, time);
|
||||
fastPlaceViolation.put(name, fastPlaceViolation.get(name) + 1);
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to place a block " + thisTime + " ms after the last one (min=" + magic.FASTPLACE_TIMEMIN + " ms)");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to place a block " + thisTime + " ms after the last one (min=" + magic.FASTPLACE_TIMEMIN + " ms)");
|
||||
}
|
||||
lastBlockPlaceTime.put(name, (time - last));
|
||||
}
|
||||
@@ -766,9 +766,9 @@ public class Backend {
|
||||
break;
|
||||
} else {
|
||||
if (manager.getConfiguration().getConfig().blockChatSpamRepetition.getValue() && m.equalsIgnoreCase(msg) && i == 1) {
|
||||
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
|
||||
return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue());
|
||||
} else if (manager.getConfiguration().getConfig().blockChatSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN * 2) {
|
||||
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
|
||||
return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -793,9 +793,9 @@ public class Backend {
|
||||
break;
|
||||
} else {
|
||||
if (manager.getConfiguration().getConfig().blockCommandSpamRepetition.getValue() && m.equalsIgnoreCase(cmd) && i == 1) {
|
||||
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
|
||||
return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue());
|
||||
} else if (manager.getConfiguration().getConfig().blockCommandSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN * 2) {
|
||||
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
|
||||
return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -820,7 +820,7 @@ public class Backend {
|
||||
long time = System.currentTimeMillis() - inventoryTime.get(name);
|
||||
inventoryClicks.put(name, 0);
|
||||
if (time < magic.INVENTORY_TIMEMIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " clicked inventory slots " + clicks + " times in " + time + " ms (max=" + magic.INVENTORY_CHECK + " in " + magic.INVENTORY_TIMEMIN + " ms)");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " clicked inventory slots " + clicks + " times in " + time + " ms (max=" + magic.INVENTORY_CHECK + " in " + magic.INVENTORY_TIMEMIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -828,7 +828,7 @@ public class Backend {
|
||||
|
||||
public CheckResult checkAutoTool(Player player) {
|
||||
if (itemInHand.containsKey(player.getName()) && itemInHand.get(player.getName()) != player.getItemInHand().getType()) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " switched tools too fast (had " + itemInHand.get(player.getName()) + ", has " + player.getItemInHand().getType() + ")");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " switched tools too fast (had " + itemInHand.get(player.getName()) + ", has " + player.getItemInHand().getType() + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -836,7 +836,7 @@ public class Backend {
|
||||
|
||||
public CheckResult checkSprintDamage(Player player) {
|
||||
if (isDoing(player, sprinted, magic.SPRINT_MIN)) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " sprinted and damaged an entity too fast (min sprint=" + magic.SPRINT_MIN + " ms)");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " sprinted and damaged an entity too fast (min sprint=" + magic.SPRINT_MIN + " ms)");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -844,7 +844,7 @@ public class Backend {
|
||||
|
||||
public CheckResult checkAnimation(Player player, Entity e) {
|
||||
if (!justAnimated(player)) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " didn't animate before damaging a " + e.getType());
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " didn't animate before damaging a " + e.getType());
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -856,7 +856,7 @@ public class Backend {
|
||||
long l = lastHeal.get(player.getName());
|
||||
lastHeal.remove(player.getName());
|
||||
if ((System.currentTimeMillis() - l) < magic.HEAL_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " healed too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + magic.HEAL_TIME_MIN + " ms)");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " healed too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + magic.HEAL_TIME_MIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -868,7 +868,7 @@ public class Backend {
|
||||
long l = startEat.get(player.getName());
|
||||
startEat.remove(player.getName());
|
||||
if ((System.currentTimeMillis() - l) < magic.EAT_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " ate too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + magic.EAT_TIME_MIN + " ms)");
|
||||
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " ate too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + magic.EAT_TIME_MIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.check;
|
||||
|
||||
public class CheckResult {
|
||||
|
||||
+2
-1
@@ -16,9 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
package net.gravitydevelopment.anticheat.check;
|
||||
|
||||
import net.gravitydevelopment.anticheat.api.CheckFailEvent;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.util.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -32,7 +32,7 @@ import net.gravitydevelopment.anticheat.config.holders.yaml.YamlRulesHolder;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Groups;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Rules;
|
||||
import net.gravitydevelopment.anticheat.manage.AnticheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
@@ -40,7 +40,7 @@ import java.util.ArrayList;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
private AnticheatManager manager;
|
||||
private AntiCheatManager manager;
|
||||
private Config config;
|
||||
private Enterprise enterprise;
|
||||
private Lang lang;
|
||||
@@ -53,7 +53,7 @@ public class Configuration {
|
||||
private ArrayList<ConfigurationFile> flatfiles;
|
||||
private ArrayList<ConfigurationTable> dbfiles;
|
||||
|
||||
public Configuration(AntiCheat plugin, AnticheatManager manager) {
|
||||
public Configuration(AntiCheat plugin, AntiCheatManager manager) {
|
||||
removeOldFiles();
|
||||
this.manager = manager;
|
||||
config = new Config(plugin, this);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Config extends ConfigurationFile {
|
||||
public ConfigValue<String> commandSpamActionOne;
|
||||
public ConfigValue<String> commandSpamActionTwo;
|
||||
|
||||
public ConfigValue<Integer> fileLogLevel;
|
||||
public ConfigValue<Boolean> logToFile;
|
||||
|
||||
public ConfigValue<List<String>> disabledWorlds;
|
||||
|
||||
@@ -85,7 +85,7 @@ public class Config extends ConfigurationFile {
|
||||
commandSpamActionOne = new ConfigValue<String>("spam.command.action-one");
|
||||
commandSpamActionTwo = new ConfigValue<String>("spam.command.action-two");
|
||||
|
||||
fileLogLevel = new ConfigValue<Integer>("system.file-log-level");
|
||||
logToFile = new ConfigValue<Boolean>("system.log-to-file");
|
||||
|
||||
disabledWorlds = new ConfigValue<List<String>>("disable-in");
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package net.gravitydevelopment.anticheat.config.providers;
|
||||
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.check.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.util.Distance;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.check.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.util.Distance;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.check.Backend;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.manage.*;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -56,9 +59,6 @@ public class EventListener implements Listener {
|
||||
if (CONFIG.getConfig().enterprise.getValue() && CONFIG.getEnterprise().loggingEnabled.getValue()) {
|
||||
CONFIG.getEnterprise().database.logEvent(user, type);
|
||||
}
|
||||
if (CONFIG.getConfig().fileLogLevel.getValue() == 2 && type.getUses(user.getName()) % 10 == 0) {
|
||||
AntiCheat.getManager().fileLog(user.getName() + " has triggered multiple " + type + " checks.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class EventListener implements Listener {
|
||||
return CHECK_MANAGER;
|
||||
}
|
||||
|
||||
public static AnticheatManager getManager() {
|
||||
public static AntiCheatManager getManager() {
|
||||
return AntiCheat.getManager();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.check.CheckResult;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.check.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.util.Distance;
|
||||
import net.gravitydevelopment.anticheat.util.Permission;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
|
||||
+16
-60
@@ -19,100 +19,52 @@
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.check.Backend;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.util.FileFormatter;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The internal hub for all managers.
|
||||
*/
|
||||
|
||||
public class AnticheatManager {
|
||||
public class AntiCheatManager {
|
||||
private static AntiCheat plugin = null;
|
||||
private static Configuration configuration;
|
||||
private static XRayTracker xrayTracker = null;
|
||||
private static UserManager userManager = null;
|
||||
private static CheckManager checkManager = null;
|
||||
private static LoggingManager loggingManager = null;
|
||||
private static Backend backend = null;
|
||||
private final Logger fileLogger;
|
||||
private static Map<String, RegisteredListener[]> eventchains = new ConcurrentHashMap<String, RegisteredListener[]>();
|
||||
private static Map<String, Long> eventcache = new ConcurrentHashMap<String, Long>();
|
||||
private static List<String> logs = new CopyOnWriteArrayList<String>();
|
||||
private static Handler fileHandler;
|
||||
private static final int LOG_LEVEL_HIGH = 3;
|
||||
|
||||
public AnticheatManager(AntiCheat instance, Logger logger) {
|
||||
public AntiCheatManager(AntiCheat instance, Logger logger) {
|
||||
plugin = instance;
|
||||
// now load all the others!!!!!
|
||||
fileLogger = Logger.getLogger("net.gravitydevelopment.anticheat.AntiCheat");
|
||||
configuration = new Configuration(plugin, this);
|
||||
loggingManager = new LoggingManager(plugin, logger, configuration);
|
||||
xrayTracker = new XRayTracker();
|
||||
userManager = new UserManager(configuration);
|
||||
checkManager = new CheckManager(this, configuration);
|
||||
userManager = new UserManager(this);
|
||||
checkManager = new CheckManager(this);
|
||||
backend = new Backend(this);
|
||||
try {
|
||||
File file = new File(plugin.getDataFolder(), "log");
|
||||
if (!file.exists()) {
|
||||
file.mkdir();
|
||||
}
|
||||
fileHandler = new FileHandler(plugin.getDataFolder() + "/log/anticheat.log", true);
|
||||
fileHandler.setFormatter(new FileFormatter());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
fileLogger.setUseParentHandlers(false);
|
||||
fileLogger.addHandler(fileHandler);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
log(message, 0);
|
||||
loggingManager.log(message);
|
||||
}
|
||||
|
||||
public void debugLog(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.GRAY + message);
|
||||
logs.add(ChatColor.stripColor(message));
|
||||
loggingManager.debugLog(message);
|
||||
}
|
||||
|
||||
public void log(String message, int i) {
|
||||
if (i != 1 && getConfiguration().getConfig().logToConsole.getValue()) {
|
||||
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.RED + message);
|
||||
}
|
||||
if (i == 0 && getConfiguration().getConfig().fileLogLevel.getValue() == LOG_LEVEL_HIGH) { // Not an alert, normal log message
|
||||
fileLog(message);
|
||||
} else if (getConfiguration().getConfig().fileLogLevel.getValue() != 0) { // alert
|
||||
fileLog(message);
|
||||
}
|
||||
logs.add(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
public void fileLog(String message) {
|
||||
fileLogger.info(message);
|
||||
}
|
||||
|
||||
public List<String> getLastLogs() {
|
||||
List<String> log = new CopyOnWriteArrayList<String>();
|
||||
if (logs.size() < 30) {
|
||||
return logs;
|
||||
}
|
||||
for (int i = logs.size() - 1; i >= 0; i--) {
|
||||
log.add(logs.get(i));
|
||||
}
|
||||
logs.clear();
|
||||
return log;
|
||||
public void playerLog(String message) {
|
||||
loggingManager.logToPlayers(message);
|
||||
}
|
||||
|
||||
public void addEvent(String e, RegisteredListener[] arr) {
|
||||
@@ -179,8 +131,12 @@ public class AnticheatManager {
|
||||
return backend;
|
||||
}
|
||||
|
||||
public LoggingManager getLoggingManager() {
|
||||
return loggingManager;
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
fileHandler.close();
|
||||
loggingManager.closeHandler();
|
||||
|
||||
if (configuration.getConfig().enterprise.getValue()) {
|
||||
configuration.getEnterprise().database.shutdown();
|
||||
@@ -19,6 +19,7 @@
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -34,16 +35,16 @@ import java.util.Map;
|
||||
*/
|
||||
|
||||
public class CheckManager {
|
||||
private AnticheatManager manager = null;
|
||||
private AntiCheatManager manager = null;
|
||||
private Configuration config;
|
||||
private static List<CheckType> checkIgnoreList = new ArrayList<CheckType>();
|
||||
private static Map<String, List<CheckType>> exemptList = new HashMap<String, List<CheckType>>();
|
||||
private static int disabled = 0;
|
||||
private static int exempt = 0;
|
||||
|
||||
public CheckManager(AnticheatManager instance, Configuration config) {
|
||||
manager = instance;
|
||||
this.config = config;
|
||||
public CheckManager(AntiCheatManager manager) {
|
||||
this.manager = manager;
|
||||
this.config = manager.getConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.util.FileFormatter;
|
||||
import net.gravitydevelopment.anticheat.util.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class LoggingManager {
|
||||
|
||||
private final Logger fileLogger;
|
||||
private static Handler fileHandler;
|
||||
private static List<String> logs = new CopyOnWriteArrayList<String>();
|
||||
private final Configuration config;
|
||||
|
||||
public LoggingManager(AntiCheat plugin, Logger logger, Configuration config) {
|
||||
this.fileLogger = Logger.getLogger("net.gravitydevelopment.anticheat.AntiCheat");
|
||||
this.config = config;
|
||||
try {
|
||||
File file = new File(plugin.getDataFolder(), "log");
|
||||
if (!file.exists()) {
|
||||
file.mkdir();
|
||||
}
|
||||
fileHandler = new FileHandler(plugin.getDataFolder() + "/log/anticheat.log", true);
|
||||
fileHandler.setFormatter(new FileFormatter());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
fileLogger.setUseParentHandlers(false);
|
||||
fileLogger.addHandler(fileHandler);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
if (config.getConfig().logToConsole.getValue()) {
|
||||
logToConsole(message);
|
||||
}
|
||||
if (config.getConfig().logToFile.getValue()) {
|
||||
logToFile(message);
|
||||
}
|
||||
logToLogs(message);
|
||||
}
|
||||
|
||||
public void debugLog(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.GRAY + message);
|
||||
logToLogs(message);
|
||||
}
|
||||
|
||||
public void logToConsole(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.RED + message);
|
||||
}
|
||||
|
||||
public void logToFile(String message) {
|
||||
fileLogger.info(message);
|
||||
}
|
||||
|
||||
public void logToPlayers(String message) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (Permission.SYSTEM_NOTICE.get(player)) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logToLogs(String message) { // Yo dawg
|
||||
logs.add(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
public List<String> getLastLogs() {
|
||||
List<String> log = new CopyOnWriteArrayList<String>();
|
||||
if (logs.size() < 30) {
|
||||
return logs;
|
||||
}
|
||||
for (int i = logs.size() - 1; i >= 0; i--) {
|
||||
log.add(logs.get(i));
|
||||
}
|
||||
logs.clear();
|
||||
return log;
|
||||
}
|
||||
|
||||
public void closeHandler() {
|
||||
fileHandler.close();
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,9 @@ public class PacketManager {
|
||||
|
||||
private ProtocolManager protocolManager;
|
||||
private AntiCheat plugin;
|
||||
private AnticheatManager manager;
|
||||
private AntiCheatManager manager;
|
||||
|
||||
public PacketManager(ProtocolManager protocolManager, AntiCheat plugin, AnticheatManager manager) {
|
||||
public PacketManager(ProtocolManager protocolManager, AntiCheat plugin, AntiCheatManager manager) {
|
||||
this.protocolManager = protocolManager;
|
||||
this.plugin = plugin;
|
||||
this.manager = manager;
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.util.Group;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -30,20 +32,20 @@ import java.util.List;
|
||||
|
||||
public class UserManager {
|
||||
private List<User> users = new ArrayList<User>();
|
||||
private static AntiCheatManager manager;
|
||||
private static Configuration config;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private static final ChatColor GOLD = ChatColor.GOLD;
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static List<String> alert;
|
||||
|
||||
/**
|
||||
* Initialize the user manager with a given configuration
|
||||
* Initialize the user manager
|
||||
*
|
||||
* @param conf Configuration to use
|
||||
* @param manager The AntiCheat Manager
|
||||
*/
|
||||
public UserManager(Configuration conf) {
|
||||
config = conf;
|
||||
alert = config.getLang().alert.getValue();
|
||||
public UserManager(AntiCheatManager manager) {
|
||||
this.manager = manager;
|
||||
this.config = manager.getConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,6 +158,15 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the alert to use for a check being failed
|
||||
*
|
||||
* @return check fail alert message
|
||||
*/
|
||||
public List<String> getAlert() {
|
||||
return config.getLang().alert.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an alert
|
||||
*
|
||||
@@ -165,6 +176,7 @@ public class UserManager {
|
||||
*/
|
||||
public void alert(User user, Group group, CheckType type) {
|
||||
ArrayList<String> messageArray = new ArrayList<String>();
|
||||
List<String> alert = getAlert();
|
||||
for (int i = 0; i < alert.size(); i++) {
|
||||
String message = alert.get(i);
|
||||
if (!message.equals("")) {
|
||||
@@ -215,9 +227,10 @@ public class UserManager {
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("KICK")) {
|
||||
user.getPlayer().kickPlayer(RED + kickReason);
|
||||
String msg = RED + config.getLang().kickBroadcast.getValue().replaceAll("&player", name);
|
||||
String msg = RED + config.getLang().kickBroadcast.getValue().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")";
|
||||
if (!msg.equals("")) {
|
||||
Bukkit.broadcastMessage(msg);
|
||||
manager.log(msg);
|
||||
manager.playerLog(msg);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("WARN")) {
|
||||
List<String> message = warning;
|
||||
@@ -229,9 +242,10 @@ public class UserManager {
|
||||
} else if (event.equalsIgnoreCase("BAN")) {
|
||||
user.getPlayer().setBanned(true);
|
||||
user.getPlayer().kickPlayer(RED + banReason);
|
||||
String msg = RED + config.getLang().banBroadcast.getValue().replaceAll("&player", name);
|
||||
String msg = RED + config.getLang().banBroadcast.getValue().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")";
|
||||
if (!msg.equals("")) {
|
||||
Bukkit.broadcastMessage(msg);
|
||||
manager.log(msg);
|
||||
manager.playerLog(msg);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("RESET")) {
|
||||
user.resetLevel();
|
||||
|
||||
@@ -102,7 +102,7 @@ public class PastebinReport {
|
||||
}
|
||||
|
||||
private void appendLogs() {
|
||||
List<String> logs = AntiCheat.getManager().getLastLogs();
|
||||
List<String> logs = AntiCheat.getManager().getLoggingManager().getLastLogs();
|
||||
if (logs.size() == 0) {
|
||||
append("No recent logs.");
|
||||
return;
|
||||
|
||||
@@ -59,6 +59,7 @@ public enum Permission {
|
||||
SYSTEM_UPDATE,
|
||||
SYSTEM_REPORT,
|
||||
SYSTEM_ALERT,
|
||||
SYSTEM_NOTICE,
|
||||
SYSTEM_CALIBRATE,
|
||||
SYSTEM_DEBUG,
|
||||
SYSTEM_RELOAD;
|
||||
|
||||
+2
-1
@@ -16,9 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.util.Group;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
@@ -57,15 +57,8 @@ public final class Utilities {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (AntiCheat.getManager().getConfiguration().getConfig().logToConsole.getValue()) {
|
||||
for (String msg : message) {
|
||||
AntiCheat.getManager().log(msg);
|
||||
}
|
||||
}
|
||||
if (AntiCheat.getManager().getConfiguration().getConfig().fileLogLevel.getValue() != 0) {
|
||||
for (String msg : message) {
|
||||
AntiCheat.getManager().log(msg, 1);
|
||||
}
|
||||
for (String msg : message) {
|
||||
AntiCheat.getManager().log(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package net.gravitydevelopment.anticheat.util.enterprise;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package net.gravitydevelopment.anticheat.util.rule;
|
||||
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package net.gravitydevelopment.anticheat.util.rule;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.User;
|
||||
import net.gravitydevelopment.anticheat.util.Group;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.TreeMap;
|
||||
* <br /><br />
|
||||
* <p/>
|
||||
* <b>Types of variables:</b><br />
|
||||
* - Check: Contains all valid checks as listed in {@link net.gravitydevelopment.anticheat.manage.CheckType}, and will return the number of times this user has failed the given check<br />
|
||||
* - Check: Contains all valid checks as listed in {@link net.gravitydevelopment.anticheat.check.CheckType}, and will return the number of times this user has failed the given check<br />
|
||||
* - Player: Contains LEVEL, the player's current level and CHECK, the check that was just failed
|
||||
* <br /><br />
|
||||
* <p/>
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.gravitydevelopment.anticheat.xray;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -29,9 +29,8 @@ system:
|
||||
auto-update: true
|
||||
# Should AntiCheat log ALL failed checks to console?
|
||||
log-to-console: false
|
||||
# Should AntiCheat log to files?
|
||||
# 0 = off, 1 = log only when an event takes place, 2 = more detailed logs, 3 = most detailed logs
|
||||
file-log-level: 1
|
||||
# Should AntiCheat log to file?
|
||||
log-to-file: true
|
||||
# Should AntiCheat display extra debug information when starting?
|
||||
verbose-startup: false
|
||||
# If silent mode is on, players will not be stopped when they try to hack, and AntiCheat will do everything possible to keep them unaware of their rising hack level.
|
||||
|
||||
@@ -12,11 +12,11 @@ chat:
|
||||
warning: 'Stop spamming the server or you will be kicked!'
|
||||
kick_reason: 'Kicked for spamming'
|
||||
ban_reason: 'Banned for spamming'
|
||||
kick_broadcast: '[AntiCheat] &player was kicked for spamming'
|
||||
ban_broadcast: '[AntiCheat] &player was banned for spamming'
|
||||
kick_broadcast: '&player was kicked for spamming'
|
||||
ban_broadcast: '&player was banned for spamming'
|
||||
ban:
|
||||
ban_reason: 'Banned by AntiCheat'
|
||||
ban_broadcast: '[AntiCheat] &player was banned for hacking.'
|
||||
ban_broadcast: '&player was banned for hacking.'
|
||||
kick:
|
||||
kick_reason: 'Kicked by AntiCheat'
|
||||
kick_broadcast: '[AntiCheat] &player was kicked for hacking.'
|
||||
kick_broadcast: '&player was kicked for hacking.'
|
||||
@@ -12,36 +12,39 @@ commands:
|
||||
usage: /anticheat help
|
||||
aliases: anti
|
||||
permissions:
|
||||
anticheat.notice:
|
||||
description: See broadcasts when a player is kicked or banned for hacking
|
||||
anticheat.alert:
|
||||
description: Get alerts
|
||||
description: See alerts when a player might be cheating
|
||||
anticheat.system.help:
|
||||
description: Help access
|
||||
description: Access the help message
|
||||
anticheat.system.report:
|
||||
description: Reports access
|
||||
description: Access cheat reports
|
||||
anticheat.system.spy:
|
||||
description: Spy system access
|
||||
description: Access the spy system
|
||||
anticheat.system.xray:
|
||||
description: XRay info access
|
||||
description: Access info about xray usage
|
||||
anticheat.mod:
|
||||
description: Mod helper perm
|
||||
children:
|
||||
anticheat.system.notice: true
|
||||
anticheat.system.alert: true
|
||||
anticheat.system.help: true
|
||||
anticheat.system.report: true
|
||||
anticheat.system.spy: true
|
||||
anticheat.system.xray: true
|
||||
anticheat.system.log:
|
||||
description: Log access
|
||||
description: Access turning console logging on or off
|
||||
anticheat.system.reload:
|
||||
description: Reload access
|
||||
description: Access reloading the system
|
||||
anticheat.system.reset:
|
||||
description: Reset access
|
||||
description: Access resetting a player's cheat level
|
||||
anticheat.system.update:
|
||||
description: Update access
|
||||
description: Access information about whether the system is updated
|
||||
anticheat.system.calibrate:
|
||||
description: Calibrate info access
|
||||
description: Access the calibration system
|
||||
anticheat.system.debug:
|
||||
description: Debug access
|
||||
description: Access debug reports
|
||||
anticheat.admin:
|
||||
description: Admin helper perm
|
||||
children:
|
||||
|
||||
Reference in new issue
Block a user