Simpler access to isSprinting() and getGameMode()

This commit is contained in:
Evenprime 2011-11-15 14:42:02 +01:00
parent c5806da644
commit fb5225fac5
7 changed files with 18 additions and 17 deletions

View File

@ -15,6 +15,8 @@ public interface NoCheatPlayer {
public BaseData getData();
public boolean isSprinting();
public int getTicksLived();
public void increaseAge(int ticks);
@ -22,4 +24,6 @@ public interface NoCheatPlayer {
public ConfigurationCache getConfiguration();
public float getSpeedAmplifier();
public boolean isCreative();
}

View File

@ -5,7 +5,6 @@ import net.minecraft.server.Block;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -108,11 +107,6 @@ public class CheckUtil {
types[Material.TRAP_DOOR.getId()] |= SOLID | NONSOLID;
}
public static final boolean isSprinting(final Player player) {
return !(player.isSprinting() && player.getFoodLevel() > 5);
}
/**
* Check if certain coordinates are considered "on ground"
*

View File

@ -2,8 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import java.util.Locale;
import org.bukkit.GameMode;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
@ -31,7 +29,7 @@ public class ReachCheck extends BlockBreakCheck {
final SimpleLocation brokenBlock = data.brokenBlockLocation;
final double distance = CheckUtil.reachCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D, brokenBlock.z + 0.5D, player.getPlayer().getGameMode() == GameMode.CREATIVE ? cc.reachDistance + 2 : cc.reachDistance);
final double distance = CheckUtil.reachCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D, brokenBlock.z + 0.5D, player.isCreative() ? cc.reachDistance + 2 : cc.reachDistance);
if(distance > 0D) {
// Player failed the check

View File

@ -2,8 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving;
import java.util.Locale;
import org.bukkit.GameMode;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
@ -48,14 +46,14 @@ public class FlyingCheck extends MovingCheck {
// In case of creative gamemode, give at least 0.60 speed limit
// horizontal
double speedLimitHorizontal = player.getPlayer().getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
double speedLimitHorizontal = player.isCreative() ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
speedLimitHorizontal *= player.getSpeedAmplifier();
result += Math.max(0.0D, horizontalDistance - moving.horizFreedom - speedLimitHorizontal);
boolean sprinting = player.getPlayer().isSprinting();
boolean sprinting = player.isSprinting();
moving.bunnyhopdelay--;

View File

@ -1,7 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import org.bukkit.GameMode;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
@ -26,7 +24,7 @@ public class RunflyCheck extends MovingCheck {
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
final boolean runflyCheck = cc.runflyCheck && !player.hasPermission(Permissions.MOVING_RUNFLY);
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.getPlayer().getGameMode() == GameMode.CREATIVE && cc.identifyCreativeMode);
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.isCreative() && cc.identifyCreativeMode);
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
// If the player is not allowed to fly and not allowed to run

View File

@ -125,7 +125,7 @@ public class RunningCheck extends MovingCheck {
// How much further did the player move than expected??
double distanceAboveLimit = 0.0D;
final boolean sprinting = player.getPlayer().isSprinting();
final boolean sprinting = player.isSprinting();
double limit = 0.0D;

View File

@ -4,6 +4,7 @@ import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
@ -70,6 +71,10 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
}
}
public boolean isSprinting() {
return player.isSprinting() && player.getFoodLevel() > 5;
}
public void setLastUsedTime(long currentTimeInMilliseconds) {
this.lastUsedTime = System.currentTimeMillis();
}
@ -77,4 +82,8 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
public boolean shouldBeRemoved(long currentTimeInMilliseconds) {
return lastUsedTime + 60000L < currentTimeInMilliseconds;
}
public boolean isCreative() {
return player.getGameMode().equals(GameMode.CREATIVE);
}
}