diff --git a/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java b/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java index 4c9140b..aad9ce8 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java +++ b/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java @@ -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 eventList = new ArrayList(); 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; } diff --git a/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java b/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java index f751f63..b9ff698 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java +++ b/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java @@ -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 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])); diff --git a/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java b/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java index 4d3ad84..7f58536 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java +++ b/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java @@ -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(); } } diff --git a/src/main/java/net/gravitydevelopment/anticheat/api/CheckFailEvent.java b/src/main/java/net/gravitydevelopment/anticheat/api/CheckFailEvent.java index 4334561..144db57 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/api/CheckFailEvent.java +++ b/src/main/java/net/gravitydevelopment/anticheat/api/CheckFailEvent.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/Backend.java b/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java similarity index 87% rename from src/main/java/net/gravitydevelopment/anticheat/manage/Backend.java rename to src/main/java/net/gravitydevelopment/anticheat/check/Backend.java index 3a1c992..6d2d020 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/Backend.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java @@ -16,13 +16,13 @@ * along with this program. If not, see . */ -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 lastFallPacket = new HashMap(); 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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/CheckResult.java b/src/main/java/net/gravitydevelopment/anticheat/check/CheckResult.java similarity index 96% rename from src/main/java/net/gravitydevelopment/anticheat/util/CheckResult.java rename to src/main/java/net/gravitydevelopment/anticheat/check/CheckResult.java index b11e984..f173844 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/CheckResult.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/CheckResult.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package net.gravitydevelopment.anticheat.util; +package net.gravitydevelopment.anticheat.check; public class CheckResult { diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/CheckType.java b/src/main/java/net/gravitydevelopment/anticheat/check/CheckType.java similarity index 97% rename from src/main/java/net/gravitydevelopment/anticheat/manage/CheckType.java rename to src/main/java/net/gravitydevelopment/anticheat/check/CheckType.java index bfc677c..5b8bb37 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/CheckType.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/CheckType.java @@ -16,9 +16,10 @@ * along with this program. If not, see . */ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java index 01b5b30..2e707e4 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java @@ -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 flatfiles; private ArrayList dbfiles; - public Configuration(AntiCheat plugin, AnticheatManager manager) { + public Configuration(AntiCheat plugin, AntiCheatManager manager) { removeOldFiles(); this.manager = manager; config = new Config(plugin, this); diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/files/Config.java b/src/main/java/net/gravitydevelopment/anticheat/config/files/Config.java index dac2076..127f376 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/files/Config.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/files/Config.java @@ -51,7 +51,7 @@ public class Config extends ConfigurationFile { public ConfigValue commandSpamActionOne; public ConfigValue commandSpamActionTwo; - public ConfigValue fileLogLevel; + public ConfigValue logToFile; public ConfigValue> disabledWorlds; @@ -85,7 +85,7 @@ public class Config extends ConfigurationFile { commandSpamActionOne = new ConfigValue("spam.command.action-one"); commandSpamActionTwo = new ConfigValue("spam.command.action-two"); - fileLogLevel = new ConfigValue("system.file-log-level"); + logToFile = new ConfigValue("system.log-to-file"); disabledWorlds = new ConfigValue>("disable-in"); } diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLLevelsHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLLevelsHolder.java index 6f8b179..595bdb0 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLLevelsHolder.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLLevelsHolder.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlLevelsHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlLevelsHolder.java index 5a7a513..cb38d20 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlLevelsHolder.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlLevelsHolder.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/providers/Levels.java b/src/main/java/net/gravitydevelopment/anticheat/config/providers/Levels.java index 5678199..88ad12d 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/providers/Levels.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/providers/Levels.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/event/BlockListener.java b/src/main/java/net/gravitydevelopment/anticheat/event/BlockListener.java index d346aa5..38d8ebb 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/event/BlockListener.java +++ b/src/main/java/net/gravitydevelopment/anticheat/event/BlockListener.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/event/EntityListener.java b/src/main/java/net/gravitydevelopment/anticheat/event/EntityListener.java index aa477e4..56c9fa3 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/event/EntityListener.java +++ b/src/main/java/net/gravitydevelopment/anticheat/event/EntityListener.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/event/EventListener.java b/src/main/java/net/gravitydevelopment/anticheat/event/EventListener.java index 6c9c7c8..38c15ae 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/event/EventListener.java +++ b/src/main/java/net/gravitydevelopment/anticheat/event/EventListener.java @@ -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(); } diff --git a/src/main/java/net/gravitydevelopment/anticheat/event/InventoryListener.java b/src/main/java/net/gravitydevelopment/anticheat/event/InventoryListener.java index a04583a..9ce3df0 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/event/InventoryListener.java +++ b/src/main/java/net/gravitydevelopment/anticheat/event/InventoryListener.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java b/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java index ce03186..8770c0f 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java +++ b/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/AnticheatManager.java b/src/main/java/net/gravitydevelopment/anticheat/manage/AntiCheatManager.java similarity index 61% rename from src/main/java/net/gravitydevelopment/anticheat/manage/AnticheatManager.java rename to src/main/java/net/gravitydevelopment/anticheat/manage/AntiCheatManager.java index b20d628..ce78d50 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/AnticheatManager.java +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/AntiCheatManager.java @@ -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 eventchains = new ConcurrentHashMap(); private static Map eventcache = new ConcurrentHashMap(); - private static List logs = new CopyOnWriteArrayList(); - 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 getLastLogs() { - List log = new CopyOnWriteArrayList(); - 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(); diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/CheckManager.java b/src/main/java/net/gravitydevelopment/anticheat/manage/CheckManager.java index 4cad59e..3eb0f42 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/CheckManager.java +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/CheckManager.java @@ -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 checkIgnoreList = new ArrayList(); private static Map> exemptList = new HashMap>(); 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(); } /** diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/LoggingManager.java b/src/main/java/net/gravitydevelopment/anticheat/manage/LoggingManager.java new file mode 100644 index 0000000..ca940b9 --- /dev/null +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/LoggingManager.java @@ -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 . + */ + +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 logs = new CopyOnWriteArrayList(); + 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 getLastLogs() { + List log = new CopyOnWriteArrayList(); + 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(); + } +} diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/PacketManager.java b/src/main/java/net/gravitydevelopment/anticheat/manage/PacketManager.java index bd3949d..4035f03 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/PacketManager.java +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/PacketManager.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java b/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java index 7ce142a..a3e4ce9 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java @@ -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 users = new ArrayList(); + 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 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 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 messageArray = new ArrayList(); + List 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 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(); diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/PastebinReport.java b/src/main/java/net/gravitydevelopment/anticheat/util/PastebinReport.java index 92c1b00..4283ee3 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/PastebinReport.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/PastebinReport.java @@ -102,7 +102,7 @@ public class PastebinReport { } private void appendLogs() { - List logs = AntiCheat.getManager().getLastLogs(); + List logs = AntiCheat.getManager().getLoggingManager().getLastLogs(); if (logs.size() == 0) { append("No recent logs."); return; diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java b/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java index 5e0e259..82fb6e8 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java @@ -59,6 +59,7 @@ public enum Permission { SYSTEM_UPDATE, SYSTEM_REPORT, SYSTEM_ALERT, + SYSTEM_NOTICE, SYSTEM_CALIBRATE, SYSTEM_DEBUG, SYSTEM_RELOAD; diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/User.java b/src/main/java/net/gravitydevelopment/anticheat/util/User.java similarity index 99% rename from src/main/java/net/gravitydevelopment/anticheat/manage/User.java rename to src/main/java/net/gravitydevelopment/anticheat/util/User.java index 9e7d684..cb79240 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/User.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/User.java @@ -16,9 +16,10 @@ * along with this program. If not, see . */ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java b/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java index 89aade8..12a9942 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java @@ -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); } } diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/enterprise/Database.java b/src/main/java/net/gravitydevelopment/anticheat/util/enterprise/Database.java index 37be4c7..7ec0750 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/enterprise/Database.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/enterprise/Database.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/rule/ConditionalRule.java b/src/main/java/net/gravitydevelopment/anticheat/util/rule/ConditionalRule.java index d0d2146..fb4e35a 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/rule/ConditionalRule.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/rule/ConditionalRule.java @@ -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; diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java b/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java index c41db08..07f3fdf 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java @@ -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; *

*

* Types of variables:
- * - 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
+ * - 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
* - Player: Contains LEVEL, the player's current level and CHECK, the check that was just failed *

*

diff --git a/src/main/java/net/gravitydevelopment/anticheat/xray/XRayListener.java b/src/main/java/net/gravitydevelopment/anticheat/xray/XRayListener.java index 2d00a0b..2708425 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/xray/XRayListener.java +++ b/src/main/java/net/gravitydevelopment/anticheat/xray/XRayListener.java @@ -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; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a637b52..b3da601 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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. diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 7927400..355796a 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -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.' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5a0d771..fe47aa7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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: