From 9253a93fe079970ffee133145667c942364758e2 Mon Sep 17 00:00:00 2001 From: h31ix Date: Sat, 29 Sep 2012 14:43:29 -0400 Subject: [PATCH] Fixed descending waterfalls (or climbing out of them to get air) and a few logging issues. --- .../anticheat/manage/AnticheatManager.java | 21 ++++++--- .../net/h31ix/anticheat/manage/Backend.java | 45 ++++++++++--------- .../java/net/h31ix/anticheat/manage/User.java | 7 +-- .../net/h31ix/anticheat/util/Utilities.java | 7 +++ 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java index 5a10f84..3336852 100644 --- a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java @@ -77,16 +77,25 @@ public class AnticheatManager fileLogger.setUseParentHandlers(false); fileLogger.addHandler(fileHandler); } - + public void log(String message) + { + log(message, 0); + } + + public void log(String message, int i) { if (getConfiguration().logConsole()) { Bukkit.getConsoleSender().sendMessage(ChatColor.RED+message); - } - if (getConfiguration().getFileLogLevel() == LOG_LEVEL_HIGH) + } + if(i == 0 && getConfiguration().getFileLogLevel() == LOG_LEVEL_HIGH) // Not an alert, normal log message { - fileLog(ChatColor.stripColor(message)); + fileLog(message); + } + else if(getConfiguration().getFileLogLevel() != 0)// alert + { + fileLog(message); } logs.add(ChatColor.stripColor(message)); } @@ -103,9 +112,9 @@ public class AnticheatManager { return logs; } - for(int i = 1; i < 31; i++) + for(int i = logs.size()-1; i >= 0; i--) { - log.add(logs.get(logs.size() - i)); + log.add(logs.get(i)); } logs.clear(); return log; diff --git a/src/main/java/net/h31ix/anticheat/manage/Backend.java b/src/main/java/net/h31ix/anticheat/manage/Backend.java index 91d5353..39fe40e 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Backend.java +++ b/src/main/java/net/h31ix/anticheat/manage/Backend.java @@ -591,39 +591,42 @@ public class Backend String name = player.getName(); int y1 = (int)distance.fromY(); int y2 = (int)distance.toY(); - if(!isMovingExempt(player) && (y1 == y2 || y1 < y2) && !Utilities.isInWater(player) && !Utilities.canStand(player.getLocation().getBlock()) && Utilities.cantStandAt(player.getLocation().add(0, -1, 0).getBlock()) && Utilities.cantStandAt(player.getLocation().add(0, -2, 0).getBlock())) + if(!isMovingExempt(player) && !Utilities.isInWater(player) && !Utilities.canStand(player.getLocation().getBlock()) && Utilities.cantStandAt(player.getLocation().add(0, -1, 0).getBlock()) && Utilities.cantStandAt(player.getLocation().add(0, -2, 0).getBlock())) { Block block = player.getLocation().getBlock(); //Check if the player is climbing up water. if(block.getRelative(BlockFace.NORTH).isLiquid() || block.getRelative(BlockFace.SOUTH).isLiquid() || block.getRelative(BlockFace.EAST).isLiquid() || block.getRelative(BlockFace.WEST).isLiquid()) { - //Even if they are using a hacked client and flying next to water to abuse this, they can't be go past the speed limit so they might as well swim - return distance.getYDifference() > magic.WATER_CLIMB_MAX; + if(y1 < y2) + { + //Even if they are using a hacked client and flying next to water to abuse this, they can't be go past the speed limit so they might as well swim + return distance.getYDifference() > magic.WATER_CLIMB_MAX; + } } - //Check if the player is crouching on slabs - if(player.isSneaking()) + else if(y1 == y2 || y1 < y2) { - if(block.getRelative(BlockFace.NORTH).getTypeId() == 43 || block.getRelative(BlockFace.NORTH).getTypeId() == 44 || block.getRelative(BlockFace.SOUTH).getTypeId() == 43 || block.getRelative(BlockFace.SOUTH).getTypeId() == 44 || block.getRelative(BlockFace.EAST).getTypeId() == 43 || block.getRelative(BlockFace.EAST).getTypeId() == 44 || block.getRelative(BlockFace.WEST).getTypeId() == 43 || block.getRelative(BlockFace.WEST).getTypeId() == 44) + //Check if the player is crouching on slabs + if(player.isSneaking()) + { + if(block.getRelative(BlockFace.NORTH).getTypeId() == 43 || block.getRelative(BlockFace.NORTH).getTypeId() == 44 || block.getRelative(BlockFace.SOUTH).getTypeId() == 43 || block.getRelative(BlockFace.SOUTH).getTypeId() == 44 || block.getRelative(BlockFace.EAST).getTypeId() == 43 || block.getRelative(BlockFace.EAST).getTypeId() == 44 || block.getRelative(BlockFace.WEST).getTypeId() == 43 || block.getRelative(BlockFace.WEST).getTypeId() == 44) + { + return false; + } + } + int violation = flightViolation.containsKey(name) ? flightViolation.get(name)+1 : 1; + increment(player, flightViolation, violation); + if(violation > magic.FLIGHT_LIMIT) + { + return true; + } + else { return false; } } - int violation = flightViolation.containsKey(name) ? flightViolation.get(name)+1 : 1; - increment(player, flightViolation, violation); - if(violation > magic.FLIGHT_LIMIT) - { - return true; - } - else - { - return false; - } - } - else - { - flightViolation.put(name, 0); - return false; } + flightViolation.put(name, 0); + return false; } public void logAscension(Player player, double y1, double y2) diff --git a/src/main/java/net/h31ix/anticheat/manage/User.java b/src/main/java/net/h31ix/anticheat/manage/User.java index 8ae3b6b..8c89ab4 100644 --- a/src/main/java/net/h31ix/anticheat/manage/User.java +++ b/src/main/java/net/h31ix/anticheat/manage/User.java @@ -80,19 +80,14 @@ public class User if(level == med) { Anticheat.getManager().getUserManager().alertMed(this, type); - return true; } else if(level == high) { Anticheat.getManager().getUserManager().alertHigh(this, type); // Prevent the player from going over the high limit level = high-10; - return true; - } - else - { - return true; } + return true; } } diff --git a/src/main/java/net/h31ix/anticheat/util/Utilities.java b/src/main/java/net/h31ix/anticheat/util/Utilities.java index 11f9843..f4a5d87 100644 --- a/src/main/java/net/h31ix/anticheat/util/Utilities.java +++ b/src/main/java/net/h31ix/anticheat/util/Utilities.java @@ -52,6 +52,13 @@ public final class Utilities Anticheat.getManager().log(msg); } } + if (Anticheat.getManager().getConfiguration().getFileLogLevel() != 0) + { + for (String msg : message) + { + Anticheat.getManager().log(msg, 1); + } + } } public static boolean cantStandAt(Block block)