more little improvements and changed default configuration

This commit is contained in:
Evenprime 2011-10-21 21:22:45 +02:00
parent 0687d6c78c
commit 3a0413b082
28 changed files with 163 additions and 179 deletions

View File

@ -26,11 +26,11 @@ public class ActionManager {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean executeActions(Player player, ActionList actions, int violationLevel, ExecutionHistory history, ConfigurationCache cc) { public boolean executeActions(final Player player, final ActionList actions, final int violationLevel, final ExecutionHistory history, final ConfigurationCache cc) {
boolean special = false; boolean special = false;
BaseData data = plugin.getData(player.getName()); final BaseData data = plugin.getData(player.getName());
// Always set this here "by hand" // Always set this here "by hand"
data.log.violationLevel = violationLevel; data.log.violationLevel = violationLevel;
@ -53,7 +53,7 @@ public class ActionManager {
} }
private void executeLogAction(LogAction l, LogData data, ConfigurationCache cc) { private void executeLogAction(LogAction l, LogData data, ConfigurationCache cc) {
plugin.log(l.level, cc.logging.prefix + l.getMessage(data), cc); plugin.log(l.level, cc.logging.prefix + l.getLogMessage(data), cc);
} }
private void executeConsoleCommand(ConsolecommandAction action, LogData data) { private void executeConsoleCommand(ConsolecommandAction action, LogData data) {

View File

@ -5,8 +5,6 @@ package cc.co.evenprime.bukkit.nocheat.actions.types;
* executed depends on how many executions have occured within the last 60 * executed depends on how many executions have occured within the last 60
* seconds and how much time was between this and the previous execution * seconds and how much time was between this and the previous execution
* *
* @author Evenprime
*
*/ */
public abstract class Action { public abstract class Action {
@ -21,6 +19,9 @@ public abstract class Action {
*/ */
public final int repeat; public final int repeat;
/**
* The name of the action, to identify it in the config file
*/
public final String name; public final String name;
public Action(String name, int delay, int repeat) { public Action(String name, int delay, int repeat) {

View File

@ -5,11 +5,12 @@ import java.util.Locale;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.data.LogData; import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
public abstract class ActionWithParameters extends Action { public abstract class ActionWithParameters extends Action {
@ -77,12 +78,12 @@ public abstract class ActionWithParameters extends Action {
} }
/** /**
* Get a log message with all the wildcards replaced with data from LogData * Get a string with all the wildcards replaced with data from LogData
* *
* @param data * @param data
* @return * @return
*/ */
public String getMessage(LogData data) { protected String getMessage(final LogData data) {
StringBuilder log = new StringBuilder(100); // Should be big enough most StringBuilder log = new StringBuilder(100); // Should be big enough most
// of the time // of the time
@ -101,6 +102,7 @@ public abstract class ActionWithParameters extends Action {
// The == is correct here, as these really are identical objects, not // The == is correct here, as these really are identical objects, not
// only equal // only equal
switch (wildcard) { switch (wildcard) {
case PLAYER: case PLAYER:
return data.playerName; return data.playerName;
@ -160,31 +162,34 @@ public abstract class ActionWithParameters extends Action {
case TEXT: case TEXT:
return data.text; return data.text;
case PLACE_LOCATION: case PLACE_LOCATION: {
Block block = data.placed; SimpleLocation l = data.placedLocation;
if(block != null) { if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", block.getX(), block.getY(), block.getZ()); return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
} else { } else {
return "null"; return "null";
} }
}
case PLACE_AGAINST: case PLACE_AGAINST: {
Block blocka = data.placedAgainst; SimpleLocation l = data.placedAgainstLocation;
if(blocka == null) { if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
} else {
return "null"; return "null";
} }
return String.format(Locale.US, "%d %d %d", blocka.getX(), blocka.getY(), blocka.getZ()); }
case BLOCK_TYPE: case BLOCK_TYPE: {
Block blockb = data.placed; Material type = data.placedType;
if(blockb == null) { if(type == null) {
return "null"; return "null";
} }
return blockb.getType().toString(); return type.toString();
}
default: default:
return "Evenprime was lazy and forgot to define " + wildcard + "."; return "Evenprime was lazy and forgot to define " + wildcard + ".";
} }
} }
} }

View File

@ -6,8 +6,6 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
* Execute a command by imitating an admin typing the command directly into the * Execute a command by imitating an admin typing the command directly into the
* console * console
* *
* @author Evenprime
*
*/ */
public class ConsolecommandAction extends ActionWithParameters { public class ConsolecommandAction extends ActionWithParameters {

View File

@ -19,7 +19,7 @@ public class LogAction extends ActionWithParameters {
this.level = level; this.level = level;
} }
public String getMessage(LogData ldata) { public String getLogMessage(final LogData ldata) {
return super.getMessage(ldata); return super.getMessage(ldata);
} }
} }

View File

@ -4,8 +4,6 @@ package cc.co.evenprime.bukkit.nocheat.actions.types;
* Do something check-specific. Usually that is to cancel the event, undo * Do something check-specific. Usually that is to cancel the event, undo
* something the player did, or do something the server should've done * something the player did, or do something the server should've done
* *
* @author Evenprime
*
*/ */
public class SpecialAction extends Action { public class SpecialAction extends Action {

View File

@ -21,15 +21,15 @@ public class CheckUtil {
* Check if a player looks at a target of a specific size, with a specific * Check if a player looks at a target of a specific size, with a specific
* precision value (roughly) * precision value (roughly)
*/ */
public static final double directionCheck(Player player, double targetX, double targetY, double targetZ, double targetWidth, double targetHeight, double precision) { public static final double directionCheck(final Player player, final double targetX, final double targetY, final double targetZ, final double targetWidth, final double targetHeight, final double precision) {
// Eye location of the player // Eye location of the player
Location eyes = player.getEyeLocation(); final Location eyes = player.getEyeLocation();
double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2)); final double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));
// View direction of the player // View direction of the player
Vector direction = player.getEyeLocation().getDirection(); final Vector direction = player.getEyeLocation().getDirection();
final double x = ((double) targetX) - eyes.getX(); final double x = ((double) targetX) - eyes.getX();
final double y = ((double) targetY) - eyes.getY(); final double y = ((double) targetY) - eyes.getY();
@ -52,11 +52,11 @@ public class CheckUtil {
return off; return off;
} }
public static final double reachCheck(Player player, double targetX, double targetY, double targetZ, double limit) { public static final double reachCheck(final Player player, final double targetX, final double targetY, final double targetZ, final double limit) {
Location eyes = player.getEyeLocation(); final Location eyes = player.getEyeLocation();
double distance = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2)); final double distance = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));
return Math.max(distance - limit, 0.0D); return Math.max(distance - limit, 0.0D);
} }

View File

@ -6,22 +6,23 @@ import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/** /**
* The main Check class for blockbreak event checking. It will decide which * The main Check class for blockbreak event checking. It will decide which
* checks need to be executed and in which order. It will also precalculate * checks need to be executed and in which order. It will also precalculate
* some values that are needed by multiple checks. * some values that are needed by multiple checks.
* *
* @author Evenprime
*
*/ */
public class BlockBreakCheck { public class BlockBreakCheck {
private final ReachCheck reachCheck; private final ReachCheck reachCheck;
private final DirectionCheck directionCheck; private final DirectionCheck directionCheck;
private final NoCheat plugin;
public BlockBreakCheck(NoCheat plugin) { public BlockBreakCheck(NoCheat plugin) {
this.plugin = plugin;
this.reachCheck = new ReachCheck(plugin); this.reachCheck = new ReachCheck(plugin);
this.directionCheck = new DirectionCheck(plugin); this.directionCheck = new DirectionCheck(plugin);
} }
@ -31,17 +32,19 @@ public class BlockBreakCheck {
boolean cancel = false; boolean cancel = false;
// Reach check only if not in creative mode! // Reach check only if not in creative mode!
boolean reach = cc.blockbreak.reachCheck && !player.hasPermission(Permissions.BLOCKBREAK_REACH); final boolean reach = cc.blockbreak.reachCheck && !player.hasPermission(Permissions.BLOCKBREAK_REACH);
boolean direction = cc.blockbreak.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION); final boolean direction = cc.blockbreak.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION);
if((reach || direction) && brokenBlock != null) { if((reach || direction) && brokenBlock != null) {
final BaseData data = plugin.getData(player.getName());
if(reach) { if(reach) {
cancel = reachCheck.check(player, brokenBlock, cc); cancel = reachCheck.check(player, data, brokenBlock, cc);
} }
if(!cancel && direction) { if(!cancel && direction) {
cancel = directionCheck.check(player, brokenBlock, cc); cancel = directionCheck.check(player, data, brokenBlock, cc);
} }
} }
return cancel; return cancel;

View File

@ -5,8 +5,10 @@ import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData; import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
/** /**
* The DirectionCheck will find out if a player tried to interact with something * The DirectionCheck will find out if a player tried to interact with something
@ -21,43 +23,50 @@ public class DirectionCheck {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean check(Player player, Block brokenBlock, ConfigurationCache cc) { public boolean check(final Player player, final BaseData data, final Block brokenBlock, final ConfigurationCache cc) {
BaseData data = plugin.getData(player.getName());
final BlockBreakData blockbreak = data.blockbreak;
final CCBlockBreak ccblockbreak = cc.blockbreak;
final boolean isInstaBreak = blockbreak.instaBrokeBlockLocation.equals(brokenBlock);
// If the block is instabreak and we don't check instabreak, return // If the block is instabreak and we don't check instabreak, return
if(!cc.blockbreak.checkinstabreakblocks && data.blockbreak.instaBrokeBlockLocation.equals(brokenBlock)) { if(isInstaBreak && !ccblockbreak.checkinstabreakblocks) {
return false; return false;
} }
boolean cancel = false; boolean cancel = false;
double off = CheckUtil.directionCheck(player, brokenBlock.getX() + 0.5D, brokenBlock.getY() + 0.5D, brokenBlock.getZ() + 0.5D, 1D, 1D, cc.blockbreak.directionPrecision); double off = CheckUtil.directionCheck(player, brokenBlock.getX() + 0.5D, brokenBlock.getY() + 0.5D, brokenBlock.getZ() + 0.5D, 1D, 1D, ccblockbreak.directionPrecision);
long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
if(off < 0.1D) { if(off < 0.1D) {
// Player did nothing wrong // Player did nothing wrong
// reduce violation counter // reduce violation counter
data.blockbreak.directionViolationLevel *= 0.9D; blockbreak.directionViolationLevel *= 0.9D;
} else { } else {
// Player failed the check // Player failed the check
// Increment violation counter // Increment violation counter
data.blockbreak.directionViolationLevel += off; if(isInstaBreak) {
// Instabreak block failures are very common, so don't be as hard on people failing them
off /= 10;
}
blockbreak.directionViolationLevel += off;
// Prepare some event-specific values for logging and custom actions // Prepare some event-specific values for logging and custom actions
data.log.check = "blockbreak.direction"; data.log.check = "blockbreak.direction";
cancel = plugin.execute(player, cc.blockbreak.directionActions, (int) data.blockbreak.directionViolationLevel, data.blockbreak.history, cc); cancel = plugin.execute(player, ccblockbreak.directionActions, (int) blockbreak.directionViolationLevel, blockbreak.history, cc);
if(cancel) { if(cancel) {
// Needed to calculate penalty times // Needed to calculate penalty times
data.blockbreak.directionLastViolationTime = time; blockbreak.directionLastViolationTime = time;
} }
} }
// If the player is still in penalty time, cancel the event anyway // If the player is still in penalty time, cancel the event anyway
if(data.blockbreak.directionLastViolationTime + cc.blockbreak.directionPenaltyTime >= time) { if(blockbreak.directionLastViolationTime + ccblockbreak.directionPenaltyTime >= time) {
return true; return true;
} }

View File

@ -8,13 +8,12 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData; import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
/** /**
* The reach check will find out if a player interacts with something that's too * The reach check will find out if a player interacts with something that's too
* far away * far away
* *
* @author Evenprime
*
*/ */
public class ReachCheck { public class ReachCheck {
@ -24,27 +23,27 @@ public class ReachCheck {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean check(Player player, Block brokenBlock, ConfigurationCache cc) { public boolean check(final Player player, final BaseData data, final Block brokenBlock, final ConfigurationCache cc) {
boolean cancel = false; boolean cancel = false;
double distance = CheckUtil.reachCheck(player, brokenBlock.getX() + 0.5D, brokenBlock.getY() + 0.5D, brokenBlock.getZ() + 0.5D, player.getGameMode() == GameMode.CREATIVE ? cc.blockbreak.reachDistance + 2 : cc.blockbreak.reachDistance); final BlockBreakData blockbreak = data.blockbreak;
final double distance = CheckUtil.reachCheck(player, brokenBlock.getX() + 0.5D, brokenBlock.getY() + 0.5D, brokenBlock.getZ() + 0.5D, player.getGameMode() == GameMode.CREATIVE ? cc.blockbreak.reachDistance + 2 : cc.blockbreak.reachDistance);
BaseData data = plugin.getData(player.getName());
if(distance > 0D) { if(distance > 0D) {
// Player failed the check // Player failed the check
// Increment violation counter // Increment violation counter
data.blockbreak.reachViolationLevel += distance; blockbreak.reachViolationLevel += distance;
// Setup data for logging // Setup data for logging
data.log.check = "blockbreak.reach"; data.log.check = "blockbreak.reach";
data.log.reachdistance = distance; data.log.reachdistance = distance;
cancel = plugin.execute(player, cc.blockbreak.reachActions, (int) data.blockbreak.reachViolationLevel, data.blockbreak.history, cc); cancel = plugin.execute(player, cc.blockbreak.reachActions, (int) blockbreak.reachViolationLevel, blockbreak.history, cc);
} else { } else {
data.blockbreak.reachViolationLevel *= 0.9D; blockbreak.reachViolationLevel *= 0.9D;
} }
return cancel; return cancel;

View File

@ -6,24 +6,26 @@ import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/** /**
*
* @author Evenprime
* *
*/ */
public class BlockPlaceCheck { public class BlockPlaceCheck {
private final ReachCheck reachCheck; private final ReachCheck reachCheck;
private final OnLiquidCheck onLiquidCheck; private final OnLiquidCheck onLiquidCheck;
private final NoCheat plugin;
public BlockPlaceCheck(NoCheat plugin) { public BlockPlaceCheck(NoCheat plugin) {
this.plugin = plugin;
reachCheck = new ReachCheck(plugin); reachCheck = new ReachCheck(plugin);
onLiquidCheck = new OnLiquidCheck(plugin); onLiquidCheck = new OnLiquidCheck(plugin);
} }
public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, ConfigurationCache cc) { public boolean check(final Player player, final Block blockPlaced, final Block blockPlacedAgainst, final ConfigurationCache cc) {
boolean cancel = false; boolean cancel = false;
@ -31,12 +33,14 @@ public class BlockPlaceCheck {
final boolean onliquid = cc.blockplace.onliquidCheck && !player.hasPermission(Permissions.BLOCKPLACE_ONLIQUID); final boolean onliquid = cc.blockplace.onliquidCheck && !player.hasPermission(Permissions.BLOCKPLACE_ONLIQUID);
final boolean reach = cc.blockplace.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH); final boolean reach = cc.blockplace.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH);
final BaseData data = plugin.getData(player.getName());
if(!cancel && reach) { if(!cancel && reach) {
cancel = reachCheck.check(player, blockPlaced, blockPlacedAgainst, cc); cancel = reachCheck.check(player, data, blockPlacedAgainst, cc);
} }
if(!cancel && onliquid) { if(!cancel && onliquid) {
cancel = onLiquidCheck.check(player, blockPlaced, blockPlacedAgainst, cc); cancel = onLiquidCheck.check(player, data, blockPlaced, blockPlacedAgainst, cc);
} }
return cancel; return cancel;

View File

@ -1,32 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The noswingcheck will only identify if an action happened without a preceding "swing"
*
*/
public class NoSwingCheck {
private final NoCheat plugin;
public NoSwingCheck(NoCheat plugin) {
this.plugin = plugin;
}
public boolean check(Player player, ConfigurationCache cc) {
boolean cancel = false;
BaseData data = plugin.getData(player.getName());
return cancel;
}
}

View File

@ -8,10 +8,10 @@ import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData; import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
/** /**
*
* @author Evenprime
* *
*/ */
public class OnLiquidCheck { public class OnLiquidCheck {
@ -22,36 +22,38 @@ public class OnLiquidCheck {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, ConfigurationCache cc) { public boolean check(final Player player, final BaseData data, final Block blockPlaced, final Block blockPlacedAgainst, final ConfigurationCache cc) {
boolean cancel = false; boolean cancel = false;
BaseData data = plugin.getData(player.getName()); final BlockPlaceData blockplace = data.blockplace;
final LogData log = data.log;
if(blockPlaced == null || blockPlaced.isEmpty() || (blockPlacedAgainst != null && isSolid(blockPlacedAgainst.getTypeId()))) { if(blockPlaced == null || blockPlaced.isEmpty() || (blockPlacedAgainst != null && isSolid(blockPlacedAgainst.getTypeId()))) {
// all ok // all ok
} else if(nextToSolid(blockPlaced.getWorld(), blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ())) { } else if(nextToSolid(blockPlaced.getWorld(), blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ())) {
// all ok // all ok
} else { } else {
data.blockplace.onliquidViolationLevel += 1; blockplace.onliquidViolationLevel += 1;
data.log.check = "blockplace.onliquid"; log.check = "blockplace.onliquid";
data.log.placed = blockPlaced; log.placedLocation.set(blockPlaced);
data.log.placedAgainst = blockPlacedAgainst; log.placedType = blockPlaced.getType();
log.placedAgainstLocation.set(blockPlacedAgainst);
cancel = plugin.execute(player, cc.blockplace.onliquidActions, (int) data.blockplace.onliquidViolationLevel, data.blockplace.history, cc); cancel = plugin.execute(player, cc.blockplace.onliquidActions, (int) blockplace.onliquidViolationLevel, blockplace.history, cc);
} }
data.blockplace.onliquidViolationLevel *= 0.95D; // Reduce level over blockplace.onliquidViolationLevel *= 0.95D; // Reduce level over
// time // time
return cancel; return cancel;
} }
private boolean nextToSolid(World world, int x, int y, int z) { private static final boolean nextToSolid(final World world, final int x, final int y, final int z) {
return isSolid(world.getBlockTypeIdAt(x, y - 1, z)) || isSolid(world.getBlockTypeIdAt(x - 1, y, z)) || isSolid(world.getBlockTypeIdAt(x + 1, y, z)) || isSolid(world.getBlockTypeIdAt(x, y, z + 1)) || isSolid(world.getBlockTypeIdAt(x, y, z - 1)) || isSolid(world.getBlockTypeIdAt(x, y + 1, z)); return isSolid(world.getBlockTypeIdAt(x, y - 1, z)) || isSolid(world.getBlockTypeIdAt(x - 1, y, z)) || isSolid(world.getBlockTypeIdAt(x + 1, y, z)) || isSolid(world.getBlockTypeIdAt(x, y, z + 1)) || isSolid(world.getBlockTypeIdAt(x, y, z - 1)) || isSolid(world.getBlockTypeIdAt(x, y + 1, z));
} }
private boolean isSolid(int id) { private static final boolean isSolid(int id) {
return !((id == Material.AIR.getId()) || (id == Material.WATER.getId()) || (id == Material.STATIONARY_WATER.getId()) || (id == Material.LAVA.getId()) || (id == Material.STATIONARY_LAVA.getId())); return !((id == Material.AIR.getId()) || (id == Material.WATER.getId()) || (id == Material.STATIONARY_WATER.getId()) || (id == Material.LAVA.getId()) || (id == Material.STATIONARY_LAVA.getId()));
} }
} }

View File

@ -7,13 +7,12 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData; import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
/** /**
* The reach check will find out if a player interacts with something that's too * The reach check will find out if a player interacts with something that's too
* far away * far away
* *
* @author Evenprime
*
*/ */
public class ReachCheck { public class ReachCheck {
@ -23,27 +22,27 @@ public class ReachCheck {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean check(Player player, Block blockPlaced, Block placedAgainstBlock, ConfigurationCache cc) { public boolean check(final Player player, final BaseData data, final Block placedAgainstBlock, final ConfigurationCache cc) {
boolean cancel = false; boolean cancel = false;
double distance = CheckUtil.reachCheck(player, placedAgainstBlock.getX() + 0.5D, placedAgainstBlock.getY() + 0.5D, placedAgainstBlock.getZ() + 0.5D, cc.blockplace.reachDistance); final double distance = CheckUtil.reachCheck(player, placedAgainstBlock.getX() + 0.5D, placedAgainstBlock.getY() + 0.5D, placedAgainstBlock.getZ() + 0.5D, cc.blockplace.reachDistance);
BaseData data = plugin.getData(player.getName()); BlockPlaceData blockplace = data.blockplace;
if(distance > 0D) { if(distance > 0D) {
// Player failed the check // Player failed the check
// Increment violation counter // Increment violation counter
data.blockplace.reachViolationLevel += distance; blockplace.reachViolationLevel += distance;
// Prepare some event-specific values for logging and custom actions // Prepare some event-specific values for logging and custom actions
data.log.check = "blockplace.reach"; data.log.check = "blockplace.reach";
data.log.reachdistance = distance; data.log.reachdistance = distance;
cancel = plugin.execute(player, cc.blockplace.reachActions, (int) data.blockplace.reachViolationLevel, data.blockplace.history, cc); cancel = plugin.execute(player, cc.blockplace.reachActions, (int) blockplace.reachViolationLevel, blockplace.history, cc);
} else { } else {
data.blockplace.reachViolationLevel *= 0.9D; blockplace.reachViolationLevel *= 0.9D;
} }
return cancel; return cancel;

View File

@ -4,8 +4,10 @@ import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData; import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
/** /**
* *
@ -19,34 +21,37 @@ public class ChatCheck {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean check(Player player, String message, ConfigurationCache cc) { public boolean check(final Player player, final String message, final ConfigurationCache cc) {
boolean cancel = false; boolean cancel = false;
final CCChat ccchat = cc.chat;
boolean spamCheck = cc.chat.spamCheck && !player.hasPermission(Permissions.CHAT_SPAM); final boolean spamCheck = ccchat.spamCheck && !player.hasPermission(Permissions.CHAT_SPAM);
if(spamCheck) { if(spamCheck) {
// Maybe it's a command and on the whitelist // Maybe it's a command and on the whitelist
for(String s : cc.chat.spamWhitelist) { for(String s : ccchat.spamWhitelist) {
if(message.startsWith(s)) { if(message.startsWith(s)) {
// It is // It is
return false; return false;
} }
} }
int time = plugin.getIngameSeconds(); final int time = plugin.getIngameSeconds();
BaseData data = plugin.getData(player.getName()); final BaseData data = plugin.getData(player.getName());
final ChatData chat = data.chat;
if(data.chat.spamLasttime + cc.chat.spamTimeframe <= time) { if(chat.spamLasttime + ccchat.spamTimeframe <= time) {
data.chat.spamLasttime = time; chat.spamLasttime = time;
data.chat.messageCount = 0; chat.messageCount = 0;
} }
data.chat.messageCount++; chat.messageCount++;
if(data.chat.messageCount > cc.chat.spamLimit) { if(chat.messageCount > ccchat.spamLimit) {
// Prepare some event-specific values for logging and custom // Prepare some event-specific values for logging and custom
// actions // actions
@ -54,7 +59,7 @@ public class ChatCheck {
data.log.check = "chat.spam"; data.log.check = "chat.spam";
data.log.text = message; data.log.text = message;
cancel = plugin.execute(player, cc.chat.spamActions, data.chat.messageCount - cc.chat.spamLimit, data.chat.history, cc); cancel = plugin.execute(player, ccchat.spamActions, chat.messageCount - ccchat.spamLimit, chat.history, cc);
} }
} }

View File

@ -23,16 +23,16 @@ public class FightCheck {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean check(Player player, Entity damagee, ConfigurationCache cc) { public boolean check(final Player player, final Entity damagee, final ConfigurationCache cc) {
boolean cancel = false; boolean cancel = false;
boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION); final boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
long time = System.currentTimeMillis();
if(directionCheck) { if(directionCheck) {
final long time = System.currentTimeMillis();
// Get the width of the damagee // Get the width of the damagee
net.minecraft.server.Entity entity = ((CraftEntity) damagee).getHandle(); net.minecraft.server.Entity entity = ((CraftEntity) damagee).getHandle();
@ -45,7 +45,7 @@ public class FightCheck {
double off = CheckUtil.directionCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, width, 2.0D, cc.fight.directionPrecision); double off = CheckUtil.directionCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, width, 2.0D, cc.fight.directionPrecision);
BaseData data = plugin.getData(player.getName()); BaseData data = plugin.getData(player.getName());
if(off < 0.1D) { if(off < 0.1D) {
// Player did probably nothing wrong // Player did probably nothing wrong
// reduce violation counter // reduce violation counter
@ -68,7 +68,7 @@ public class FightCheck {
data.fight.directionLastViolationTime = time; data.fight.directionLastViolationTime = time;
} }
} }
// If the player is still in penalty time, cancel the event anyway // If the player is still in penalty time, cancel the event anyway
if(data.fight.directionLastViolationTime + cc.fight.directionPenaltyTime >= time) { if(data.fight.directionLastViolationTime + cc.fight.directionPenaltyTime >= time) {
return true; return true;

View File

@ -19,8 +19,6 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
* need to be executed and in which order. It will also precalculate some values * need to be executed and in which order. It will also precalculate some values
* that are needed by multiple checks. * that are needed by multiple checks.
* *
* @author Evenprime
*
*/ */
public class RunFlyCheck { public class RunFlyCheck {
@ -114,7 +112,7 @@ public class RunFlyCheck {
} }
SimpleLocation lblock = new SimpleLocation(); SimpleLocation lblock = new SimpleLocation();
lblock.setLocation(blockPlaced); lblock.set(blockPlaced);
SimpleLocation lplayer = new SimpleLocation(); SimpleLocation lplayer = new SimpleLocation();
lplayer.setLocation(player.getLocation()); lplayer.setLocation(player.getLocation());

View File

@ -21,8 +21,6 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper;
/** /**
* Central location for everything that's described in the configuration file(s) * Central location for everything that's described in the configuration file(s)
* *
* @author Evenprime
*
*/ */
public class ConfigurationManager { public class ConfigurationManager {

View File

@ -215,9 +215,9 @@ public class DefaultConfiguration extends Configuration {
w(w, "# - Then comes the 'message', depending on where the action is used, different keywords in [ ] may be used"); w(w, "# - Then comes the 'message', depending on where the action is used, different keywords in [ ] may be used");
w(w, ""); w(w, "");
w(w, "# Gives a very short log message of the violation, only containing name, violation type and total violation value, at most once every 15 seconds, only if more than 3 violations happened within the last minute (low) and immediatly (med,high)"); w(w, "# Gives a very short log message of the violation, only containing name, violation type and total violation value, at most once every 15 seconds, only if more than 3 violations happened within the last minute (low) and immediatly (med,high)");
w(w, "log moveLogLowShort 3 15 low [player] failed [check]"); w(w, "log moveLogLowShort 3 15 low [player] failed [check]. VL [violations]");
w(w, "log moveLogMedShort 0 15 med [player] failed [check]"); w(w, "log moveLogMedShort 0 15 med [player] failed [check]. VL [violations]");
w(w, "log moveLogHighShort 0 15 high [player] failed [check]"); w(w, "log moveLogHighShort 0 15 high [player] failed [check]. VL [violations]");
w(w, ""); w(w, "");
w(w, "# Gives a log message of the violation, only containing name, violation type and total violation value, at most once every second, only if more than 5 violations happened within the last minute (low) and immediatly (med,high)"); w(w, "# Gives a log message of the violation, only containing name, violation type and total violation value, at most once every second, only if more than 5 violations happened within the last minute (low) and immediatly (med,high)");
w(w, "log morepacketsLow 5 1 low [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); w(w, "log morepacketsLow 5 1 low [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations].");
@ -230,12 +230,12 @@ public class DefaultConfiguration extends Configuration {
w(w, "log moveLogHighLong 0 15 high [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); w(w, "log moveLogHighLong 0 15 high [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations].");
w(w, ""); w(w, "");
w(w, "# Some other log messages that are limited a bit by default, to avoid too extreme spam"); w(w, "# Some other log messages that are limited a bit by default, to avoid too extreme spam");
w(w, "log reachLog 0 1 med [player] failed [check]: tried to interact with a block over distance [reachdistance]."); w(w, "log reachLog 0 5 med [player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]");
w(w, "log directionLog 2 1 med [player] failed [check]: tried to destroy a block out of line of sight."); w(w, "log directionLog 2 5 med [player] failed [check]: tried to destroy a block out of line of sight. VL [violations]");
w(w, "log onliquidLog 2 1 med [player] failed [check]: tried to place a [blocktype] block at [placelocation] against block at [placeagainst]."); w(w, "log onliquidLog 2 5 med [player] failed [check]: tried to place a [blocktype] block at [placelocation] against block at [placeagainst]. VL [violations]");
w(w, "log spamLog 0 4 med [player] failed [check]: Last sent message \"[text]\"."); w(w, "log spamLog 0 5 med [player] failed [check]: Last sent message \"[text]\". VL [violations]");
w(w, "log nofallLog 0 1 med [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks."); w(w, "log nofallLog 0 5 med [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks. VL [violations]");
w(w, "log fightDirectionLog 0 5 med [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]"); w(w, "log fightDirectionLog 0 5 med [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations].");
w(w, ""); w(w, "");
w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event."); w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event.");
w(w, "# - They start with the word 'special'"); w(w, "# - They start with the word 'special'");

View File

@ -3,8 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.config;
/** /**
* The various permission nodes used by NoCheat * The various permission nodes used by NoCheat
* *
* @author Evenprime
*
*/ */
public class Permissions { public class Permissions {

View File

@ -12,8 +12,6 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
* A list of actions, that associates actions and a treshold. It allows to * A list of actions, that associates actions and a treshold. It allows to
* retrieve all actions that match a certain treshold. * retrieve all actions that match a certain treshold.
* *
* @author Evenprime
*
*/ */
public class ActionList { public class ActionList {
@ -49,7 +47,7 @@ public class ActionList {
* @param violationLevel * @param violationLevel
* @return * @return
*/ */
public Action[] getActions(Integer vl) { public Action[] getActions(int vl) {
Integer result = null; Integer result = null;

View File

@ -6,7 +6,6 @@ import java.util.Map;
import cc.co.evenprime.bukkit.nocheat.actions.types.Action; import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
/** /**
* @author Evenprime
* *
*/ */
public class ActionMapper { public class ActionMapper {

View File

@ -1,6 +1,6 @@
package cc.co.evenprime.bukkit.nocheat.data; package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.block.Block; import org.bukkit.Material;
/** /**
* Everything that could be relevant for logging or consolecommand actions * Everything that could be relevant for logging or consolecommand actions
@ -9,11 +9,12 @@ public class LogData extends Data {
public String check; public String check;
public int violationLevel; public int violationLevel;
public final PreciseLocation toLocation = new PreciseLocation(); public final PreciseLocation toLocation = new PreciseLocation();
public int packets; public int packets;
public String text; public String text;
public Block placed; public final SimpleLocation placedLocation = new SimpleLocation();
public Block placedAgainst; public Material placedType;
public final SimpleLocation placedAgainstLocation = new SimpleLocation();
public double reachdistance; public double reachdistance;
public float falldistance; public float falldistance;
public String playerName; public String playerName;

View File

@ -2,7 +2,12 @@ package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.Location; import org.bukkit.Location;
public class PreciseLocation { /**
* A class to store x,y,z triple data, instead of using bukkits Location objects,
* which can't be easily recycled
*
*/
public final class PreciseLocation {
public double x; public double x;
public double y; public double y;
@ -12,28 +17,28 @@ public class PreciseLocation {
reset(); reset();
} }
public void set(Location location) { public final void set(Location location) {
x = location.getX(); x = location.getX();
y = location.getY(); y = location.getY();
z = location.getZ(); z = location.getZ();
} }
public void set(PreciseLocation location) { public final void set(PreciseLocation location) {
x = location.x; x = location.x;
y = location.y; y = location.y;
z = location.z; z = location.z;
} }
public boolean isSet() { public final boolean isSet() {
return x != Double.MAX_VALUE; return x != Double.MAX_VALUE;
} }
public void reset() { public final void reset() {
x = Double.MAX_VALUE; x = Double.MAX_VALUE;
y = Double.MAX_VALUE; y = Double.MAX_VALUE;
z = Double.MAX_VALUE; z = Double.MAX_VALUE;
} }
public boolean equals(Location location) { public final boolean equals(Location location) {
return location.getX() == x && location.getY() == y && location.getZ() == z; return location.getX() == x && location.getY() == y && location.getZ() == z;
} }
} }

View File

@ -9,7 +9,7 @@ import org.bukkit.block.Block;
* our own "Location" object which is easily reusable. * our own "Location" object which is easily reusable.
* *
*/ */
public class SimpleLocation { public final class SimpleLocation {
public int x; public int x;
public int y; public int y;
@ -19,26 +19,26 @@ public class SimpleLocation {
reset(); reset();
} }
public boolean equals(Block block) { public final boolean equals(Block block) {
return block.getX() == x && block.getY() == y && block.getZ() == z; return block.getX() == x && block.getY() == y && block.getZ() == z;
} }
public void setLocation(Block block) { public final void set(Block block) {
x = block.getX(); x = block.getX();
y = block.getY(); y = block.getY();
z = block.getZ(); z = block.getZ();
} }
public void setLocation(Location location) { public final void setLocation(Location location) {
x = location.getBlockX(); x = location.getBlockX();
y = location.getBlockY(); y = location.getBlockY();
z = location.getBlockZ(); z = location.getBlockZ();
} }
public boolean isSet() { public final boolean isSet() {
return x != Integer.MAX_VALUE; return x != Integer.MAX_VALUE;
} }
public void reset() { public final void reset() {
x = Integer.MAX_VALUE; x = Integer.MAX_VALUE;
y = Integer.MAX_VALUE; y = Integer.MAX_VALUE;
z = Integer.MAX_VALUE; z = Integer.MAX_VALUE;

View File

@ -98,7 +98,7 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
// Remember this location. We ignore block breaks in the block-break // Remember this location. We ignore block breaks in the block-break
// direction check that are insta-breaks // direction check that are insta-breaks
data.blockbreak.instaBrokeBlockLocation.setLocation(event.getBlock()); data.blockbreak.instaBrokeBlockLocation.set(event.getBlock());
// store performance time // store performance time
if(performanceCheck) if(performanceCheck)

View File

@ -41,7 +41,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
} }
@Override @Override
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(final PlayerChatEvent event) {
if(event.isCancelled()) { if(event.isCancelled()) {
return; return;
@ -60,9 +60,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
// Find out if checks need to be done for that player // Find out if checks need to be done for that player
if(cc.chat.check && !player.hasPermission(Permissions.CHAT)) { if(cc.chat.check && !player.hasPermission(Permissions.CHAT)) {
boolean cancel = false; final boolean cancel = chatCheck.check(player, event.getMessage(), cc);
cancel = chatCheck.check(player, event.getMessage(), cc);
if(cancel) { if(cancel) {
event.setCancelled(true); event.setCancelled(true);
@ -74,7 +72,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
chatPerformance.addTime(System.nanoTime() - nanoTimeStart); chatPerformance.addTime(System.nanoTime() - nanoTimeStart);
} }
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
// We redirect to the other method anyway, so no need to set up a // We redirect to the other method anyway, so no need to set up a
// performance counter here // performance counter here

View File

@ -5,8 +5,6 @@ import java.util.logging.Level;
/** /**
* Define the available log levels (low, med, high, off) * Define the available log levels (low, med, high, off)
* *
* @author Evenprime
*
*/ */
public enum LogLevel { public enum LogLevel {