NoFallCheck implementation

This commit is contained in:
Evenprime 2011-09-19 19:28:56 +02:00
parent 41a09ea5ae
commit 1ac3c524e5
9 changed files with 140 additions and 22 deletions

View File

@ -30,6 +30,7 @@ permissions:
nocheat.checks.moving.swimming: true
nocheat.checks.moving.sneaking: true
nocheat.checks.moving.noclip: true
nocheat.checks.moving.nofall: true
nocheat.checks.moving.morepackets: true
nocheat.checks.blockbreak.*:
@ -69,6 +70,9 @@ permissions:
nocheat.checks.moving.noclip:
description: Allow a player to walk through walls
default: op
nocheat.checks.moving.nofall:
description: Allow a player to cheat and not take fall damage at all
default: op
nocheat.checks.moving.morepackets:
description: Allow a player to send more move-event-packets than normal, causing him to move faster than normal
default: op

View File

@ -77,22 +77,24 @@ public class DefaultConfiguration {
runflyNode.add(new IntegerOption("swimmingspeedlimit", 18));
ActionListOption walkactions = new ActionListOption("actions");
runflyNode.add(walkactions);
walkactions.add(0, "moveLogLowShort moveCancel");
walkactions.add(100, "moveLogMedShort moveCancel");
walkactions.add(400, "moveLogHighShort moveCancel");
runflyNode.add(new BooleanOption("checknofall", true, false));
runflyNode.add(new IntegerOption("nofallmultiplier", 100));
ActionListOption nofallactions = new ActionListOption("nofallactions");
runflyNode.add(nofallactions);
nofallactions.add(0, "nofallLog nofallCancel");
runflyNode.add(new BooleanOption("allowlimitedflying", false, false));
runflyNode.add(new IntegerOption("flyingspeedlimitvertical", 100));
runflyNode.add(new IntegerOption("flyingspeedlimithorizontal", 60));
ActionListOption flyactions = new ActionListOption("flyingactions");
runflyNode.add(flyactions);
flyactions.add(0, "moveLogLowShort moveCancel");
flyactions.add(100, "moveLogMedShort moveCancel");
flyactions.add(400, "moveLogHighShort moveCancel");
@ -330,6 +332,7 @@ public class DefaultConfiguration {
w(w, "log durabilityLog 0 1 med NC: [player] failed [check]: tried to use infinity durability hack.");
w(w, "log onliquidLog 2 1 med NC: [player] failed [check]: tried to place a block on liquids.");
w(w, "log spamLog 0 4 med NC: [player] failed [check]: Last sent message \"[text]\".");
w(w, "log nofallLog 0 1 med NC: [player] failed [check]: tried to avoid fall damage for ~[distance] blocks.");
w(w, "");
w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event.");
w(w, "# - They start with the word 'special'");
@ -344,6 +347,7 @@ public class DefaultConfiguration {
w(w, "special blockplaceCancel 0 0");
w(w, "special interactCancel 0 0");
w(w, "special spamCancel 0 0");
w(w, "special nofallCancel 0 0");
w(w, "");
w(w, "# CONSOLECOMMAND Actions: They will execute a command as if it were typed into the console.");
w(w, "# - They start with the word 'consolecommand'");

View File

@ -23,6 +23,7 @@ public class Permissions {
public final static String MOVE_SWIM = _MOVE + ".swimming";
public final static String MOVE_FLY = _MOVE + ".flying";
public final static String MOVE_NOCLIP = _MOVE + ".noclip";
public final static String MOVE_NOFALL = _MOVE + ".nofall";
public final static String MOVE_MOREPACKETS = _MOVE + ".morepackets";
public final static String BLOCKBREAK = _CHECKS + ".blockbreak.*";

View File

@ -0,0 +1,86 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import java.util.HashMap;
import java.util.Locale;
import net.minecraft.server.DamageSource;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.entity.EntityDamageEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutorWithHistory;
import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
/**
* A check to see if people cheat by tricking the server to not deal them
* fall damage.
*
* @author Evenprime
*
*/
public class NoFallCheck {
private final ActionExecutor action;
private final NoCheat plugin;
public NoFallCheck(NoCheat plugin) {
this.action = new ActionExecutorWithHistory(plugin);
this.plugin = plugin;
}
/**
* Calculate if and how much the player "failed" this check.
*
*/
public void check(final Player player, final Location from, final boolean fromOnOrInGround, final Location to, final boolean toOnOrInGround, final ConfigurationCache cc, final MovingData data) {
double oldY = from.getY();
double newY = to.getY();
// This check is pretty much always a step behind for technical reasons.
if(fromOnOrInGround) {
// Start with zero fall distance
data.fallDistance = 0F;
}
// We want to know if the fallDistance recorded by the game is smaller
// than the fall distance recorded by the plugin
float distance = data.fallDistance - player.getFallDistance();
if(distance > 0.01 && toOnOrInGround && data.fallDistance > 2.0F) {
data.nofallViolationLevel += distance;
// Prepare some event-specific values for logging and custom actions
HashMap<String, String> params = new HashMap<String, String>();
params.put(LogAction.DISTANCE, String.format(Locale.US, "%.2f", data.fallDistance));
params.put(LogAction.CHECK, "nofall");
boolean cancel = action.executeActions(player, cc.moving.nofallActions, (int) data.nofallViolationLevel, params, cc);
// If "cancelled", the fall damage gets dealt in a way that's visible to other players
if(cancel) {
// Increase the damage a bit :)
float totalDistance = (data.fallDistance - 2.0F)* cc.moving.nofallMultiplier + 2.0F;
player.setFallDistance(totalDistance);
((CraftPlayer)player).getHandle().b(totalDistance, true);
}
data.fallDistance = 0F;
}
// Reduce falldamage violation level
data.nofallViolationLevel *= 0.99D;
// Increase the fall distance that is recorded by the plugin
if(!toOnOrInGround && oldY > newY) {
data.fallDistance += (float) (oldY - newY);
}
}
}

View File

@ -23,6 +23,7 @@ public class RunFlyCheck {
private final FlyingCheck flyingCheck;
private final RunningCheck runningCheck;
private final NoclipCheck noclippingCheck;
private final NoFallCheck noFallCheck;
private final MorePacketsCheck morePacketsCheck;
private final MovingEventHelper helper;
@ -31,7 +32,8 @@ public class RunFlyCheck {
this.helper = new MovingEventHelper();
this.flyingCheck = new FlyingCheck(plugin);
this.runningCheck = new RunningCheck(plugin);
this.noFallCheck = new NoFallCheck(plugin);
this.runningCheck = new RunningCheck(plugin, noFallCheck);
this.noclippingCheck = new NoclipCheck(plugin);
this.morePacketsCheck = new MorePacketsCheck(plugin);
}

View File

@ -31,11 +31,14 @@ public class RunningCheck {
// How many move events can a player have in air before he is expected to
// lose altitude (or eventually land somewhere)
private final static int jumpingLimit = 6;
private final ActionExecutor action;
public RunningCheck(NoCheat plugin) {
private final NoFallCheck noFallCheck;
public RunningCheck(NoCheat plugin, NoFallCheck noFallCheck) {
this.action = new ActionExecutorWithHistory(plugin);
this.noFallCheck = noFallCheck;
}
public Location check(final Player player, final Location from, final Location to, final MovingEventHelper helper, final ConfigurationCache cc, final MovingData data) {
@ -105,6 +108,13 @@ public class RunningCheck {
data.jumpPhase = 0;
}
}
/********* EXECUTE THE NOFALL CHECK ********************/
final boolean checkNoFall = cc.moving.nofallCheck && !player.hasPermission(Permissions.MOVE_NOFALL);
if(checkNoFall && newToLocation == null) {
noFallCheck.check(player, from, fromOnGround || fromInGround, to, toOnGround || toInGround, cc, data);
}
return newToLocation;
}
@ -176,7 +186,6 @@ public class RunningCheck {
double distanceAboveLimit = 0.0D;
final double toY = to.getY();
final double fromY = from.getY();
double limit = data.vertFreedom + cc.moving.jumpheight;

View File

@ -13,7 +13,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Configuration;
public class CCMoving {
public final boolean check;
public final boolean runflyCheck;
public final double walkingSpeedLimit;
public final double sprintingSpeedLimit;
@ -31,6 +31,10 @@ public class CCMoving {
public final boolean noclipCheck;
public final ActionList noclipActions;
public final boolean nofallCheck;
public final float nofallMultiplier;
public final ActionList nofallActions;
public final boolean morePacketsCheck;
public final ActionList morePacketsActions;
@ -43,17 +47,21 @@ public class CCMoving {
sprintingSpeedLimit = ((double) data.getInteger("moving.runfly.sprintingspeedlimit")) / 100D;
jumpheight = ((double) data.getInteger("moving.runfly.jumpheight")) / 100D;
actions = data.getActionList("moving.runfly.actions");
swimmingCheck = data.getBoolean("moving.runfly.checkswimming");
swimmingSpeedLimit = ((double) data.getInteger("moving.runfly.swimmingspeedlimit")) / 100D;
sneakingCheck = data.getBoolean("moving.runfly.checksneaking");
sneakingSpeedLimit = ((double) data.getInteger("moving.runfly.sneakingspeedlimit")) / 100D;
allowFlying = data.getBoolean("moving.runfly.allowlimitedflying");
flyingSpeedLimitVertical = ((double) data.getInteger("moving.runfly.flyingspeedlimitvertical")) / 100D;
flyingSpeedLimitHorizontal = ((double) data.getInteger("moving.runfly.flyingspeedlimithorizontal")) / 100D;
flyingActions = data.getActionList("moving.runfly.flyingactions");
nofallCheck = data.getBoolean("moving.runfly.checknofall");
nofallMultiplier = ((float) data.getInteger("moving.runfly.nofallmultiplier")) / 100F;
nofallActions = data.getActionList("moving.runfly.nofallactions");
noclipCheck = data.getBoolean("moving.noclip.check");
noclipActions = data.getActionList("moving.noclip.actions");

View File

@ -10,32 +10,35 @@ import org.bukkit.Location;
*/
public class MovingData {
public int jumpPhase = 0;
public int jumpPhase = 0;
public Location runflySetBackPoint = null;
public Location runflySetBackPoint = null;
public double runflyViolationLevel = 0.0D;
public double runflyViolationLevel = 0.0D;
public double vertFreedom = 0.0D;
public double vertVelocity = 0.0D;
public int vertVelocityCounter = 0;
public double horizFreedom = 0.0D;
public int horizVelocityCounter = 0;
public double vertFreedom = 0.0D;
public double vertVelocity = 0.0D;
public int vertVelocityCounter = 0;
public double horizFreedom = 0.0D;
public int horizVelocityCounter = 0;
public double nofallViolationLevel = 0.0D;
public float fallDistance = 0.0F;
public int noclipX;
public int noclipY;
public int noclipZ;
public double horizontalBuffer;
public int bunnyhopdelay = 0;
public int bunnyhopdelay = 0;
public int morePacketsCounter;
public double morePacketsBuffer = 50;
public double morePacketsBuffer = 50;
public Location morePacketsSetbackPoint;
public double morePacketsViolationLevel = 0;
public Location teleportTo;
public int lastElapsedIngameSeconds = 0;
public int lastElapsedIngameSeconds = 0;
}

View File

@ -90,6 +90,7 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
data.morePacketsCounter = 0;
data.morePacketsSetbackPoint = null;
data.jumpPhase = 0;
data.fallDistance = 0F;
if(newLocation != null) {