Add depth strider support.

This commit is contained in:
asofold 2014-12-05 11:47:34 +01:00
parent 7b5f22e64d
commit 7b51b1ae43
4 changed files with 298 additions and 247 deletions

View File

@ -17,7 +17,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.7.9-R0.2</version> <version>1.8-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.neatmonster</groupId> <groupId>fr.neatmonster</groupId>

View File

@ -14,6 +14,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.compat.BridgeEnchant;
import fr.neatmonster.nocheatplus.logging.Streams; import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.ActionAccumulator; import fr.neatmonster.nocheatplus.utilities.ActionAccumulator;
@ -33,7 +34,7 @@ public class SurvivalFly extends Check {
// Tags // Tags
private static final String DOUBLE_BUNNY = "doublebunny"; private static final String DOUBLE_BUNNY = "doublebunny";
// Horizontal speeds/modifiers. // Horizontal speeds/modifiers/factors (modifier: speed = walkspeed * modX, factors: speed *= fY).
public static final double walkSpeed = 0.221D; public static final double walkSpeed = 0.221D;
public static final double modSneak = 0.13D / walkSpeed; public static final double modSneak = 0.13D / walkSpeed;
@ -41,10 +42,16 @@ public class SurvivalFly extends Check {
public static final double modBlock = 0.16D / walkSpeed; public static final double modBlock = 0.16D / walkSpeed;
public static final double modSwim = 0.115D / walkSpeed; public static final double modSwim = 0.115D / walkSpeed;
public static final double[] fDepthStrider = new double[] {
1.0,
0.1645 / modSwim / walkSpeed,
0.1995 / modSwim / walkSpeed,
1.0 / modSwim, // Results in walkspeed.
};
public static final double modWeb = 0.105D / walkSpeed; // TODO: walkingSpeed * 0.15D; <- does not work public static final double modWeb = 0.105D / walkSpeed; // TODO: walkingSpeed * 0.15D; <- does not work
public static final double modIce = 2.5D; public static final double fIce = 2.5D; //
/** Faster moving down stream (water mainly). */ /** Faster moving down stream (water mainly). */
public static final double modDownStream = 0.19 / (walkSpeed * modSwim); public static final double modDownStream = 0.19 / (walkSpeed * modSwim);
@ -519,10 +526,14 @@ public class SurvivalFly extends Check {
hAllowedDistance = modWeb * walkSpeed * cc.survivalFlyWalkingSpeed / 100D; hAllowedDistance = modWeb * walkSpeed * cc.survivalFlyWalkingSpeed / 100D;
} else if (from.isInLiquid() && to.isInLiquid()) { } else if (from.isInLiquid() && to.isInLiquid()) {
// Check all liquids (lava might demand even slower speed though). // Check all liquids (lava might demand even slower speed though).
// TODO: too many false positives with just checking from ? // TODO: Test how to go with only checking from (less dolphins).
// TODO: Sneaking and blocking applies to when in water ! // TODO: Sneaking and blocking applies to when in water !
hAllowedDistance = modSwim * walkSpeed * cc.survivalFlySwimmingSpeed / 100D; hAllowedDistance = modSwim * walkSpeed * cc.survivalFlySwimmingSpeed / 100D;
// TODO: Depth strider. final int level = BridgeEnchant.getDepthStriderLevel(player);
if (level > 0) {
// The hard way.
hAllowedDistance *= fDepthStrider[level];
}
} else if (!sfDirty && player.isSneaking() && reallySneaking.contains(player.getName()) && (!checkPermissions || !player.hasPermission(Permissions.MOVING_SURVIVALFLY_SNEAKING))) { } else if (!sfDirty && player.isSneaking() && reallySneaking.contains(player.getName()) && (!checkPermissions || !player.hasPermission(Permissions.MOVING_SURVIVALFLY_SNEAKING))) {
hAllowedDistance = modSneak * walkSpeed * cc.survivalFlySneakingSpeed / 100D; hAllowedDistance = modSneak * walkSpeed * cc.survivalFlySneakingSpeed / 100D;
} }
@ -556,7 +567,7 @@ public class SurvivalFly extends Check {
// If the player is on ice, give them a higher maximum speed. // If the player is on ice, give them a higher maximum speed.
if (data.sfOnIce > 0) { if (data.sfOnIce > 0) {
hAllowedDistance *= modIce; hAllowedDistance *= fIce;
} }
// TODO: Attributes // TODO: Attributes

View File

@ -0,0 +1,32 @@
package fr.neatmonster.nocheatplus.compat;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public final class BridgeEnchant {
private static Enchantment DEPTH_STRIDER = null;
static {
try {
DEPTH_STRIDER = Enchantment.DEPTH_STRIDER;
} catch (Throwable t) {}
}
public static int getDepthStriderLevel(Player player) {
if (DEPTH_STRIDER != null) {
final ItemStack boots = player.getInventory().getBoots();
if (boots != null && boots.getType() != Material.AIR) {
return Math.min(3, boots.getEnchantmentLevel(BridgeEnchant.DEPTH_STRIDER));
}
}
return 0;
}
public static boolean hasDepthStrider() {
return DEPTH_STRIDER != null;
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.compat.BridgeEnchant;
import fr.neatmonster.nocheatplus.compat.MCAccess; import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.BlockProperties; import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation; import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
@ -199,6 +200,7 @@ public class DebugUtil {
} }
final double jump = mcAccess.getJumpAmplifier(player); final double jump = mcAccess.getJumpAmplifier(player);
final double speed = mcAccess.getFasterMovementAmplifier(player); final double speed = mcAccess.getFasterMovementAmplifier(player);
final double strider = BridgeEnchant.getDepthStriderLevel(player);
if (BuildParameters.debugLevel > 0){ if (BuildParameters.debugLevel > 0){
try{ try{
// TODO: Check backwards compatibility (1.4.2). Remove try-catch // TODO: Check backwards compatibility (1.4.2). Remove try-catch
@ -213,8 +215,14 @@ public class DebugUtil {
builder.append("(sneaking)"); builder.append("(sneaking)");
} }
} }
if (speed != Double.NEGATIVE_INFINITY || jump != Double.NEGATIVE_INFINITY){ if (speed != Double.NEGATIVE_INFINITY){
builder.append(" (" + (speed != Double.NEGATIVE_INFINITY ? ("e_speed=" + (speed + 1)) : "") + (jump != Double.NEGATIVE_INFINITY ? ("e_jump=" + (jump + 1)) : "") + ")"); builder.append("(e_speed=" + (speed + 1) + ")");
}
if (jump != Double.NEGATIVE_INFINITY){
builder.append("(e_jump=" + (jump + 1) + ")");
}
if (strider != 0){
builder.append("(e_depth_strider=" + strider + ")");
} }
// Print basic info first in order // Print basic info first in order
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, builder.toString()); NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, builder.toString());