mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-14 19:41:21 +01:00
more little improvements and changed default configuration
This commit is contained in:
parent
0687d6c78c
commit
3a0413b082
@ -26,11 +26,11 @@ public class ActionManager {
|
||||
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;
|
||||
|
||||
BaseData data = plugin.getData(player.getName());
|
||||
final BaseData data = plugin.getData(player.getName());
|
||||
// Always set this here "by hand"
|
||||
data.log.violationLevel = violationLevel;
|
||||
|
||||
@ -53,7 +53,7 @@ public class ActionManager {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -5,8 +5,6 @@ package cc.co.evenprime.bukkit.nocheat.actions.types;
|
||||
* executed depends on how many executions have occured within the last 60
|
||||
* seconds and how much time was between this and the previous execution
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public abstract class Action {
|
||||
|
||||
@ -21,6 +19,9 @@ public abstract class Action {
|
||||
*/
|
||||
public final int repeat;
|
||||
|
||||
/**
|
||||
* The name of the action, to identify it in the config file
|
||||
*/
|
||||
public final String name;
|
||||
|
||||
public Action(String name, int delay, int repeat) {
|
||||
|
@ -5,11 +5,12 @@ import java.util.Locale;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.data.LogData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
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
|
||||
* @return
|
||||
*/
|
||||
public String getMessage(LogData data) {
|
||||
protected String getMessage(final LogData data) {
|
||||
StringBuilder log = new StringBuilder(100); // Should be big enough most
|
||||
// of the time
|
||||
|
||||
@ -101,6 +102,7 @@ public abstract class ActionWithParameters extends Action {
|
||||
// The == is correct here, as these really are identical objects, not
|
||||
// only equal
|
||||
switch (wildcard) {
|
||||
|
||||
case PLAYER:
|
||||
return data.playerName;
|
||||
|
||||
@ -160,31 +162,34 @@ public abstract class ActionWithParameters extends Action {
|
||||
case TEXT:
|
||||
return data.text;
|
||||
|
||||
case PLACE_LOCATION:
|
||||
Block block = data.placed;
|
||||
if(block != null) {
|
||||
return String.format(Locale.US, "%d %d %d", block.getX(), block.getY(), block.getZ());
|
||||
case PLACE_LOCATION: {
|
||||
SimpleLocation l = data.placedLocation;
|
||||
if(l.isSet()) {
|
||||
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
case PLACE_AGAINST:
|
||||
Block blocka = data.placedAgainst;
|
||||
if(blocka == null) {
|
||||
case PLACE_AGAINST: {
|
||||
SimpleLocation l = data.placedAgainstLocation;
|
||||
if(l.isSet()) {
|
||||
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
return String.format(Locale.US, "%d %d %d", blocka.getX(), blocka.getY(), blocka.getZ());
|
||||
}
|
||||
|
||||
case BLOCK_TYPE:
|
||||
Block blockb = data.placed;
|
||||
if(blockb == null) {
|
||||
case BLOCK_TYPE: {
|
||||
Material type = data.placedType;
|
||||
if(type == null) {
|
||||
return "null";
|
||||
}
|
||||
return blockb.getType().toString();
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
default:
|
||||
return "Evenprime was lazy and forgot to define " + wildcard + ".";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
* console
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class ConsolecommandAction extends ActionWithParameters {
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class LogAction extends ActionWithParameters {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getMessage(LogData ldata) {
|
||||
public String getLogMessage(final LogData ldata) {
|
||||
return super.getMessage(ldata);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ package cc.co.evenprime.bukkit.nocheat.actions.types;
|
||||
* Do something check-specific. Usually that is to cancel the event, undo
|
||||
* something the player did, or do something the server should've done
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class SpecialAction extends Action {
|
||||
|
||||
|
@ -21,15 +21,15 @@ public class CheckUtil {
|
||||
* Check if a player looks at a target of a specific size, with a specific
|
||||
* 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
|
||||
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
|
||||
Vector direction = player.getEyeLocation().getDirection();
|
||||
final Vector direction = player.getEyeLocation().getDirection();
|
||||
|
||||
final double x = ((double) targetX) - eyes.getX();
|
||||
final double y = ((double) targetY) - eyes.getY();
|
||||
@ -52,11 +52,11 @@ public class CheckUtil {
|
||||
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);
|
||||
}
|
||||
|
@ -6,22 +6,23 @@ import org.bukkit.entity.Player;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
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
|
||||
* checks need to be executed and in which order. It will also precalculate
|
||||
* some values that are needed by multiple checks.
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class BlockBreakCheck {
|
||||
|
||||
private final ReachCheck reachCheck;
|
||||
private final DirectionCheck directionCheck;
|
||||
private final NoCheat plugin;
|
||||
|
||||
public BlockBreakCheck(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
this.reachCheck = new ReachCheck(plugin);
|
||||
this.directionCheck = new DirectionCheck(plugin);
|
||||
}
|
||||
@ -31,17 +32,19 @@ public class BlockBreakCheck {
|
||||
boolean cancel = false;
|
||||
|
||||
// Reach check only if not in creative mode!
|
||||
boolean reach = cc.blockbreak.reachCheck && !player.hasPermission(Permissions.BLOCKBREAK_REACH);
|
||||
boolean direction = cc.blockbreak.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION);
|
||||
final boolean reach = cc.blockbreak.reachCheck && !player.hasPermission(Permissions.BLOCKBREAK_REACH);
|
||||
final boolean direction = cc.blockbreak.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION);
|
||||
|
||||
if((reach || direction) && brokenBlock != null) {
|
||||
|
||||
final BaseData data = plugin.getData(player.getName());
|
||||
|
||||
if(reach) {
|
||||
cancel = reachCheck.check(player, brokenBlock, cc);
|
||||
cancel = reachCheck.check(player, data, brokenBlock, cc);
|
||||
}
|
||||
|
||||
if(!cancel && direction) {
|
||||
cancel = directionCheck.check(player, brokenBlock, cc);
|
||||
cancel = directionCheck.check(player, data, brokenBlock, cc);
|
||||
}
|
||||
}
|
||||
return cancel;
|
||||
|
@ -5,8 +5,10 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
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.data.BaseData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
|
||||
|
||||
/**
|
||||
* The DirectionCheck will find out if a player tried to interact with something
|
||||
@ -21,43 +23,50 @@ public class DirectionCheck {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean check(Player player, Block brokenBlock, ConfigurationCache cc) {
|
||||
|
||||
BaseData data = plugin.getData(player.getName());
|
||||
public boolean check(final Player player, final BaseData data, final Block brokenBlock, final ConfigurationCache cc) {
|
||||
|
||||
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(!cc.blockbreak.checkinstabreakblocks && data.blockbreak.instaBrokeBlockLocation.equals(brokenBlock)) {
|
||||
if(isInstaBreak && !ccblockbreak.checkinstabreakblocks) {
|
||||
return 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) {
|
||||
// Player did nothing wrong
|
||||
// reduce violation counter
|
||||
data.blockbreak.directionViolationLevel *= 0.9D;
|
||||
blockbreak.directionViolationLevel *= 0.9D;
|
||||
} else {
|
||||
// Player failed the check
|
||||
// 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
|
||||
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) {
|
||||
// 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(data.blockbreak.directionLastViolationTime + cc.blockbreak.directionPenaltyTime >= time) {
|
||||
if(blockbreak.directionLastViolationTime + ccblockbreak.directionPenaltyTime >= time) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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.config.cache.ConfigurationCache;
|
||||
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
|
||||
* far away
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class ReachCheck {
|
||||
|
||||
@ -24,27 +23,27 @@ public class ReachCheck {
|
||||
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;
|
||||
|
||||
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) {
|
||||
// Player failed the check
|
||||
|
||||
// Increment violation counter
|
||||
data.blockbreak.reachViolationLevel += distance;
|
||||
|
||||
blockbreak.reachViolationLevel += distance;
|
||||
|
||||
// Setup data for logging
|
||||
data.log.check = "blockbreak.reach";
|
||||
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 {
|
||||
data.blockbreak.reachViolationLevel *= 0.9D;
|
||||
blockbreak.reachViolationLevel *= 0.9D;
|
||||
}
|
||||
|
||||
return cancel;
|
||||
|
@ -6,24 +6,26 @@ import org.bukkit.entity.Player;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class BlockPlaceCheck {
|
||||
|
||||
private final ReachCheck reachCheck;
|
||||
private final OnLiquidCheck onLiquidCheck;
|
||||
private final NoCheat plugin;
|
||||
|
||||
public BlockPlaceCheck(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
|
||||
reachCheck = new ReachCheck(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;
|
||||
|
||||
@ -31,12 +33,14 @@ public class BlockPlaceCheck {
|
||||
final boolean onliquid = cc.blockplace.onliquidCheck && !player.hasPermission(Permissions.BLOCKPLACE_ONLIQUID);
|
||||
final boolean reach = cc.blockplace.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH);
|
||||
|
||||
final BaseData data = plugin.getData(player.getName());
|
||||
|
||||
if(!cancel && reach) {
|
||||
cancel = reachCheck.check(player, blockPlaced, blockPlacedAgainst, cc);
|
||||
cancel = reachCheck.check(player, data, blockPlacedAgainst, cc);
|
||||
}
|
||||
|
||||
if(!cancel && onliquid) {
|
||||
cancel = onLiquidCheck.check(player, blockPlaced, blockPlacedAgainst, cc);
|
||||
cancel = onLiquidCheck.check(player, data, blockPlaced, blockPlacedAgainst, cc);
|
||||
}
|
||||
|
||||
return cancel;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -8,10 +8,10 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.LogData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class OnLiquidCheck {
|
||||
@ -22,36 +22,38 @@ public class OnLiquidCheck {
|
||||
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;
|
||||
|
||||
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()))) {
|
||||
// all ok
|
||||
} else if(nextToSolid(blockPlaced.getWorld(), blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ())) {
|
||||
// all ok
|
||||
} else {
|
||||
data.blockplace.onliquidViolationLevel += 1;
|
||||
data.log.check = "blockplace.onliquid";
|
||||
data.log.placed = blockPlaced;
|
||||
data.log.placedAgainst = blockPlacedAgainst;
|
||||
blockplace.onliquidViolationLevel += 1;
|
||||
log.check = "blockplace.onliquid";
|
||||
log.placedLocation.set(blockPlaced);
|
||||
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
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
@ -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.config.cache.ConfigurationCache;
|
||||
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
|
||||
* far away
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class ReachCheck {
|
||||
|
||||
@ -23,27 +22,27 @@ public class ReachCheck {
|
||||
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;
|
||||
|
||||
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) {
|
||||
// Player failed the check
|
||||
|
||||
// Increment violation counter
|
||||
data.blockplace.reachViolationLevel += distance;
|
||||
blockplace.reachViolationLevel += distance;
|
||||
|
||||
// Prepare some event-specific values for logging and custom actions
|
||||
data.log.check = "blockplace.reach";
|
||||
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 {
|
||||
data.blockplace.reachViolationLevel *= 0.9D;
|
||||
blockplace.reachViolationLevel *= 0.9D;
|
||||
}
|
||||
|
||||
return cancel;
|
||||
|
@ -4,8 +4,10 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
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.data.BaseData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -19,34 +21,37 @@ public class ChatCheck {
|
||||
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;
|
||||
|
||||
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) {
|
||||
|
||||
// Maybe it's a command and on the whitelist
|
||||
for(String s : cc.chat.spamWhitelist) {
|
||||
for(String s : ccchat.spamWhitelist) {
|
||||
if(message.startsWith(s)) {
|
||||
// It is
|
||||
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) {
|
||||
data.chat.spamLasttime = time;
|
||||
data.chat.messageCount = 0;
|
||||
if(chat.spamLasttime + ccchat.spamTimeframe <= time) {
|
||||
chat.spamLasttime = time;
|
||||
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
|
||||
// actions
|
||||
@ -54,7 +59,7 @@ public class ChatCheck {
|
||||
data.log.check = "chat.spam";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,16 +23,16 @@ public class FightCheck {
|
||||
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 directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
final boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
|
||||
|
||||
if(directionCheck) {
|
||||
|
||||
final long time = System.currentTimeMillis();
|
||||
|
||||
// Get the width of the damagee
|
||||
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);
|
||||
|
||||
BaseData data = plugin.getData(player.getName());
|
||||
|
||||
|
||||
if(off < 0.1D) {
|
||||
// Player did probably nothing wrong
|
||||
// reduce violation counter
|
||||
@ -68,7 +68,7 @@ public class FightCheck {
|
||||
data.fight.directionLastViolationTime = time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the player is still in penalty time, cancel the event anyway
|
||||
if(data.fight.directionLastViolationTime + cc.fight.directionPenaltyTime >= time) {
|
||||
return true;
|
||||
|
@ -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
|
||||
* that are needed by multiple checks.
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class RunFlyCheck {
|
||||
|
||||
@ -114,7 +112,7 @@ public class RunFlyCheck {
|
||||
}
|
||||
|
||||
SimpleLocation lblock = new SimpleLocation();
|
||||
lblock.setLocation(blockPlaced);
|
||||
lblock.set(blockPlaced);
|
||||
SimpleLocation lplayer = new SimpleLocation();
|
||||
lplayer.setLocation(player.getLocation());
|
||||
|
||||
|
@ -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)
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class ConfigurationManager {
|
||||
|
||||
|
@ -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, "");
|
||||
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 moveLogMedShort 0 15 med [player] failed [check]");
|
||||
w(w, "log moveLogHighShort 0 15 high [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]. VL [violations]");
|
||||
w(w, "log moveLogHighShort 0 15 high [player] failed [check]. VL [violations]");
|
||||
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, "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, "");
|
||||
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 directionLog 2 1 med [player] failed [check]: tried to destroy a block out of line of sight.");
|
||||
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 spamLog 0 4 med [player] failed [check]: Last sent message \"[text]\".");
|
||||
w(w, "log nofallLog 0 1 med [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks.");
|
||||
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 reachLog 0 5 med [player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]");
|
||||
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 5 med [player] failed [check]: tried to place a [blocktype] block at [placelocation] against block at [placeagainst]. VL [violations]");
|
||||
w(w, "log spamLog 0 5 med [player] failed [check]: Last sent message \"[text]\". VL [violations]");
|
||||
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, "");
|
||||
w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event.");
|
||||
w(w, "# - They start with the word 'special'");
|
||||
|
@ -3,8 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.config;
|
||||
/**
|
||||
* The various permission nodes used by NoCheat
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class Permissions {
|
||||
|
||||
|
@ -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
|
||||
* retrieve all actions that match a certain treshold.
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class ActionList {
|
||||
|
||||
@ -49,7 +47,7 @@ public class ActionList {
|
||||
* @param violationLevel
|
||||
* @return
|
||||
*/
|
||||
public Action[] getActions(Integer vl) {
|
||||
public Action[] getActions(int vl) {
|
||||
|
||||
Integer result = null;
|
||||
|
||||
|
@ -6,7 +6,6 @@ import java.util.Map;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
|
||||
|
||||
/**
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class ActionMapper {
|
||||
|
@ -1,6 +1,6 @@
|
||||
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
|
||||
@ -9,11 +9,12 @@ public class LogData extends Data {
|
||||
|
||||
public String check;
|
||||
public int violationLevel;
|
||||
public final PreciseLocation toLocation = new PreciseLocation();
|
||||
public final PreciseLocation toLocation = new PreciseLocation();
|
||||
public int packets;
|
||||
public String text;
|
||||
public Block placed;
|
||||
public Block placedAgainst;
|
||||
public final SimpleLocation placedLocation = new SimpleLocation();
|
||||
public Material placedType;
|
||||
public final SimpleLocation placedAgainstLocation = new SimpleLocation();
|
||||
public double reachdistance;
|
||||
public float falldistance;
|
||||
public String playerName;
|
||||
|
@ -2,7 +2,12 @@ package cc.co.evenprime.bukkit.nocheat.data;
|
||||
|
||||
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 y;
|
||||
@ -12,28 +17,28 @@ public class PreciseLocation {
|
||||
reset();
|
||||
}
|
||||
|
||||
public void set(Location location) {
|
||||
public final void set(Location location) {
|
||||
x = location.getX();
|
||||
y = location.getY();
|
||||
z = location.getZ();
|
||||
}
|
||||
|
||||
public void set(PreciseLocation location) {
|
||||
public final void set(PreciseLocation location) {
|
||||
x = location.x;
|
||||
y = location.y;
|
||||
z = location.z;
|
||||
}
|
||||
|
||||
public boolean isSet() {
|
||||
public final boolean isSet() {
|
||||
return x != Double.MAX_VALUE;
|
||||
}
|
||||
public void reset() {
|
||||
public final void reset() {
|
||||
x = Double.MAX_VALUE;
|
||||
y = 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;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.block.Block;
|
||||
* our own "Location" object which is easily reusable.
|
||||
*
|
||||
*/
|
||||
public class SimpleLocation {
|
||||
public final class SimpleLocation {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
@ -19,26 +19,26 @@ public class SimpleLocation {
|
||||
reset();
|
||||
}
|
||||
|
||||
public boolean equals(Block block) {
|
||||
public final boolean equals(Block block) {
|
||||
return block.getX() == x && block.getY() == y && block.getZ() == z;
|
||||
}
|
||||
|
||||
public void setLocation(Block block) {
|
||||
public final void set(Block block) {
|
||||
x = block.getX();
|
||||
y = block.getY();
|
||||
z = block.getZ();
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
public final void setLocation(Location location) {
|
||||
x = location.getBlockX();
|
||||
y = location.getBlockY();
|
||||
z = location.getBlockZ();
|
||||
}
|
||||
|
||||
public boolean isSet() {
|
||||
public final boolean isSet() {
|
||||
return x != Integer.MAX_VALUE;
|
||||
}
|
||||
public void reset() {
|
||||
public final void reset() {
|
||||
x = Integer.MAX_VALUE;
|
||||
y = Integer.MAX_VALUE;
|
||||
z = Integer.MAX_VALUE;
|
||||
|
@ -98,7 +98,7 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
|
||||
|
||||
// Remember this location. We ignore block breaks in the block-break
|
||||
// direction check that are insta-breaks
|
||||
data.blockbreak.instaBrokeBlockLocation.setLocation(event.getBlock());
|
||||
data.blockbreak.instaBrokeBlockLocation.set(event.getBlock());
|
||||
|
||||
// store performance time
|
||||
if(performanceCheck)
|
||||
|
@ -41,7 +41,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
public void onPlayerChat(final PlayerChatEvent event) {
|
||||
|
||||
if(event.isCancelled()) {
|
||||
return;
|
||||
@ -60,9 +60,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
|
||||
// Find out if checks need to be done for that player
|
||||
if(cc.chat.check && !player.hasPermission(Permissions.CHAT)) {
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
cancel = chatCheck.check(player, event.getMessage(), cc);
|
||||
final boolean cancel = chatCheck.check(player, event.getMessage(), cc);
|
||||
|
||||
if(cancel) {
|
||||
event.setCancelled(true);
|
||||
@ -74,7 +72,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
|
||||
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
|
||||
// performance counter here
|
||||
|
@ -5,8 +5,6 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* Define the available log levels (low, med, high, off)
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public enum LogLevel {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user