diff --git a/src/main/java/net/h31ix/anticheat/Anticheat.java b/src/main/java/net/h31ix/anticheat/Anticheat.java index 3103d1e..b6f5b13 100644 --- a/src/main/java/net/h31ix/anticheat/Anticheat.java +++ b/src/main/java/net/h31ix/anticheat/Anticheat.java @@ -270,10 +270,10 @@ public class Anticheat extends JavaPlugin { logger.log(Level.INFO, "[AC] Checking for updates..."); } - URL url = null; - URLConnection urlConn = null; + URL url; + URLConnection urlConn; InputStreamReader inStream = null; - BufferedReader buff = null; + BufferedReader buff; String v = ""; try { diff --git a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java index 1fe9490..b961ab1 100644 --- a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java +++ b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java @@ -27,20 +27,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerBedEnterEvent; -import org.bukkit.event.player.PlayerBedLeaveEvent; -import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.event.player.*; import org.bukkit.inventory.PlayerInventory; public class PlayerListener extends EventListener @@ -209,6 +197,7 @@ public class PlayerListener extends EventListener double x = distance.getXDifference(); double y = distance.getYDifference(); double z = distance.getZDifference(); + backend.checkAscension(player,from.getY(),to.getY()); if(checkManager.willCheck(player, CheckType.FLY) && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && backend.checkFlight(player, distance)) { from.setX(from.getX()-1); @@ -272,7 +261,7 @@ public class PlayerListener extends EventListener } } @EventHandler(ignoreCancelled = true) - public void checkDirSpeed(PlayerMoveEvent event) + public void checkSpeed(PlayerMoveEvent event) { Player player = event.getPlayer(); Location from = event.getFrom(); diff --git a/src/main/java/net/h31ix/anticheat/manage/Backend.java b/src/main/java/net/h31ix/anticheat/manage/Backend.java index 6641162..5e2195d 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Backend.java +++ b/src/main/java/net/h31ix/anticheat/manage/Backend.java @@ -67,6 +67,9 @@ public class Backend private static final int Y_MAXVIOTIME = 5000; private static final int NOFALL_LIMIT = 5; + private static final int WATER_ASCENSION_VIOLATION_MAX = 13; + private static final int WATER_SPEED_VIOLATION_MAX = 4; + private static final int SPRINT_FOOD_MIN = 6; private static final int EAT_MIN = 20; private static final int HEAL_MIN = 35; @@ -109,6 +112,7 @@ public class Backend private List isInWater = new ArrayList(); private List isInWaterCache = new ArrayList(); private List instantBreakExempt = new ArrayList(); + private List isAscending = new ArrayList(); private Map oldMessage = new HashMap(); private Map lastMessage = new HashMap(); private Map flightViolation = new HashMap(); @@ -127,6 +131,8 @@ public class Backend private Map lastBlockPlaced = new HashMap(); private Map lastBlockPlaceTime = new HashMap(); private Map blockPunches = new HashMap(); + private Map waterAscensionViolation = new HashMap(); + private Map waterSpeedViolation = new HashMap(); public Backend(AnticheatManager instance) { @@ -251,47 +257,94 @@ public class Backend public boolean checkWaterWalk(Player player, double x, double z) { Block block = player.getLocation().getBlock(); - if(block.isLiquid() && player.getVehicle() == null) + if(player.getVehicle() == null && !player.isFlying()) { - if(isInWater.contains(player.getName())) + if(block.isLiquid() && block.getRelative(BlockFace.DOWN).isLiquid()) { - if(isInWaterCache.contains(player.getName())) - { - if(x > XZ_SPEED_MAX_WATER || z > XZ_SPEED_MAX_WATER && !Utilities.sprintFly(player) && player.getNearbyEntities(1, 1, 1).isEmpty()) - { - return true; - } - else if(x > XZ_SPEED_MAX_WATER_SPRINT || z > XZ_SPEED_MAX_WATER_SPRINT) - { - return true; - } + if(isInWater.contains(player.getName())) + { + if(isInWaterCache.contains(player.getName())) + { + if(player.getNearbyEntities(1, 1, 1).isEmpty()) + { + boolean b = false; + if(!Utilities.sprintFly(player) && x > XZ_SPEED_MAX_WATER || z > XZ_SPEED_MAX_WATER) + { + b = true; + } + else if(x > XZ_SPEED_MAX_WATER_SPRINT || z > XZ_SPEED_MAX_WATER_SPRINT) + { + b = true; + } + if(b) + { + if(waterSpeedViolation.containsKey(player.getName())) + { + int v = waterSpeedViolation.get(player.getName()); + if(v >= WATER_SPEED_VIOLATION_MAX) + { + waterSpeedViolation.put(player.getName(), 0); + return true; + } + else + { + waterSpeedViolation.put(player.getName(), v+1); + } + } + else + { + waterSpeedViolation.put(player.getName(), 1); + } + } + } + } + else + { + isInWaterCache.add(player.getName()); + return false; + } } else { - isInWaterCache.add(player.getName()); + isInWater.add(player.getName()); return false; } } + else if (block.getRelative(BlockFace.DOWN).isLiquid() && isAscending(player) && Utilities.cantStandAt(block) && Utilities.cantStandAt(block.getRelative(BlockFace.DOWN))) + { + if(waterAscensionViolation.containsKey(player.getName())) + { + int v = waterAscensionViolation.get(player.getName()); + if(v >= WATER_ASCENSION_VIOLATION_MAX) + { + waterAscensionViolation.put(player.getName(), 0); + return true; + } + else + { + waterAscensionViolation.put(player.getName(), v+1); + } + } + else + { + waterAscensionViolation.put(player.getName(), 1); + } + } else { - isInWater.add(player.getName()); - return false; + isInWater.remove(player.getName()); + isInWaterCache.remove(player.getName()); } - } - isInWater.remove(player.getName()); - isInWaterCache.remove(player.getName()); return false; } public boolean checkYAxis(Player player, Distance distance) { - //Arrow to the knee check - if(distance.getYDifference() > 400) { - //teleport. so just cancel. + if(distance.getYDifference() > 400) + { return false; } - if(!isMovingExempt(player)) { double y1 = player.getLocation().getY(); @@ -405,6 +458,18 @@ public class Backend return false; } + public void checkAscension(Player player, double y1, double y2) + { + if(y1 < y2) + { + isAscending.add(player.getName()); + } + else + { + isAscending.remove(player.getName()); + } + } + public boolean checkSwing(Player player, Block block) { return !player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !Utilities.isInstantBreak(block.getType()) && !justAnimated(player); @@ -712,6 +777,11 @@ public class Backend return movingExempt.contains(player.getName()) || player.isFlying(); } + public boolean isAscending(Player player) + { + return isAscending.contains(player.getName()); + } + public boolean isSpeedExempt(Player player) { return movingExempt.contains(player.getName()); } diff --git a/src/main/java/net/h31ix/anticheat/manage/Utilities.java b/src/main/java/net/h31ix/anticheat/manage/Utilities.java index 8aca6b6..b6747c5 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Utilities.java +++ b/src/main/java/net/h31ix/anticheat/manage/Utilities.java @@ -73,11 +73,11 @@ public final class Utilities { return !canStand(block) && cantStandClose(block) && cantStandFar(block); } - private static boolean cantStandClose(Block block) + public static boolean cantStandClose(Block block) { return !canStand(block.getRelative(BlockFace.NORTH)) && !canStand(block.getRelative(BlockFace.EAST)) && !canStand(block.getRelative(BlockFace.SOUTH)) && !canStand(block.getRelative(BlockFace.WEST)); } - private static boolean cantStandFar(Block block) + public static boolean cantStandFar(Block block) { return !canStand(block.getRelative(BlockFace.NORTH_WEST)) && !canStand(block.getRelative(BlockFace.NORTH_EAST)) && !canStand(block.getRelative(BlockFace.SOUTH_WEST)) && !canStand(block.getRelative(BlockFace.SOUTH_EAST)); }