Option to set movement speed limits

This commit is contained in:
Evenprime 2011-07-17 17:16:08 +02:00
parent ee1ae892eb
commit c438eee164
5 changed files with 56 additions and 20 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 1.09f version: 1.10a
softdepend: [ Permissions, CraftIRC ] softdepend: [ Permissions, CraftIRC ]

View File

@ -53,6 +53,10 @@ public class MovingCheck extends Check {
public boolean allowFakeSneak; public boolean allowFakeSneak;
public boolean allowFastSwim; public boolean allowFastSwim;
public double stepWidth;
public double sneakWidth;
public double swimWidth;
private boolean waterElevators; private boolean waterElevators;
private String logMessage; private String logMessage;
@ -72,6 +76,8 @@ public class MovingCheck extends Check {
private static final double magic = 0.30000001192092896D; private static final double magic = 0.30000001192092896D;
private static final double magic2 = 0.69999998807907103D; private static final double magic2 = 0.69999998807907103D;
/** /**
* The actual check. * The actual check.
@ -118,7 +124,7 @@ public class MovingCheck extends Check {
if(runCheck) { if(runCheck) {
result += Math.max(0D, runningCheck.check(from, to, result += Math.max(0D, runningCheck.check(from, to,
!allowFakeSneak && player.isSneaking(), !allowFastSwim && (fromType & toType & MovingEventHelper.LIQUID) > 0, data)); !allowFakeSneak && player.isSneaking(), !allowFastSwim && (fromType & toType & MovingEventHelper.LIQUID) > 0, data, this));
} }
/********* HANDLE/COMBINE THE RESULTS OF THE CHECKS ***********/ /********* HANDLE/COMBINE THE RESULTS OF THE CHECKS ***********/
@ -519,6 +525,10 @@ public class MovingCheck extends Check {
setActive(config.getBooleanValue("active.moving")); setActive(config.getBooleanValue("active.moving"));
enforceTeleport = config.getBooleanValue("moving.enforceteleport"); enforceTeleport = config.getBooleanValue("moving.enforceteleport");
stepWidth = ((double)config.getIntegerValue("moving.limits.walking")) /100D;
sneakWidth = ((double)config.getIntegerValue("moving.limits.sneaking"))/100D;
swimWidth = ((double)config.getIntegerValue("moving.limits.swimming"))/100D;
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
setActive(false); setActive(false);

View File

@ -6,34 +6,30 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
public class RunningCheck { public class RunningCheck {
public final static double stepWidth = 0.22D;
public final static double sneakWidth = 0.14D;
public final static double swimWidth = 0.18D;
public RunningCheck() { } public RunningCheck() { }
public double check(final Location from, final Location to, final boolean isSneaking, final boolean isSwimming, final MovingData data) { public double check(final Location from, final Location to, final boolean isSneaking, final boolean isSwimming, final MovingData data, MovingCheck check) {
// How much further did the player move than expected?? // How much further did the player move than expected??
double distanceAboveLimit = 0.0D; double distanceAboveLimit = 0.0D;
// First calculate the distance the player has moved horizontally // First calculate the distance the player has moved horizontally
final double xDistance = from.getX()-to.getX(); final double xDistance = from.getX()-to.getX();
final double zDistance = from.getZ()-to.getZ(); final double zDistance = from.getZ()-to.getZ();
final double totalDistance = Math.sqrt((xDistance*xDistance + zDistance*zDistance)); final double totalDistance = Math.sqrt((xDistance*xDistance + zDistance*zDistance));
// TODO: Also ask cc which to apply
if(isSneaking) { if(isSneaking) {
distanceAboveLimit = totalDistance - sneakWidth; distanceAboveLimit = totalDistance - check.sneakWidth;
} }
else if(isSwimming) { else if(isSwimming) {
distanceAboveLimit = totalDistance - swimWidth; distanceAboveLimit = totalDistance - check.swimWidth;
} }
else { else {
distanceAboveLimit = totalDistance - stepWidth; distanceAboveLimit = totalDistance - check.stepWidth;
} }
return distanceAboveLimit - data.horizFreedom; return distanceAboveLimit - data.horizFreedom;
} }
} }

View File

@ -50,7 +50,7 @@ public class NoCheatConfiguration {
// Setup the configuration tree // Setup the configuration tree
config(configurationFile, descriptionsFile); config(configurationFile, descriptionsFile);
} }
/** /**
@ -157,7 +157,7 @@ public class NoCheatConfiguration {
movingNode.add(new LongStringOption("summarymessage", movingNode.add(new LongStringOption("summarymessage",
SimpleYaml.getString("moving.summarymessage", "Moving summary of last ~[timeframe] seconds: [player] total Violations: [violations]", yamlContent))); SimpleYaml.getString("moving.summarymessage", "Moving summary of last ~[timeframe] seconds: [player] total Violations: [violations]", yamlContent)));
movingNode.add(new IntegerOption("summaryafter", movingNode.add(new IntegerOption("summaryafter",
SimpleYaml.getInt("moving.summaryafter", 15, yamlContent))); SimpleYaml.getInt("moving.summaryafter", 15, yamlContent)));
@ -176,6 +176,20 @@ public class NoCheatConfiguration {
movingNode.add(new BooleanOption("enforceteleport", movingNode.add(new BooleanOption("enforceteleport",
SimpleYaml.getBoolean("moving.enforceteleport", false, yamlContent))); SimpleYaml.getBoolean("moving.enforceteleport", false, yamlContent)));
/*** MOVING LIMITS section ***/
{
ParentOption movingLimitsNode = new ParentOption("limits", false);
movingNode.add(movingLimitsNode);
movingLimitsNode.add(new IntegerOption("walking",
SimpleYaml.getInt("moving.limits.walking", 22, yamlContent)));
movingLimitsNode.add(new IntegerOption("sneaking",
SimpleYaml.getInt("moving.limits.sneaking", 14, yamlContent)));
movingLimitsNode.add(new IntegerOption("swimming",
SimpleYaml.getInt("moving.limits.swimming", 18, yamlContent)));
}
/*** MOVING ACTION section ***/ /*** MOVING ACTION section ***/
{ {
ParentOption movingActionNode = new ParentOption("action", false); ParentOption movingActionNode = new ParentOption("action", false);
@ -235,13 +249,13 @@ public class NoCheatConfiguration {
bogusitemsNode.add(new BooleanOption("checkops", bogusitemsNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("bogusitems.checkops", false, yamlContent))); SimpleYaml.getBoolean("bogusitems.checkops", false, yamlContent)));
} }
/*** NUKE section ***/ /*** NUKE section ***/
{ {
ParentOption nukeNode = new ParentOption("nuke", false); ParentOption nukeNode = new ParentOption("nuke", false);
root.add(nukeNode); root.add(nukeNode);
nukeNode.add(new BooleanOption("checkops", nukeNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("nuke.checkops", false, yamlContent))); SimpleYaml.getBoolean("nuke.checkops", false, yamlContent)));
nukeNode.add(new LongStringOption("logmessage", nukeNode.add(new LongStringOption("logmessage",
@ -250,7 +264,7 @@ public class NoCheatConfiguration {
SimpleYaml.getString("nuke.kickmessage", "No nuking allowed", yamlContent))); SimpleYaml.getString("nuke.kickmessage", "No nuking allowed", yamlContent)));
nukeNode.add(new BooleanOption("limitreach", nukeNode.add(new BooleanOption("limitreach",
SimpleYaml.getBoolean("nuke.limitreach", true, yamlContent))); SimpleYaml.getBoolean("nuke.limitreach", true, yamlContent)));
} }
/*** CUSTOMACTIONS section ***/ /*** CUSTOMACTIONS section ***/
@ -418,7 +432,7 @@ public class NoCheatConfiguration {
public boolean getBooleanValue(String optionName) throws ConfigurationException { public boolean getBooleanValue(String optionName) throws ConfigurationException {
return getBooleanOption(optionName).getBooleanValue(); return getBooleanOption(optionName).getBooleanValue();
} }
private BooleanOption getBooleanOption(String optionName) throws ConfigurationException { private BooleanOption getBooleanOption(String optionName) throws ConfigurationException {
Option o = getOption(optionName); Option o = getOption(optionName);

View File

@ -135,6 +135,22 @@ public class Explainations {
"of other plugins to prevent/cancel the teleport. This is usually a 'not-so-nice' thing to do,\n" + "of other plugins to prevent/cancel the teleport. This is usually a 'not-so-nice' thing to do,\n" +
"but sometimes the only way to get the plugin to work properly in combination with others."); "but sometimes the only way to get the plugin to work properly in combination with others.");
set("moving.limits.walking", "How far can a player move with one step. The value doesn't represent any\n" +
"real distance units, it's just an indicator. 22 is about the normal walking speed of players.\n" +
"If you want to let them move faster, increase that number. If you decrease that number, players\n" +
"will have to move slower, but that will only work if they have a client mod that allows them to\n" +
"move slower than normal.");
set("moving.limits.sneaking", "How far can a player move while sneaking in one step. The value doesn't represent any\n" +
"real distance units, it's just an indicator. 14 is about the normal sneaking speed of players.\n" +
"If you want to let them sneak faster, increase that number. If you decrease that number, players\n" +
"will have to move even slower, but that will only work if they have a client mod that allows them to\n" +
"move slower than normal. If you have set \"allowfakesneak\" to true, this value is meaningless.");
set("moving.limits.swimming", "How far can a player move while swimming in one step. The value doesn't represent any\n" +
"real distance units, it's just an indicator. 18 is about the normal swimming speed of players.\n" +
"If you want to let them swim faster, increase that number. If you decrease that number, players\n" +
"will have to move even slower, but that will only work if they have a client mod that allows them to\n" +
"move slower than normal. If you have set \"allowfastswim\" to true, this value is meaningless.");
set("moving.action.low", "Execute these actions when a player moves further/higher in one step than the\n" + set("moving.action.low", "Execute these actions when a player moves further/higher in one step than the\n" +
"limits defined by this plugin allow.\n" + "limits defined by this plugin allow.\n" +
"Actions are executed in order. Available actions are loglow = log a message with low severeness,\n" + "Actions are executed in order. Available actions are loglow = log a message with low severeness,\n" +