From e3d9b693b32f3e031828303da7e49936409c39c9 Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 31 Oct 2012 05:52:14 +0100 Subject: [PATCH] Bleeding: Attempt to fix jump boost handling. --- .../checks/moving/CreativeFly.java | 18 +--------- .../nocheatplus/checks/moving/MovingData.java | 1 + .../checks/moving/MovingListener.java | 21 ++++++++++- .../checks/moving/SurvivalFly.java | 36 ++++++++----------- 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java index 0dfc397d..96c6f1ed 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java @@ -100,23 +100,7 @@ public class CreativeFly extends Check { resultH *= 100D; - // Is the player affected by the "jumping" potion. This is really just a very, very crude estimation and far - // from reality. - double jumpAmplifier = 1D; - if (entity.hasEffect(MobEffectList.JUMP)) { - final int amplifier = entity.getEffect(MobEffectList.JUMP).getAmplifier(); - if (amplifier > 20) - jumpAmplifier = 1.5D * (amplifier + 1D); - else - jumpAmplifier = 1.2D * (amplifier + 1D); - } - if (jumpAmplifier > data.jumpAmplifier) - data.jumpAmplifier = jumpAmplifier; - - final double limitV = cc.creativeFlyVerticalSpeed / 100D * VERTICAL_SPEED * data.jumpAmplifier; - - if (from.getY() >= to.getY() && data.jumpAmplifier > 0D) - data.jumpAmplifier--; + final double limitV = cc.creativeFlyVerticalSpeed / 100D * VERTICAL_SPEED; // * data.jumpAmplifier; // Super simple, just check distance compared to max distance vertical. final double resultV = Math.max(0D, yDistance - data.verticalFreedom - limitV) * 100D; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index b1cdf499..fc647d0b 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -145,6 +145,7 @@ public class MovingData extends ACheckData { public void clearFlyData() { bunnyhopDelay = 0; survivalFlyJumpPhase = 0; + jumpAmplifier = 0; setBack = null; survivalFlyLastYDist = Double.MAX_VALUE; fromX = toX = Double.MAX_VALUE; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 334c4319..69fab1db 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -3,10 +3,14 @@ package fr.neatmonster.nocheatplus.checks.moving; import java.util.ArrayList; import java.util.List; +import net.minecraft.server.EntityPlayer; +import net.minecraft.server.MobEffectList; + import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Vehicle; @@ -345,6 +349,21 @@ public class MovingListener implements Listener { final MovingData data = MovingData.getData(player); data.noFallAssumeGround = false; data.teleported = null; + + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // Potion effect "Jump". + final double jumpAmplifier; + if (mcPlayer.hasEffect(MobEffectList.JUMP)) { +// final int amplifier = mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); +// if (amplifier > 20) +// jumpAmplifier = 1.5D * (amplifier + 1D); +// else +// jumpAmplifier = 1.2D * (amplifier + 1D); + jumpAmplifier = 1D + mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + if (cc.debug) System.out.println(player.getName() + " Jump effect: " + data.jumpAmplifier); + } + else jumpAmplifier = 1D; + if (jumpAmplifier > data.jumpAmplifier) data.jumpAmplifier = jumpAmplifier; // Just try to estimate velocities over time. Not very precise, but works good enough most of the time. Do // general data modifications one for each event. @@ -378,7 +397,7 @@ public class MovingListener implements Listener { if ((cc.ignoreCreative || player.getGameMode() != GameMode.CREATIVE) && (cc.ignoreAllowFlight || !player.getAllowFlight()) && cc.survivalFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY)){ // If he is handled by the survival fly check, execute it. - newTo = survivalFly.check(player, pFrom, pTo, data, cc); + newTo = survivalFly.check(player, mcPlayer, pFrom, pTo, data, cc); // If don't have a new location and if he is handled by the no fall check, execute it. if (newTo == null && cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL)) // NOTE: noFall might set yOnGround for the positions. diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 6748992f..b1a81c2f 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -6,7 +6,6 @@ import net.minecraft.server.EntityPlayer; import net.minecraft.server.MobEffectList; import org.bukkit.Location; -import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; @@ -90,7 +89,7 @@ public class SurvivalFly extends Check { * the to * @return the location */ - public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) { + public Location check(final Player player, final EntityPlayer mcPlayer, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) { final long now = System.currentTimeMillis(); // A player is considered sprinting if the flag is set and if he has enough food level. @@ -150,6 +149,7 @@ public class SurvivalFly extends Check { // data.ground ? // ? set jumpphase to height / 0.15 ? data.survivalFlyJumpPhase = 0; + data.jumpAmplifier = 0; data.clearAccounting(); // Tell NoFall that we assume the player to have been on ground somehow. data.noFallAssumeGround = true; @@ -198,10 +198,10 @@ public class SurvivalFly extends Check { hAllowedDistance *= modIce; // Taken directly from Minecraft code, should work. - final EntityPlayer entity = ((CraftPlayer) player).getHandle(); + // player.hasPotionEffect(PotionEffectType.SPEED); - if (entity.hasEffect(MobEffectList.FASTER_MOVEMENT)) - hAllowedDistance *= 1.0D + 0.2D * (entity.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) + hAllowedDistance *= 1.0D + 0.2D * (mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1); // Account for flowing liquids (only if needed). if (hDistance > swimmingSpeed && from.isInLiquid() && from.isDownStream(xDistance, zDistance)){ @@ -250,25 +250,12 @@ public class SurvivalFly extends Check { } else data.horizontalBuffer = Math.min(1D, data.horizontalBuffer - hDistanceAboveLimit); - // Potion effect "Jump". - double jumpAmplifier = 1D; -// player.hasPotionEffect(PotionEffectType.JUMP) - if (entity.hasEffect(MobEffectList.JUMP)) { - final int amplifier = entity.getEffect(MobEffectList.JUMP).getAmplifier(); - if (amplifier > 20) - jumpAmplifier = 1.5D * (amplifier + 1D); - else - jumpAmplifier = 1.2D * (amplifier + 1D); - } - if (jumpAmplifier > data.jumpAmplifier) - data.jumpAmplifier = jumpAmplifier; - // Calculate the vertical speed limit based on the current jump phase. double vAllowedDistance, vDistanceAboveLimit; if (from.isInWeb()){ // Very simple: force players to descend or stay. vAllowedDistance = from.isOnGround() ? 0.1D : 0; - data.jumpAmplifier = 0; + data.jumpAmplifier = 0; vDistanceAboveLimit = yDistance; if (cc.survivalFlyCobwebHack && vDistanceAboveLimit > 0 && hDistanceAboveLimit <= 0){ if (now - data.survivalFlyCobwebTime > 3000){ @@ -290,9 +277,14 @@ public class SurvivalFly extends Check { } else{ vAllowedDistance = (!(fromOnGround || data.noFallAssumeGround) && !toOnGround ? 1.45D : 1.35D) + data.verticalFreedom; - vAllowedDistance *= data.jumpAmplifier; - if (data.survivalFlyJumpPhase > 6 + data.jumpAmplifier && data.verticalVelocityCounter <= 0){ - vAllowedDistance -= (data.survivalFlyJumpPhase - 6) * 0.15D; + final int maxJumpPhase; + if (data.jumpAmplifier > 0){ + vAllowedDistance += 0.5 + data.jumpAmplifier - 1.0; + maxJumpPhase = (int) (9 + (data.jumpAmplifier - 1.0) * 6); + } + else maxJumpPhase = 6; + if (data.survivalFlyJumpPhase > maxJumpPhase && data.verticalVelocityCounter <= 0){ + vAllowedDistance -= Math.max(0, (data.survivalFlyJumpPhase - maxJumpPhase) * 0.15D); } vDistanceAboveLimit = to.getY() - data.setBack.getY() - vAllowedDistance;