diff --git a/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java b/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java index b969209..2b70883 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java @@ -38,6 +38,7 @@ import org.bukkit.potion.PotionEffectType; import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.check.movement.FlightCheck; +import net.gravitydevelopment.anticheat.check.movement.YAxisCheck; import net.gravitydevelopment.anticheat.config.Configuration; import net.gravitydevelopment.anticheat.config.providers.Lang; import net.gravitydevelopment.anticheat.config.providers.Magic; @@ -57,10 +58,6 @@ public class Backend { private Map nofallViolation = new HashMap(); private Map speedViolation = new HashMap(); private Map fastBreakViolation = new HashMap(); - private Map yAxisViolations = new HashMap(); - private Map yAxisLastViolation = new HashMap(); - private Map lastYcoord = new HashMap(); - private Map lastYtime = new HashMap(); private Map fastBreaks = new HashMap(); private Map blockBreakHolder = new HashMap(); private Map lastBlockBroken = new HashMap(); @@ -138,10 +135,10 @@ public class Backend { FlightCheck.blocksOverFlight.remove(pN); nofallViolation.remove(pN); fastBreakViolation.remove(pN); - yAxisViolations.remove(pN); - yAxisLastViolation.remove(pN); - lastYcoord.remove(pN); - lastYtime.remove(pN); + YAxisCheck.yAxisViolations.remove(pN); + YAxisCheck.yAxisLastViolation.remove(pN); + YAxisCheck.lastYcoord.remove(pN); + YAxisCheck.lastYtime.remove(pN); fastBreaks.remove(pN); blockBreakHolder.remove(pN); lastBlockBroken.remove(pN); @@ -452,63 +449,6 @@ public class Backend { return PASS; } - public CheckResult checkYAxis(Player player, Distance distance) { - if (distance.getYDifference() > magic.TELEPORT_MIN() || distance.getYDifference() < 0) { - return PASS; - } - if (!isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) && !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player)) { - double y1 = player.getLocation().getY(); - String name = player.getName(); - // Fix Y axis spam. - if (!lastYcoord.containsKey(name) || !lastYtime.containsKey(name) || !yAxisLastViolation.containsKey(name) || !yAxisLastViolation.containsKey(name)) { - lastYcoord.put(name, y1); - yAxisViolations.put(name, 0); - yAxisLastViolation.put(name, 0L); - lastYtime.put(name, System.currentTimeMillis()); - } else { - if (y1 > lastYcoord.get(name) && yAxisViolations.get(name) > magic.Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(name)) < magic.Y_MAXVIOTIME()) { - Location g = player.getLocation(); - yAxisViolations.put(name, yAxisViolations.get(name) + 1); - yAxisLastViolation.put(name, System.currentTimeMillis()); - if (!silentMode()) { - g.setY(lastYcoord.get(name)); - player.sendMessage(ChatColor.RED + "[AntiCheat] Fly hacking on the y-axis detected. Please wait 5 seconds to prevent getting damage."); - if (g.getBlock().getType() == Material.AIR) { - player.teleport(g); - } - } - 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); - yAxisLastViolation.put(name, 0L); - } - } - long i = System.currentTimeMillis() - lastYtime.get(name); - double diff = magic.Y_MAXDIFF() + (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0); - if ((y1 - lastYcoord.get(name)) > diff && i < magic.Y_TIME()) { - Location g = player.getLocation(); - yAxisViolations.put(name, yAxisViolations.get(name) + 1); - yAxisLastViolation.put(name, System.currentTimeMillis()); - if (!silentMode()) { - g.setY(lastYcoord.get(name)); - if (g.getBlock().getType() == Material.AIR) { - player.teleport(g); - } - } - 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()); - lastYcoord.put(name, y1); - } - } - } - } - // Fix Y axis spam - return PASS; - } - public CheckResult checkTimer(Player player) { String name = player.getName(); int step = 1; @@ -987,10 +927,10 @@ public class Backend { /* Data for fly/speed should be reset */ nofallViolation.remove(player.getName()); FlightCheck.blocksOverFlight.remove(player.getName()); - yAxisViolations.remove(player.getName()); - yAxisLastViolation.remove(player.getName()); - lastYcoord.remove(player.getName()); - lastYtime.remove(player.getName()); + YAxisCheck.yAxisViolations.remove(player.getName()); + YAxisCheck.yAxisLastViolation.remove(player.getName()); + YAxisCheck.lastYcoord.remove(player.getName()); + YAxisCheck.lastYtime.remove(player.getName()); } public void logExitFly(final Player player) { diff --git a/src/main/java/net/gravitydevelopment/anticheat/check/CheckType.java b/src/main/java/net/gravitydevelopment/anticheat/check/CheckType.java index b1b3698..6a2b3eb 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/check/CheckType.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/CheckType.java @@ -57,7 +57,8 @@ public enum CheckType { FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE), ITEM_SPAM(Permission.CHECK_ITEMSPAM), FAST_INVENTORY(Permission.CHECK_FASTINVENTORY), - AUTOTOOL(Permission.CHECK_AUTOTOOL); + AUTOTOOL(Permission.CHECK_AUTOTOOL), + GLIDE(Permission.CHECK_GLIDE); private final Permission permission; private final Map level = new HashMap(); diff --git a/src/main/java/net/gravitydevelopment/anticheat/check/movement/FlightCheck.java b/src/main/java/net/gravitydevelopment/anticheat/check/movement/FlightCheck.java index 11b72d9..d09d1ea 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/check/movement/FlightCheck.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/movement/FlightCheck.java @@ -49,7 +49,7 @@ public class FlightCheck { return PASS; } - private static boolean isMovingExempt(Player player) { + public static boolean isMovingExempt(Player player) { return isDoing(player, movingExempt, -1); } diff --git a/src/main/java/net/gravitydevelopment/anticheat/check/movement/GlideCheck.java b/src/main/java/net/gravitydevelopment/anticheat/check/movement/GlideCheck.java new file mode 100644 index 0000000..292f578 --- /dev/null +++ b/src/main/java/net/gravitydevelopment/anticheat/check/movement/GlideCheck.java @@ -0,0 +1,25 @@ +package net.gravitydevelopment.anticheat.check.movement; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.entity.Player; + +import net.gravitydevelopment.anticheat.AntiCheat; +import net.gravitydevelopment.anticheat.check.CheckResult; +import net.gravitydevelopment.anticheat.util.Distance; + +/** + * + * @author Marco STILL IN ALPHA TESTING! + */ +public class GlideCheck { + + private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); + + public static CheckResult runCheck(Player player, Distance distance) { + return PASS; + // TODO + } + +} diff --git a/src/main/java/net/gravitydevelopment/anticheat/check/movement/YAxisCheck.java b/src/main/java/net/gravitydevelopment/anticheat/check/movement/YAxisCheck.java new file mode 100644 index 0000000..5ec9acd --- /dev/null +++ b/src/main/java/net/gravitydevelopment/anticheat/check/movement/YAxisCheck.java @@ -0,0 +1,90 @@ +package net.gravitydevelopment.anticheat.check.movement; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; + +import net.gravitydevelopment.anticheat.AntiCheat; +import net.gravitydevelopment.anticheat.check.CheckResult; +import net.gravitydevelopment.anticheat.util.Distance; +import net.gravitydevelopment.anticheat.util.Utilities; + +/** + * The suckishness and false-positives of this check are killing me. TODO TODO TODO FIX THIS!!!1! + */ +public class YAxisCheck { + + private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); + + public static Map lastYcoord = new HashMap(); + public static Map lastYtime = new HashMap(); + public static Map yAxisViolations = new HashMap(); + public static Map yAxisLastViolation = new HashMap(); + + private static boolean hasJumpPotion(Player player) { + return player.hasPotionEffect(PotionEffectType.JUMP); + } + + public static CheckResult runCheck(Player player, Distance distance) { + if (distance.getYDifference() > AntiCheat.getManager().getBackend().getMagic().TELEPORT_MIN() || distance.getYDifference() < 0) { + return PASS; + } + if (!FlightCheck.isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) && !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player)) { + double y1 = player.getLocation().getY(); + String name = player.getName(); + // Fix Y axis spam. + if (!lastYcoord.containsKey(name) || !lastYtime.containsKey(name) || !yAxisLastViolation.containsKey(name) || !yAxisLastViolation.containsKey(name)) { + lastYcoord.put(name, y1); + yAxisViolations.put(name, 0); + yAxisLastViolation.put(name, 0L); + lastYtime.put(name, System.currentTimeMillis()); + } else { + if (y1 > lastYcoord.get(name) && yAxisViolations.get(name) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(name)) < AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOTIME()) { + Location g = player.getLocation(); + yAxisViolations.put(name, yAxisViolations.get(name) + 1); + yAxisLastViolation.put(name, System.currentTimeMillis()); + if (!AntiCheat.getManager().getBackend().silentMode()) { + g.setY(lastYcoord.get(name)); + player.sendMessage(ChatColor.RED + "[AntiCheat] Fly hacking on the y-axis detected. Please wait 5 seconds to prevent getting damage."); + if (g.getBlock().getType() == Material.AIR) { + player.teleport(g); + } + } + return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis " + yAxisViolations.get(name) + " times (max =" + AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() + ")"); + } else { + if (yAxisViolations.get(name) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(name)) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOTIME()) { + yAxisViolations.put(name, 0); + yAxisLastViolation.put(name, 0L); + } + } + long i = System.currentTimeMillis() - lastYtime.get(name); + double diff = AntiCheat.getManager().getBackend().getMagic().Y_MAXDIFF() + (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0); + if ((y1 - lastYcoord.get(name)) > diff && i < AntiCheat.getManager().getBackend().getMagic().Y_TIME()) { + Location g = player.getLocation(); + yAxisViolations.put(name, yAxisViolations.get(name) + 1); + yAxisLastViolation.put(name, System.currentTimeMillis()); + if (!AntiCheat.getManager().getBackend().silentMode()) { + g.setY(lastYcoord.get(name)); + if (g.getBlock().getType() == Material.AIR) { + player.teleport(g); + } + } + return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + AntiCheat.getManager().getBackend().getMagic().Y_TIME() + ")"); + } else { + if ((y1 - lastYcoord.get(name)) > AntiCheat.getManager().getBackend().getMagic().Y_MAXDIFF() + 1 || (System.currentTimeMillis() - lastYtime.get(name)) > AntiCheat.getManager().getBackend().getMagic().Y_TIME()) { + lastYtime.put(name, System.currentTimeMillis()); + lastYcoord.put(name, y1); + } + } + } + } + // Fix Y axis spam + return PASS; + } + +} diff --git a/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java b/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java index bba189f..1ff6971 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java +++ b/src/main/java/net/gravitydevelopment/anticheat/event/PlayerListener.java @@ -55,6 +55,8 @@ import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.check.CheckResult; import net.gravitydevelopment.anticheat.check.CheckType; import net.gravitydevelopment.anticheat.check.movement.FlightCheck; +import net.gravitydevelopment.anticheat.check.movement.GlideCheck; +import net.gravitydevelopment.anticheat.check.movement.YAxisCheck; import net.gravitydevelopment.anticheat.util.Distance; import net.gravitydevelopment.anticheat.util.Permission; import net.gravitydevelopment.anticheat.util.User; @@ -343,6 +345,15 @@ public class PlayerListener extends EventListener { log(result.getMessage(), player, CheckType.FLY); } } + if (getCheckManager().willCheckQuick(player, CheckType.GLIDE) && !player.isFlying() && (Bukkit.getVersion().contains("1.9") && !player.isGliding()) /*TODO: ElytraFly check, this is a quick workaround */) { + CheckResult result = GlideCheck.runCheck(player, distance); + if (result.failed()) { + if (!silentMode()) { + event.setTo(user.getGoodLocation(from.clone())); + } + log(result.getMessage(), player, CheckType.GLIDE); + } + } if (getCheckManager().willCheckQuick(player, CheckType.VCLIP) && event.getFrom().getY() > event.getTo().getY()) { CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo())); if (result.failed()) { @@ -459,7 +470,7 @@ public class PlayerListener extends EventListener { } if (getCheckManager().willCheck(player, CheckType.FLY) && !player.isFlying()) { - CheckResult result1 = getBackend().checkYAxis(player, new Distance(from, to)); + CheckResult result1 = YAxisCheck.runCheck(player, new Distance(from, to)); CheckResult result2 = getBackend().checkAscension(player, from.getY(), to.getY()); String log = result1.failed() ? result1.getMessage() : result2.failed() ? result2.getMessage() : ""; if (!log.equals("")) { diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java b/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java index 1708ff7..dcccb9b 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/Permission.java @@ -48,6 +48,7 @@ public enum Permission { CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, + CHECK_GLIDE, /* System Nodes */ SYSTEM_LOG, diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dde8a56..e45607b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,14 +1,13 @@ -# AntiCheat configuration file -# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues +# AntiCheatReloaded configuration file spam: chat: - # Should AntiCheat block players spamming messages in chat? + # Should AntiCheatReloaded block players spamming messages in chat? block-speed: true block-repetition: true # Valid actions = NONE,KICK,BAN,COMMAND[command] action-one: KICK action-two: BAN - # Should AntiCheat block players spamming commands in chat? + # Should AntiCheatReloaded block players spamming commands in chat? command: block-speed: true block-repetition: true @@ -18,22 +17,22 @@ spam: system: # Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so, and will have to update manually. auto-update: true - # Should AntiCheat log ALL failed checks to console? + # Should AntiCheatReloaded log ALL failed checks to console? log-to-console: false - # Should AntiCheat log to file? + # Should AntiCheatReloaded log to file? log-to-file: true - # Should AntiCheat display extra debug information when starting? + # Should AntiCheatReloaded 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. + # If silent mode is on, players will not be stopped when they try to hack, and AntiCheatReloaded will do everything possible to keep them unaware of their rising hack level. # However, alerts will still be sent to console and to admins online, and events will still take place. silent-mode: false # Should ops be exempt from all checks? exempt-op: false - # Should AntiCheat track plugins in its own registered events? + # Should AntiCheatReloaded track plugins in its own registered events? event-chains: true # Should Enterprise options be enabled? Only set this to true if you're an advanced user. enterprise: false -# Use /anticheat check for a list of valid checks +# Use /AntiCheatReloaded check for a list of valid checks disabled-checks: - EXAMPLE_CHECK disable-in: diff --git a/src/main/resources/groups.yml b/src/main/resources/groups.yml index 29d0e63..cd3b2ba 100644 --- a/src/main/resources/groups.yml +++ b/src/main/resources/groups.yml @@ -1,5 +1,4 @@ -# AntiCheat configuration file -# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues +# AntiCheatReloaded configuration file groups: - 'Medium : 20 : YELLOW : WARN' - 'High : 50 : RED : KICK' diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index c7f261a..4252b52 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -1,15 +1,14 @@ -# AntiCheat language file -# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues +# AntiCheatReloaded language file ALERT: - '&player has just entered the &group hack group.' - '&player''s last failed check was: &check.' - 'Type ''/anticheat report &player'' for more information.' WARNING: -- '[AntiCheat] Hacking is not permitted.' -- '[AntiCheat] If you continue to hack, action will be taken.' -BAN_REASON: 'Banned by AntiCheat' +- '[AntiCheatReloaded] Hacking is not permitted.' +- '[AntiCheatReloaded] If you continue to hack, action will be taken.' +BAN_REASON: 'Banned by AntiCheatReloaded' BAN_BROADCAST: '&player was banned for hacking.' -KICK_REASON: 'Kicked by AntiCheat' +KICK_REASON: 'Kicked by AntiCheatReloaded' KICK_BROADCAST: '&player was kicked for hacking.' SPAM_WARNING: 'Stop spamming the server or you will be kicked!' SPAM_KICK_REASON: 'Kicked for spamming' diff --git a/src/main/resources/magic.yml b/src/main/resources/magic.yml index 2114b90..c6ddd6d 100644 --- a/src/main/resources/magic.yml +++ b/src/main/resources/magic.yml @@ -1,6 +1,4 @@ -# AntiCheat configuration file -# Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/ -# Documentation for these values is available at http://gravitydevelopment.net/docs/anticheat/net/gravitydevelopment/anticheat/config/providers/Magic.html +# AntiCheatReloaded configuration file ANIMATION_INTERACT_MAX: 3 ANIMATION_MIN: 200 ASCENSION_COUNT_MAX: 8 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3c5a25f..7afb611 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ -author: Gravity -description: AntiCheat helps easily identify and block malicious users on your server. +name: AntiCheatReloaded +author: Rammelkast +description: AntiCheatReloaded helps easily identify and block malicious users on your server. main: net.gravitydevelopment.anticheat.AntiCheat -name: AntiCheat softdepend: [ProtocolLib] startup: postworld url: http://gravitydevelopment.net diff --git a/src/main/resources/rules.yml b/src/main/resources/rules.yml index ac0c79d..fc45a2f 100644 --- a/src/main/resources/rules.yml +++ b/src/main/resources/rules.yml @@ -1,5 +1,4 @@ -# AntiCheat configuration file -# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues +# AntiCheatReloaded rules file rules: # if spider check is less than 0, set group to 20. otherwise, do nothing - 'Check_SPIDER < 0 ? Player.KICK : null'