From 2d34799a87056c6046f333072558fe3eb1b524ea Mon Sep 17 00:00:00 2001 From: Evenprime Date: Tue, 22 Feb 2011 15:08:08 +0100 Subject: [PATCH] Check against building in air + more configuration options + less noisy logging. --- .../bukkit/nocheat/BlockPlacingCheck.java | 16 ++++++-- .../evenprime/bukkit/nocheat/MovingCheck.java | 37 +++++++++++++------ .../bukkit/nocheat/NoCheatConfiguration.java | 10 +++++ .../nocheat/NoCheatPluginBlockListener.java | 2 +- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/cc/co/evenprime/bukkit/nocheat/BlockPlacingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/BlockPlacingCheck.java index 6e7cbf2b..f033f8d3 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/BlockPlacingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/BlockPlacingCheck.java @@ -1,6 +1,8 @@ package cc.co.evenprime.bukkit.nocheat; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.event.block.BlockPlaceEvent; public class BlockPlacingCheck { @@ -15,10 +17,18 @@ public class BlockPlacingCheck { return; } - if(event.getBlockAgainst().getType() == Material.AIR) { + Location l = event.getBlockPlaced().getLocation(); + World w = event.getBlock().getWorld(); + int airId = Material.AIR.getId(); + + if(w.getBlockTypeIdAt(l.getBlockX()-1, l.getBlockY(), l.getBlockZ()) == airId && + w.getBlockTypeIdAt(l.getBlockX()+1, l.getBlockY(), l.getBlockZ()) == airId && + w.getBlockTypeIdAt(l.getBlockX(), l.getBlockY()-1, l.getBlockZ()) == airId && + w.getBlockTypeIdAt(l.getBlockX(), l.getBlockY()+1, l.getBlockZ()) == airId && + w.getBlockTypeIdAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()-1) == airId && + w.getBlockTypeIdAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()+1) == airId) { event.setCancelled(true); - NoCheatPlugin.log.warning("NoCheatPlugin: Airbuild violation: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " against air"); - + NoCheatPlugin.log.warning("NoCheatPlugin: Airbuild violation: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " in the air"); } } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/MovingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/MovingCheck.java index 9637fe8c..581059e7 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/MovingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/MovingCheck.java @@ -18,6 +18,8 @@ public class MovingCheck { private static final int MINOR = 1; private static final int NONE = 0; + private static final int freeIllegalMoves = 1; + private enum BlockType { SOLID, NONSOLID, LADDER, LIQUID, UNKNOWN; } @@ -225,9 +227,8 @@ public class MovingCheck { else if(offset > 0.6D) vl = vl > NORMAL ? vl : NORMAL; else vl = vl > MINOR ? vl : MINOR; } - else { - data.phase++; // Enter next phase of the flight - } + + data.phase++; // Enter next phase of the flight } // do a security check on the jumping phase, such that we don't get @@ -260,27 +261,33 @@ public class MovingCheck { data.movingSetBackPoint = event.getFrom().clone(); } + // Start logging only after the freebee illegal moves are over + if(data.minorViolationsInARow == freeIllegalMoves + 1) { + NoCheatPlugin.log.info("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ())); + + } + data.minorViolationsInARow++; + // 16 minor violations in a row count as one normal violation if(data.minorViolationsInARow % 16 == 0) { normalViolation(data, event); } - else if(data.minorViolationsInARow % 2 == 0) { + else if(data.minorViolationsInARow % (freeIllegalMoves+1) == 0) { // now we need it - NoCheatPlugin.log.info("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ())); resetPlayer(data, event); } } protected static void normalViolation(NoCheatPluginData data, PlayerMoveEvent event) { // Log the first violation in a row - if(data.normalViolationsInARow <= 1) + if(data.normalViolationsInARow == 0) NoCheatPlugin.log.warning("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ())); resetPlayer(data, event); data.normalViolationsInARow++; - } + } protected static void heavyViolation(NoCheatPluginData data, PlayerMoveEvent event) { @@ -303,9 +310,14 @@ public class MovingCheck { NoCheatPlugin.log.warning("NoCheatPlugin: Moving violation stopped: "+event.getPlayer().getName()+ " total Events: "+ data.normalViolationsInARow); data.normalViolationsInARow = 0; } - data.minorViolationsInARow = 0; - data.normalViolationsInARow = 0; - data.heavyViolationsInARow = 0; + else if(data.minorViolationsInARow > freeIllegalMoves) { + NoCheatPlugin.log.info("NoCheatPlugin: Moving violation stopped: "+event.getPlayer().getName()+ " total Events: "+ data.minorViolationsInARow); + data.minorViolationsInARow = 0; + } + else { + data.minorViolationsInARow = 0; + } + data.movingSetBackPoint = null; } @@ -316,7 +328,10 @@ public class MovingCheck { * @param event */ private static void resetPlayer(NoCheatPluginData data, PlayerMoveEvent event) { - + + // If we only log, we never reset the player to his original location + if(NoCheatConfiguration.movingLogOnly) return; + if(data.phase > 7) { data.phase = 7; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java index 481f786d..a449aa15 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java @@ -18,6 +18,8 @@ public class NoCheatConfiguration { public static boolean speedhackCheckActive = true; public static boolean movingCheckActive = true; + public static boolean airbuildCheckActive = false; + public static int speedhackInterval = 2000; public static int speedhackLow = 60; public static int speedhackMed = 90; @@ -27,6 +29,8 @@ public class NoCheatConfiguration { public static double movingDistanceMed = 1.0D; public static double movingDistanceHigh = 5.0D; + public static boolean movingLogOnly = false; + private static ConsoleHandler ch = null; private static FileHandler fh = null; @@ -66,11 +70,14 @@ public class NoCheatConfiguration { speedhackCheckActive = c.getBoolean("active.speedhack", true); movingCheckActive = c.getBoolean("active.moving", true); + airbuildCheckActive = c.getBoolean("active.airbuild", false); speedhackInterval = c.getInt("speedhack.interval", 2000); speedhackLow = c.getInt("speedhack.limits.low", 60); speedhackMed = c.getInt("speedhack.limits.med", 90); speedhackHigh = c.getInt("speedhack.limits.high", 120); + + movingLogOnly = c.getBoolean("moving.logonly", false); } private static Level stringToLevel(String string) { @@ -100,6 +107,7 @@ public class NoCheatConfiguration { w.write("active:"); w.newLine(); w.write(" speedhack: true"); w.newLine(); w.write(" moving: true"); w.newLine(); + w.write(" airbuild: false"); w.newLine(); w.write("# Speedhack: interval in milliseconds, limits are events in that interval") ;w.newLine(); w.write("speedhack:"); w.newLine(); w.write(" interval: 2000"); w.newLine(); @@ -107,6 +115,8 @@ public class NoCheatConfiguration { w.write(" low: 60"); w.newLine(); w.write(" med: 90"); w.newLine(); w.write(" high: 120"); w.newLine(); + w.write("moving:"); w.newLine(); + w.write(" logonly: false"); w.newLine(); w.flush(); w.close(); } catch (IOException e) { // TODO Auto-generated catch block diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginBlockListener.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginBlockListener.java index f7b79b5a..ca9f1c5a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginBlockListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginBlockListener.java @@ -13,7 +13,7 @@ public class NoCheatPluginBlockListener extends BlockListener { @Override public void onBlockPlace(BlockPlaceEvent event) { - if(!event.isCancelled() && NoCheatConfiguration.speedhackCheckActive) + if(!event.isCancelled() && NoCheatConfiguration.airbuildCheckActive) BlockPlacingCheck.check(event); } }