Check against building in air + more configuration options + less

noisy logging.
This commit is contained in:
Evenprime 2011-02-22 15:08:08 +01:00
parent 62dfce532d
commit 2d34799a87
4 changed files with 50 additions and 15 deletions

View File

@ -1,6 +1,8 @@
package cc.co.evenprime.bukkit.nocheat; package cc.co.evenprime.bukkit.nocheat;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
public class BlockPlacingCheck { public class BlockPlacingCheck {
@ -15,10 +17,18 @@ public class BlockPlacingCheck {
return; return;
} }
if(event.getBlockAgainst().getType() == Material.AIR) { Location l = event.getBlockPlaced().getLocation();
event.setCancelled(true); World w = event.getBlock().getWorld();
NoCheatPlugin.log.warning("NoCheatPlugin: Airbuild violation: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " against air"); 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() + " in the air");
} }
} }
} }

View File

@ -18,6 +18,8 @@ public class MovingCheck {
private static final int MINOR = 1; private static final int MINOR = 1;
private static final int NONE = 0; private static final int NONE = 0;
private static final int freeIllegalMoves = 1;
private enum BlockType { private enum BlockType {
SOLID, NONSOLID, LADDER, LIQUID, UNKNOWN; SOLID, NONSOLID, LADDER, LIQUID, UNKNOWN;
} }
@ -225,9 +227,8 @@ public class MovingCheck {
else if(offset > 0.6D) vl = vl > NORMAL ? vl : NORMAL; else if(offset > 0.6D) vl = vl > NORMAL ? vl : NORMAL;
else vl = vl > MINOR ? vl : MINOR; 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 // 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(); 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++; data.minorViolationsInARow++;
// 16 minor violations in a row count as one normal violation
if(data.minorViolationsInARow % 16 == 0) { if(data.minorViolationsInARow % 16 == 0) {
normalViolation(data, event); normalViolation(data, event);
} }
else if(data.minorViolationsInARow % 2 == 0) { else if(data.minorViolationsInARow % (freeIllegalMoves+1) == 0) {
// now we need it // 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); resetPlayer(data, event);
} }
} }
protected static void normalViolation(NoCheatPluginData data, PlayerMoveEvent event) { protected static void normalViolation(NoCheatPluginData data, PlayerMoveEvent event) {
// Log the first violation in a row // 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())); 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); resetPlayer(data, event);
data.normalViolationsInARow++; data.normalViolationsInARow++;
} }
protected static void heavyViolation(NoCheatPluginData data, PlayerMoveEvent event) { 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); NoCheatPlugin.log.warning("NoCheatPlugin: Moving violation stopped: "+event.getPlayer().getName()+ " total Events: "+ data.normalViolationsInARow);
data.normalViolationsInARow = 0; data.normalViolationsInARow = 0;
} }
data.minorViolationsInARow = 0; else if(data.minorViolationsInARow > freeIllegalMoves) {
data.normalViolationsInARow = 0; NoCheatPlugin.log.info("NoCheatPlugin: Moving violation stopped: "+event.getPlayer().getName()+ " total Events: "+ data.minorViolationsInARow);
data.heavyViolationsInARow = 0; data.minorViolationsInARow = 0;
}
else {
data.minorViolationsInARow = 0;
}
data.movingSetBackPoint = null; data.movingSetBackPoint = null;
} }
@ -317,6 +329,9 @@ public class MovingCheck {
*/ */
private static void resetPlayer(NoCheatPluginData data, PlayerMoveEvent 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) { if(data.phase > 7) {
data.phase = 7; data.phase = 7;
} }

View File

@ -18,6 +18,8 @@ public class NoCheatConfiguration {
public static boolean speedhackCheckActive = true; public static boolean speedhackCheckActive = true;
public static boolean movingCheckActive = true; public static boolean movingCheckActive = true;
public static boolean airbuildCheckActive = false;
public static int speedhackInterval = 2000; public static int speedhackInterval = 2000;
public static int speedhackLow = 60; public static int speedhackLow = 60;
public static int speedhackMed = 90; public static int speedhackMed = 90;
@ -27,6 +29,8 @@ public class NoCheatConfiguration {
public static double movingDistanceMed = 1.0D; public static double movingDistanceMed = 1.0D;
public static double movingDistanceHigh = 5.0D; public static double movingDistanceHigh = 5.0D;
public static boolean movingLogOnly = false;
private static ConsoleHandler ch = null; private static ConsoleHandler ch = null;
private static FileHandler fh = null; private static FileHandler fh = null;
@ -66,11 +70,14 @@ public class NoCheatConfiguration {
speedhackCheckActive = c.getBoolean("active.speedhack", true); speedhackCheckActive = c.getBoolean("active.speedhack", true);
movingCheckActive = c.getBoolean("active.moving", true); movingCheckActive = c.getBoolean("active.moving", true);
airbuildCheckActive = c.getBoolean("active.airbuild", false);
speedhackInterval = c.getInt("speedhack.interval", 2000); speedhackInterval = c.getInt("speedhack.interval", 2000);
speedhackLow = c.getInt("speedhack.limits.low", 60); speedhackLow = c.getInt("speedhack.limits.low", 60);
speedhackMed = c.getInt("speedhack.limits.med", 90); speedhackMed = c.getInt("speedhack.limits.med", 90);
speedhackHigh = c.getInt("speedhack.limits.high", 120); speedhackHigh = c.getInt("speedhack.limits.high", 120);
movingLogOnly = c.getBoolean("moving.logonly", false);
} }
private static Level stringToLevel(String string) { private static Level stringToLevel(String string) {
@ -100,6 +107,7 @@ public class NoCheatConfiguration {
w.write("active:"); w.newLine(); w.write("active:"); w.newLine();
w.write(" speedhack: true"); w.newLine(); w.write(" speedhack: true"); w.newLine();
w.write(" moving: 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: interval in milliseconds, limits are events in that interval") ;w.newLine();
w.write("speedhack:"); w.newLine(); w.write("speedhack:"); w.newLine();
w.write(" interval: 2000"); w.newLine(); w.write(" interval: 2000"); w.newLine();
@ -107,6 +115,8 @@ public class NoCheatConfiguration {
w.write(" low: 60"); w.newLine(); w.write(" low: 60"); w.newLine();
w.write(" med: 90"); w.newLine(); w.write(" med: 90"); w.newLine();
w.write(" high: 120"); w.newLine(); w.write(" high: 120"); w.newLine();
w.write("moving:"); w.newLine();
w.write(" logonly: false"); w.newLine();
w.flush(); w.close(); w.flush(); w.close();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block

View File

@ -13,7 +13,7 @@ public class NoCheatPluginBlockListener extends BlockListener {
@Override @Override
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if(!event.isCancelled() && NoCheatConfiguration.speedhackCheckActive) if(!event.isCancelled() && NoCheatConfiguration.airbuildCheckActive)
BlockPlacingCheck.check(event); BlockPlacingCheck.check(event);
} }
} }