Removed blockplace.noswing check, because it causes problems

Added blockplace.direction check
This commit is contained in:
Evenprime 2011-10-30 20:15:03 +01:00
parent 71b53892c4
commit 99a197607b
13 changed files with 147 additions and 80 deletions

View File

@ -62,8 +62,8 @@ permissions:
description: Allow a player to place blocks at maximum range (about 6-7 blocks) description: Allow a player to place blocks at maximum range (about 6-7 blocks)
nocheat.checks.blockplace.onliquid: nocheat.checks.blockplace.onliquid:
description: Allow a player to place non-liquid blocks on liquids description: Allow a player to place non-liquid blocks on liquids
nocheat.checks.blockplace.noswing: nocheat.checks.blockplace.direction:
description: Allow a player to place blocks without swinging their arm description: Allow a player to place blocks outside their line of view
nocheat.checks.chat: nocheat.checks.chat:
description: Allow the player to bypass all chat checks description: Allow the player to bypass all chat checks
children: children:

View File

@ -13,10 +13,10 @@ import cc.co.evenprime.bukkit.nocheat.data.BaseData;
*/ */
public class BlockPlaceCheck { public class BlockPlaceCheck {
private final ReachCheck reachCheck; private final ReachCheck reachCheck;
private final OnLiquidCheck onLiquidCheck; private final OnLiquidCheck onLiquidCheck;
private final NoswingCheck noswingCheck; private final DirectionCheck directionCheck;
private final NoCheat plugin; private final NoCheat plugin;
public BlockPlaceCheck(NoCheat plugin) { public BlockPlaceCheck(NoCheat plugin) {
@ -24,7 +24,7 @@ public class BlockPlaceCheck {
reachCheck = new ReachCheck(plugin); reachCheck = new ReachCheck(plugin);
onLiquidCheck = new OnLiquidCheck(plugin); onLiquidCheck = new OnLiquidCheck(plugin);
noswingCheck = new NoswingCheck(plugin); directionCheck = new DirectionCheck(plugin);
} }
public boolean check(final Player player, final Block blockPlaced, final Block blockPlacedAgainst, final ConfigurationCache cc) { public boolean check(final Player player, final Block blockPlaced, final Block blockPlacedAgainst, final ConfigurationCache cc) {
@ -34,16 +34,21 @@ public class BlockPlaceCheck {
// Which checks are going to be executed? // Which checks are going to be executed?
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 boolean noswing = cc.blockplace.noswingCheck && !player.hasPermission(Permissions.BLOCKPLACE_NOSWING); final boolean direction = cc.blockplace.directionCheck && !player.hasPermission(Permissions.BLOCKPLACE_DIRECTION);
final BaseData data = plugin.getData(player.getName()); final BaseData data = plugin.getData(player.getName());
if(noswing) { if(blockPlaced != null && blockPlacedAgainst != null) {
cancel = noswingCheck.check(player, data, cc); data.blockplace.blockPlaced.set(blockPlaced);
} data.blockplace.blockPlacedAgainst.set(blockPlacedAgainst);
if(!cancel && reach) {
cancel = reachCheck.check(player, data, blockPlacedAgainst, cc); if(!cancel && direction) {
cancel = directionCheck.check(player, data, cc);
}
if(!cancel && reach) {
cancel = reachCheck.check(player, data, cc);
}
} }
if(!cancel && onliquid) { if(!cancel && onliquid) {

View File

@ -0,0 +1,87 @@
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.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
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.SimpleLocation;
public class DirectionCheck {
private final NoCheat plugin;
public DirectionCheck(NoCheat plugin) {
this.plugin = plugin;
}
public boolean check(final Player player, final BaseData data, final ConfigurationCache cc) {
boolean cancel = false;
final CCBlockPlace ccblockplace = cc.blockplace;
final BlockPlaceData blockplace = data.blockplace;
final SimpleLocation blockPlaced = blockplace.blockPlaced;
final SimpleLocation blockPlacedAgainst = blockplace.blockPlacedAgainst;
// First check if the crosshair matches (roughly) the clicked block
double off = CheckUtil.directionCheck(player, blockPlacedAgainst.x + 0.5D, blockPlacedAgainst.y + 0.5D, blockPlacedAgainst.z + 0.5D, 1D, 1D, ccblockplace.directionPrecision);
// now check if the player is looking at the block from the correct side
double off2 = 0.0D;
// Find out against which face the player tried to build, and if he
// stood on the correct side
if(blockPlaced.x > blockPlacedAgainst.x) {
off2 = blockPlacedAgainst.x + 0.5D - player.getEyeLocation().getX();
} else if(blockPlaced.x < blockPlacedAgainst.x) {
off2 = -(blockPlacedAgainst.x + 0.5D - player.getEyeLocation().getX());
} else if(blockPlaced.y > blockPlacedAgainst.y) {
off2 = blockPlacedAgainst.y + 0.5D - player.getEyeLocation().getY();
} else if(blockPlaced.y < blockPlacedAgainst.y) {
off2 = -(blockPlacedAgainst.y + 0.5D - player.getEyeLocation().getY());
} else if(blockPlaced.z > blockPlacedAgainst.z) {
off2 = blockPlacedAgainst.z + 0.5D - player.getEyeLocation().getZ();
} else if(blockPlaced.z < blockPlacedAgainst.z) {
off2 = -(blockPlacedAgainst.z + 0.5D - player.getEyeLocation().getZ());
}
if(off2 > 0.0D) {
off += off2;
}
final long time = System.currentTimeMillis();
if(off < 0.1D) {
// Player did nothing wrong
// reduce violation counter
blockplace.directionViolationLevel *= 0.9D;
} else {
// Player failed the check
// Increment violation counter
blockplace.directionViolationLevel += off;
// Prepare some event-specific values for logging and custom actions
data.log.check = "blockplace.direction";
cancel = plugin.execute(player, ccblockplace.directionActions, (int) blockplace.directionViolationLevel, blockplace.history, cc);
if(cancel) {
// Needed to calculate penalty times
blockplace.directionLastViolationTime = time;
}
}
// If the player is still in penalty time, cancel the event anyway
if(blockplace.directionLastViolationTime + ccblockplace.directionPenaltyTime >= time) {
return true;
}
return cancel;
}
}

View File

@ -1,36 +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;
public class NoswingCheck {
private final NoCheat plugin;
public NoswingCheck(NoCheat plugin) {
this.plugin = plugin;
}
public boolean check(final Player player, final BaseData data, final ConfigurationCache cc) {
boolean cancel = false;
// did he swing his arm before?
if(data.armswung) {
data.armswung = false;
data.blockplace.noswingVL *= 0.90D;
} else {
data.blockplace.noswingVL += 1;
// Prepare some event-specific values for logging and custom
// actions
data.log.check = "blockplace.noswing";
cancel = plugin.execute(player, cc.blockplace.noswingActions, (int) data.blockplace.noswingVL, data.blockplace.history, cc);
}
return cancel;
}
}

View File

@ -1,6 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace; package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
@ -8,6 +7,7 @@ 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; import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
/** /**
* 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
@ -22,11 +22,12 @@ public class ReachCheck {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean check(final Player player, final BaseData data, final Block placedAgainstBlock, final ConfigurationCache cc) { public boolean check(final Player player, final BaseData data, final ConfigurationCache cc) {
boolean cancel = false; boolean cancel = false;
final SimpleLocation placedAgainstBlock = data.blockplace.blockPlacedAgainst;
final 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.x + 0.5D, placedAgainstBlock.y + 0.5D, placedAgainstBlock.z + 0.5D, cc.blockplace.reachDistance);
BlockPlaceData blockplace = data.blockplace; BlockPlaceData blockplace = data.blockplace;

View File

@ -69,7 +69,7 @@ public abstract class Configuration {
public final static OptionNode BLOCKBREAK_DIRECTION_CHECK = new OptionNode("check", BLOCKBREAK_DIRECTION, DataType.BOOLEAN); public final static OptionNode BLOCKBREAK_DIRECTION_CHECK = new OptionNode("check", BLOCKBREAK_DIRECTION, DataType.BOOLEAN);
public final static OptionNode BLOCKBREAK_DIRECTION_CHECKINSTABREAKBLOCKS = new OptionNode("checkinstabreakblocks", BLOCKBREAK_DIRECTION, DataType.BOOLEAN); public final static OptionNode BLOCKBREAK_DIRECTION_CHECKINSTABREAKBLOCKS = new OptionNode("checkinstabreakblocks", BLOCKBREAK_DIRECTION, DataType.BOOLEAN);
public final static OptionNode BLOCKBREAK_DIRECTION_PRECISION = new OptionNode("precision", BLOCKBREAK_DIRECTION, DataType.INTEGER); public final static OptionNode BLOCKBREAK_DIRECTION_PRECISION = new OptionNode("precision", BLOCKBREAK_DIRECTION, DataType.INTEGER);
public final static OptionNode BLOCKBREAK_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", BLOCKBREAK_DIRECTION, DataType.INTEGER); ; public final static OptionNode BLOCKBREAK_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", BLOCKBREAK_DIRECTION, DataType.INTEGER);
public final static OptionNode BLOCKBREAK_DIRECTION_ACTIONS = new OptionNode("actions", BLOCKBREAK_DIRECTION, DataType.ACTIONLIST); public final static OptionNode BLOCKBREAK_DIRECTION_ACTIONS = new OptionNode("actions", BLOCKBREAK_DIRECTION, DataType.ACTIONLIST);
private final static OptionNode BLOCKBREAK_NOSWING = new OptionNode("noswing", BLOCKBREAK, DataType.PARENT); private final static OptionNode BLOCKBREAK_NOSWING = new OptionNode("noswing", BLOCKBREAK, DataType.PARENT);
@ -88,9 +88,11 @@ public abstract class Configuration {
public final static OptionNode BLOCKPLACE_ONLIQUID_CHECK = new OptionNode("check", BLOCKPLACE_ONLIQUID, DataType.BOOLEAN); public final static OptionNode BLOCKPLACE_ONLIQUID_CHECK = new OptionNode("check", BLOCKPLACE_ONLIQUID, DataType.BOOLEAN);
public final static OptionNode BLOCKPLACE_ONLIQUID_ACTIONS = new OptionNode("actions", BLOCKPLACE_ONLIQUID, DataType.ACTIONLIST); public final static OptionNode BLOCKPLACE_ONLIQUID_ACTIONS = new OptionNode("actions", BLOCKPLACE_ONLIQUID, DataType.ACTIONLIST);
private final static OptionNode BLOCKPLACE_NOSWING = new OptionNode("noswing", BLOCKPLACE, DataType.PARENT); private final static OptionNode BLOCKPLACE_DIRECTION = new OptionNode("direction", BLOCKPLACE, DataType.PARENT);
public final static OptionNode BLOCKPLACE_NOSWING_CHECK = new OptionNode("check", BLOCKPLACE_NOSWING, DataType.BOOLEAN); public static final OptionNode BLOCKPLACE_DIRECTION_CHECK = new OptionNode("check", BLOCKPLACE_DIRECTION, DataType.BOOLEAN); ;
public final static OptionNode BLOCKPLACE_NOSWING_ACTIONS = new OptionNode("actions", BLOCKPLACE_NOSWING, DataType.ACTIONLIST); public static final OptionNode BLOCKPLACE_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", BLOCKPLACE_DIRECTION, DataType.INTEGER);
public final static OptionNode BLOCKPLACE_DIRECTION_PRECISION = new OptionNode("precision", BLOCKPLACE_DIRECTION, DataType.INTEGER);
public static final OptionNode BLOCKPLACE_DIRECTION_ACTIONS = new OptionNode("actions", BLOCKPLACE_DIRECTION, DataType.ACTIONLIST);
private final static OptionNode CHAT = new OptionNode("chat", ROOT, DataType.PARENT); private final static OptionNode CHAT = new OptionNode("chat", ROOT, DataType.PARENT);
public final static OptionNode CHAT_CHECK = new OptionNode("check", CHAT, DataType.BOOLEAN); public final static OptionNode CHAT_CHECK = new OptionNode("check", CHAT, DataType.BOOLEAN);

View File

@ -97,11 +97,9 @@ public class DefaultConfiguration extends Configuration {
setValue(BLOCKBREAK_REACH_ACTIONS, reachActionList); setValue(BLOCKBREAK_REACH_ACTIONS, reachActionList);
setValue(BLOCKBREAK_DIRECTION_CHECK, true); setValue(BLOCKBREAK_DIRECTION_CHECK, true);
setValue(BLOCKBREAK_DIRECTION_CHECKINSTABREAKBLOCKS, true); setValue(BLOCKBREAK_DIRECTION_CHECKINSTABREAKBLOCKS, true);
setValue(BLOCKBREAK_DIRECTION_PRECISION, 50); setValue(BLOCKBREAK_DIRECTION_PRECISION, 50);
setValue(BLOCKBREAK_DIRECTION_PENALTYTIME, 300); setValue(BLOCKBREAK_DIRECTION_PENALTYTIME, 300);
ActionList directionActionList = new ActionList(); ActionList directionActionList = new ActionList();
directionActionList.setActions(0, action.getActions("blockbreakCancel".split(" "))); directionActionList.setActions(0, action.getActions("blockbreakCancel".split(" ")));
directionActionList.setActions(10, action.getActions("directionLog blockbreakCancel".split(" "))); directionActionList.setActions(10, action.getActions("directionLog blockbreakCancel".split(" ")));
@ -132,11 +130,13 @@ public class DefaultConfiguration extends Configuration {
onliquidActionList.setActions(3, action.getActions("onliquidLog blockplaceCancel".split(" "))); onliquidActionList.setActions(3, action.getActions("onliquidLog blockplaceCancel".split(" ")));
setValue(BLOCKPLACE_ONLIQUID_ACTIONS, onliquidActionList); setValue(BLOCKPLACE_ONLIQUID_ACTIONS, onliquidActionList);
setValue(BLOCKPLACE_NOSWING_CHECK, true); setValue(BLOCKPLACE_DIRECTION_CHECK, true);
ActionList noswingActionList = new ActionList(); setValue(BLOCKPLACE_DIRECTION_PRECISION, 50);
noswingActionList.setActions(0, action.getActions("noswingLog blockplaceCancel".split(" "))); setValue(BLOCKPLACE_DIRECTION_PENALTYTIME, 300);
setValue(BLOCKPLACE_NOSWING_ACTIONS, noswingActionList); ActionList directionActionList = new ActionList();
directionActionList.setActions(0, action.getActions("blockplaceCancel".split(" ")));
directionActionList.setActions(10, action.getActions("directionLog blockplaceCancel".split(" ")));
setValue(BLOCKPLACE_DIRECTION_ACTIONS, directionActionList);
} }
/*** CHAT ***/ /*** CHAT ***/

View File

@ -75,8 +75,10 @@ public class Explainations {
set(Configuration.BLOCKPLACE_ONLIQUID_CHECK, "If true, check if a player is trying to place non-liquid blocks against liquid blocks\nIn a normal Minecraft game, it is impossible to place a block without it touching something that is considered solid (neither air nor a liquid).\nBut if people use a modified client, to can do that. This check tries to identify that trick."); set(Configuration.BLOCKPLACE_ONLIQUID_CHECK, "If true, check if a player is trying to place non-liquid blocks against liquid blocks\nIn a normal Minecraft game, it is impossible to place a block without it touching something that is considered solid (neither air nor a liquid).\nBut if people use a modified client, to can do that. This check tries to identify that trick.");
set(Configuration.BLOCKPLACE_ONLIQUID_ACTIONS, "What should be done if a player is is trying to place non-liquid blocks against liquid blocks.\nUnit is number of place(attempt)s."); set(Configuration.BLOCKPLACE_ONLIQUID_ACTIONS, "What should be done if a player is is trying to place non-liquid blocks against liquid blocks.\nUnit is number of place(attempt)s.");
set(Configuration.BLOCKPLACE_NOSWING_CHECK, "If true, check if a player swung his arm before placing a block, which he should have done."); set(Configuration.BLOCKPLACE_DIRECTION_CHECK, "If true, check if a player is looking at the block that he's placing.");
set(Configuration.BLOCKPLACE_NOSWING_ACTIONS, "What should be done if a player didn't swing his arm.\nUnit is number of blockplacing without armswinging."); set(Configuration.BLOCKPLACE_DIRECTION_PRECISION, "Define how precise a player has to be when placing blocks. Lower values mean more precision, higher values less precision.");
set(Configuration.BLOCKPLACE_DIRECTION_PENALTYTIME, "Define how long after a failed attempt to place blocks a player will be disallowed to place another block. \nUnit is milliseconds, default is 300.");
set(Configuration.BLOCKPLACE_DIRECTION_ACTIONS, "What should be done if a player is placing blocks that are not in his line of sight.\nUnit is number of place(attempt)s outside the line of sight.");
set(Configuration.CHAT_CHECK, "If true, do various checks on PlayerChat events."); set(Configuration.CHAT_CHECK, "If true, do various checks on PlayerChat events.");

View File

@ -26,7 +26,7 @@ public class Permissions {
public final static String BLOCKPLACE = CHECKS + ".blockplace"; public final static String BLOCKPLACE = CHECKS + ".blockplace";
public final static String BLOCKPLACE_ONLIQUID = BLOCKPLACE + ".onliquid"; public final static String BLOCKPLACE_ONLIQUID = BLOCKPLACE + ".onliquid";
public final static String BLOCKPLACE_REACH = BLOCKPLACE + ".reach"; public final static String BLOCKPLACE_REACH = BLOCKPLACE + ".reach";
public static final String BLOCKPLACE_NOSWING = BLOCKPLACE + ".noswing"; public static final String BLOCKPLACE_DIRECTION = BLOCKPLACE + ".direction";
public final static String CHAT = CHECKS + ".chat"; public final static String CHAT = CHECKS + ".chat";
public final static String CHAT_SPAM = CHAT + ".spam"; public final static String CHAT_SPAM = CHAT + ".spam";

View File

@ -16,8 +16,10 @@ public class CCBlockPlace {
public final double reachDistance; public final double reachDistance;
public final ActionList reachActions; public final ActionList reachActions;
public final boolean noswingCheck; public final boolean directionCheck;
public final ActionList noswingActions; public final ActionList directionActions;
public final long directionPenaltyTime;
public final double directionPrecision;
public CCBlockPlace(Configuration data) { public CCBlockPlace(Configuration data) {
@ -30,7 +32,10 @@ public class CCBlockPlace {
reachDistance = data.getInteger(Configuration.BLOCKPLACE_REACH_LIMIT); reachDistance = data.getInteger(Configuration.BLOCKPLACE_REACH_LIMIT);
reachActions = data.getActionList(Configuration.BLOCKPLACE_REACH_ACTIONS); reachActions = data.getActionList(Configuration.BLOCKPLACE_REACH_ACTIONS);
noswingCheck = data.getBoolean(Configuration.BLOCKPLACE_NOSWING_CHECK); directionCheck = data.getBoolean(Configuration.BLOCKPLACE_DIRECTION_CHECK);
noswingActions = data.getActionList(Configuration.BLOCKPLACE_NOSWING_ACTIONS); directionPenaltyTime = data.getInteger(Configuration.BLOCKPLACE_DIRECTION_PENALTYTIME);
directionPrecision = ((double) data.getInteger(Configuration.BLOCKPLACE_DIRECTION_PRECISION)) / 100D;
directionActions = data.getActionList(Configuration.BLOCKPLACE_DIRECTION_ACTIONS);
} }
} }

View File

@ -14,9 +14,7 @@ public class BaseData extends Data {
public long lastUsedTime; public long lastUsedTime;
public boolean armswung; // This technically does belong to public boolean armswung;
// many other checks, so I'll put
// it here for convenience
public BaseData() { public BaseData() {
this.blockbreak = new BlockBreakData(); this.blockbreak = new BlockBreakData();

View File

@ -5,8 +5,13 @@ package cc.co.evenprime.bukkit.nocheat.data;
*/ */
public class BlockPlaceData extends Data { public class BlockPlaceData extends Data {
public double onliquidViolationLevel = 0.0D; public double onliquidViolationLevel = 0.0D;
public double reachViolationLevel = 0.0D; public double reachViolationLevel = 0.0D;
public final ExecutionHistory history = new ExecutionHistory(); public final ExecutionHistory history = new ExecutionHistory();
public double noswingVL = 0.0D; public double noswingVL = 0.0D;
public double directionViolationLevel = 0.0D;
public long directionLastViolationTime = 0;
public final SimpleLocation blockPlacedAgainst = new SimpleLocation();
public final SimpleLocation blockPlaced = new SimpleLocation();
} }

View File

@ -99,8 +99,6 @@ public class BlockPlaceEventManager extends BlockListener implements EventManage
s.add("blockplace.onliquid"); s.add("blockplace.onliquid");
if(cc.blockplace.check && cc.blockplace.reachCheck) if(cc.blockplace.check && cc.blockplace.reachCheck)
s.add("blockplace.reach"); s.add("blockplace.reach");
if(cc.blockplace.check && cc.blockplace.noswingCheck)
s.add("blockplace.noswing");
return s; return s;
} }