Add hidden settings for setting the size for the on-ground

bounding box for moving (creativefly+survivalfly) and nofall checks.
[Using a
bigger default one for nofall reduces false positives a lot.]
This commit is contained in:
asofold 2012-08-31 12:47:30 +02:00
parent 68519185a8
commit f5ef5ac3be
5 changed files with 60 additions and 6 deletions

View File

@ -83,6 +83,11 @@ public class MovingConfig implements CheckConfig {
public final int survivalFlySwimmingSpeed;
public final int survivalFlyWalkingSpeed;
public final ActionList survivalFlyActions;
public final double noFallyOnGround;
public final double yOnGround;
/**
* Instantiates a new moving configuration.
@ -115,6 +120,15 @@ public class MovingConfig implements CheckConfig {
survivalFlySwimmingSpeed = data.getInt(ConfPaths.MOVING_SURVIVALFLY_SWIMMINGSPEED, 100);
survivalFlyWalkingSpeed = data.getInt(ConfPaths.MOVING_SURVIVALFLY_WALKINGSPEED, 100);
survivalFlyActions = data.getActionList(ConfPaths.MOVING_SURVIVALFLY_ACTIONS, Permissions.MOVING_SURVIVALFLY);
yOnGround = readyOnGround(data, ConfPaths.MOVING_YONGROUND, 0.001);
noFallyOnGround = readyOnGround(data, ConfPaths.MOVING_NOFALL_YONGROUND, 0.3);
}
private final double readyOnGround(final ConfigFile data, final String path, final double preset){
final double yOnGround = data.getDouble(path, preset);
if (yOnGround < 0 || yOnGround > 2.0) return 2.0;
else return yOnGround;
}
/* (non-Javadoc)

View File

@ -308,7 +308,9 @@ public class MovingListener implements Listener {
// Don't care for movements to another world (such that it is very likely the event data was modified by another
// plugin before we got it) or if the player is inside a vehicle.
if (!event.getFrom().getWorld().equals(event.getTo().getWorld()) || player.isInsideVehicle())
final Location from = event.getFrom();
final Location to = event.getTo();
if (!from.getWorld().equals(to.getWorld()) || player.isInsideVehicle())
return;
final MovingData data = MovingData.getData(player);
@ -328,11 +330,12 @@ public class MovingListener implements Listener {
} else if (data.verticalFreedom > 0.001D)
// Counter has run out, now reduce the vertical freedom over time.
data.verticalFreedom *= 0.93D;
data.from.set(event.getFrom(), player);
final double yOnGround = MovingConfig.getConfig(player).yOnGround;
data.from.set(from, player, yOnGround);
if (data.from.isOnGround())
data.ground = data.from.getLocation();
data.to.set(event.getTo(), player);
data.to.set(to, player, yOnGround);
Location newTo = null;
@ -344,6 +347,7 @@ public class MovingListener implements Listener {
newTo = survivalFly.check(player, data.from, data.to);
// If don't have a new location and if he is handled by the no fall check, execute it.
if (newTo == null && noFall.isEnabled(player))
// NOTE: noFall might set yOnGround for the positions.
noFall.check(player, data.from, data.to);
} else
// He isn't handled by any fly check, clear his data.

View File

@ -47,6 +47,11 @@ public class NoFall extends Check {
public void check(final Player player, final PlayerLocation from, final PlayerLocation to) {
final MovingConfig cc = MovingConfig.getConfig(player);
final MovingData data = MovingData.getData(player);
if (from.getY() > to.getY()){
if (from.getyOnGround() != cc.noFallyOnGround) from.setyOnGround(cc.noFallyOnGround);
if (to.getyOnGround() != cc.noFallyOnGround) to.setyOnGround(cc.noFallyOnGround);
}
data.noFallWasOnGround = data.noFallOnGround;
data.noFallOnGround = to.isOnGround();

View File

@ -328,6 +328,10 @@ public abstract class ConfPaths {
public static final String MOVING_SURVIVALFLY_SWIMMINGSPEED = MOVING_SURVIVALFLY + "swimmingspeed";
public static final String MOVING_SURVIVALFLY_WALKINGSPEED = MOVING_SURVIVALFLY + "walkingspeed";
public static final String MOVING_SURVIVALFLY_ACTIONS = MOVING_SURVIVALFLY + "actions";
// Special (to be sorted in or factored out).
public static final String MOVING_NOFALL_YONGROUND = MOVING_NOFALL + "yonground";
public static final String MOVING_YONGROUND = MOVING + "yonground";
/*
* dP"8 d8 ,e,
@ -339,4 +343,5 @@ public abstract class ConfPaths {
* "8",P"
*/
public static final String STRINGS = "strings";
}

View File

@ -66,6 +66,9 @@ public class PlayerLocation {
/** The bounding box of the player. */
private AxisAlignedBB boundingBox;
/** Y parameter for growing the bounding box with the isOnGround check.*/
private double yOnGround = 0.001;
/** The entity player. */
private EntityPlayer entity;
@ -208,7 +211,7 @@ public class PlayerLocation {
public boolean isOnGround() {
if (onGround == null) {
AxisAlignedBB boundingBoxGround = boundingBox.clone();
boundingBoxGround = boundingBoxGround.d(0D, -0.001D, 0D);
boundingBoxGround = boundingBoxGround.d(0D, -getyOnGround(), 0D);
onGround = world.getCubes(entity, boundingBoxGround).size() > 0;
}
return onGround;
@ -238,6 +241,18 @@ public class PlayerLocation {
onLadder = world.getTypeId(x, y, z) == Block.LADDER.id || world.getTypeId(x, y, z) == Block.VINE.id;
return onLadder;
}
/**
* Sets the player location object.
*
* @param location
* the location
* @param player
* the player
*/
public void set(final Location location, final Player player){
set(location, player, 0.001);
}
/**
* Sets the player location object.
@ -247,7 +262,7 @@ public class PlayerLocation {
* @param player
* the player
*/
public void set(final Location location, final Player player) {
public void set(final Location location, final Player player, final double yFreedom) {
this.location = location;
entity = ((CraftPlayer) player).getHandle();
@ -259,5 +274,16 @@ public class PlayerLocation {
world = ((CraftWorld) location.getWorld()).getHandle();
aboveStairs = inLava = inWater = inWeb = onGround = onIce = onLadder = null;
this.setyOnGround(yFreedom);
}
public double getyOnGround() {
return yOnGround;
}
public void setyOnGround(final double yOnGround) {
this.yOnGround = yOnGround;
this.onGround = null;
}
}