mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-28 03:17:53 +01:00
Removed "precisevelocity" option because it is no longer needed +
added option to allow flying generally + much more reliable way to determine a players velocity before Minecraft taints the values
This commit is contained in:
parent
2781965d53
commit
7390acdd39
@ -3,7 +3,7 @@ name: NoCheat
|
||||
author: Evenprime
|
||||
|
||||
main: cc.co.evenprime.bukkit.nocheat.NoCheat
|
||||
version: 0.8.3
|
||||
version: 0.8.3a
|
||||
|
||||
commands:
|
||||
nocheat:
|
||||
|
@ -25,6 +25,7 @@ import cc.co.evenprime.bukkit.nocheat.listeners.AirbuildListener;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.BedteleportListener;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.MovingListener;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.MovingMonitor;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.MovingEntityListener;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.SpeedhackListener;
|
||||
|
||||
import com.ensifera.animosity.craftirc.CraftIRC;
|
||||
@ -174,7 +175,10 @@ public class NoCheat extends JavaPlugin {
|
||||
// Register listeners for moving check
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, new MovingListener(movingCheck), Priority.Lowest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, new MovingMonitor(movingCheck), Priority.Monitor, this);
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, new MovingMonitor(movingCheck), Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, new MovingMonitor(movingCheck), Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, new MovingEntityListener(movingCheck), Priority.Monitor, this);
|
||||
|
||||
// Register listeners for speedhack check
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, new SpeedhackListener(speedhackCheck), Priority.High, this);
|
||||
|
||||
|
@ -95,17 +95,17 @@ public class NoCheatConfiguration {
|
||||
plugin.speedhackCheck.limits[2] = c.getInt("speedhack.limits.high", plugin.speedhackCheck.limits[2]);
|
||||
|
||||
plugin.speedhackCheck.logMessage = c.getString("speedhack.logmessage", plugin.speedhackCheck.logMessage);
|
||||
|
||||
|
||||
plugin.movingCheck.actions[0] = stringToActions(c.getString("moving.action.low"), plugin.movingCheck.actions[0]);
|
||||
plugin.movingCheck.actions[1] = stringToActions(c.getString("moving.action.med"), plugin.movingCheck.actions[1]);
|
||||
plugin.movingCheck.actions[2] = stringToActions(c.getString("moving.action.high"), plugin.movingCheck.actions[2]);
|
||||
|
||||
|
||||
|
||||
plugin.movingCheck.logMessage = c.getString("moving.logmessage", plugin.movingCheck.logMessage);
|
||||
plugin.movingCheck.summaryMessage = c.getString("moving.summarymessage", plugin.movingCheck.summaryMessage);
|
||||
|
||||
plugin.movingCheck.preciseVelocity = c.getBoolean("moving.precisevelocity", plugin.movingCheck.preciseVelocity);
|
||||
|
||||
|
||||
plugin.movingCheck.allowFlying = c.getBoolean("moving.allowFlying", plugin.movingCheck.allowFlying);
|
||||
|
||||
plugin.speedhackCheck.actions[0] = stringToActions(c.getString("speedhack.action.low"), plugin.speedhackCheck.actions[0]);
|
||||
plugin.speedhackCheck.actions[1] = stringToActions(c.getString("speedhack.action.med"), plugin.speedhackCheck.actions[1]);
|
||||
plugin.speedhackCheck.actions[2] = stringToActions(c.getString("speedhack.action.high"), plugin.speedhackCheck.actions[2]);
|
||||
@ -245,8 +245,8 @@ public class NoCheatConfiguration {
|
||||
w.write("moving:"); w.newLine();
|
||||
w.write(" logmessage: \"" + plugin.movingCheck.logMessage+"\""); w.newLine();
|
||||
w.write(" summarymessage: \"" + plugin.movingCheck.summaryMessage+"\""); w.newLine();
|
||||
w.write("# If you get problems with plugins that accellerate players movement, try setting this to false"); w.newLine();
|
||||
w.write(" precisevelocity: \"" + plugin.movingCheck.preciseVelocity+"\""); w.newLine();
|
||||
w.write("# Should (normal speed) flying be generally allowed?"); w.newLine();
|
||||
w.write(" allowflying: \"" + plugin.movingCheck.allowFlying+"\""); w.newLine();
|
||||
w.write("# Moving Action, one or more of 'loglow logmed loghigh cancel'"); w.newLine();
|
||||
w.write(" action:"); w.newLine();
|
||||
w.write(" low: "+actionsToString(plugin.movingCheck.actions[0])); w.newLine();
|
||||
|
@ -38,6 +38,7 @@ public class NoCheatData {
|
||||
|
||||
public int airbuildPerSecond = 0;
|
||||
public Runnable airbuildSummaryTask = null;
|
||||
public double maxYVelocity = 0.0D;
|
||||
|
||||
public NoCheatData() { }
|
||||
}
|
@ -45,7 +45,7 @@ public class MovingCheck extends Check {
|
||||
|
||||
public int ticksBeforeSummary = 100;
|
||||
|
||||
public int ticksDelayForVelocity = 40;
|
||||
public boolean allowFlying = false;
|
||||
|
||||
// How should moving violations be treated?
|
||||
public final Action actions[][] = {
|
||||
@ -56,8 +56,6 @@ public class MovingCheck extends Check {
|
||||
public String logMessage = "Moving violation: %1$s from %2$s (%4$.5f, %5$.5f, %6$.5f) to %3$s (%7$.5f, %8$.5f, %9$.5f)";
|
||||
public String summaryMessage = "Moving summary of last ~%2$d seconds: %1$s total Violations: (%3$d,%4$d,%5$d)";
|
||||
|
||||
public boolean preciseVelocity = true;
|
||||
|
||||
private static final double magic = 0.30000001192092896D;
|
||||
private static final double magic2 = 0.69999998807907103D;
|
||||
|
||||
@ -167,10 +165,10 @@ public class MovingCheck extends Check {
|
||||
if(plugin.hasPermission(event.getPlayer(), "nocheat.moving"))
|
||||
return;
|
||||
|
||||
boolean flyingAllowed = false;
|
||||
boolean canFly = false;
|
||||
|
||||
if(plugin.hasPermission(event.getPlayer(), "nocheat.flying"))
|
||||
flyingAllowed = true;
|
||||
if(allowFlying || plugin.hasPermission(event.getPlayer(), "nocheat.flying"))
|
||||
canFly = true;
|
||||
|
||||
// Get the player-specific data
|
||||
final NoCheatData data = plugin.getPlayerData(event.getPlayer());
|
||||
@ -202,38 +200,19 @@ public class MovingCheck extends Check {
|
||||
return; // players are allowed to "teleport" into a bed over "short" distances
|
||||
}
|
||||
|
||||
// Give additional movement based on velocity (not too precise, but still better than false positives)
|
||||
Vector v = event.getPlayer().getVelocity();
|
||||
updateVelocity(event.getPlayer());
|
||||
/**** Horizontal movement check START ****/
|
||||
|
||||
int vl1 = -1;
|
||||
|
||||
if(preciseVelocity) {
|
||||
// Compare the velocity vector to the existing movement freedom that we've from previous events
|
||||
double tmp = Math.abs(v.getX()*5D) + Math.abs(v.getZ()*5D);
|
||||
if(tmp > data.movingHorizFreedom)
|
||||
data.movingHorizFreedom = tmp;
|
||||
else
|
||||
data.movingHorizFreedom *= 0.9;
|
||||
vl1 = limitCheck(combined - (data.movingHorizFreedom + 0.6D), moveLimits);
|
||||
|
||||
// Violation level
|
||||
vl1 = limitCheck(combined - (data.movingHorizFreedom + 0.6D), moveLimits);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compare the velocity vector to the existing movement freedom that we've from previous events
|
||||
double tmp = Math.abs(v.getX()) + Math.abs(v.getZ());
|
||||
// Reduce horiz moving freedom with each event
|
||||
data.movingHorizFreedom *= 0.9;
|
||||
|
||||
if(tmp > data.movingHorizFreedom || tmp > 1.0D)
|
||||
data.movingHorizFreedomCounter = 20;
|
||||
else if(data.movingHorizFreedomCounter > 0 )
|
||||
data.movingHorizFreedomCounter--;
|
||||
/**** Horizontal movement check END ****/
|
||||
|
||||
data.movingHorizFreedom = tmp;
|
||||
|
||||
// Violation level
|
||||
vl1 = limitCheck(combined - ((data.movingHorizFreedomCounter > 0 ? 15.0D : 0.6D)), moveLimits);
|
||||
}
|
||||
|
||||
/**** Vertical movement check START ****/
|
||||
// pre-calculate boundary values that are needed multiple times in the following checks
|
||||
// the array each contains [lowerX, higherX, Y, lowerZ, higherZ]
|
||||
int fromValues[] = {lowerBorder(from.getX()), upperBorder(from.getX()), (int)Math.floor(from.getY()+0.5D), lowerBorder(from.getZ()),upperBorder(from.getZ()) };
|
||||
@ -255,14 +234,16 @@ public class MovingCheck extends Check {
|
||||
// its movement, plus additional events if the "velocity" was big and can cause longer flights
|
||||
|
||||
// The server sent the player a "velocity" packet a short time ago
|
||||
if(v.getY() > 0.0D) {
|
||||
data.movingVertFreedomCounter = ticksDelayForVelocity;
|
||||
if(data.maxYVelocity > 0.0D) {
|
||||
data.movingVertFreedomCounter = 30;
|
||||
|
||||
// Be generous with the height limit for the client
|
||||
data.movingVertFreedom += v.getY()*3D;
|
||||
data.movingVertFreedom += data.maxYVelocity*2D;
|
||||
data.maxYVelocity = 0.0D;
|
||||
}
|
||||
// If the server no longer has a positive velocity, start consuming the event counter for this client
|
||||
else if(data.movingVertFreedomCounter > 0) {
|
||||
|
||||
// consume a counter for this client
|
||||
if(data.movingVertFreedomCounter > 0) {
|
||||
data.movingVertFreedomCounter--;
|
||||
}
|
||||
|
||||
@ -277,10 +258,10 @@ public class MovingCheck extends Check {
|
||||
Location newSetBack = null;
|
||||
|
||||
// there's no use for counting this
|
||||
if(flyingAllowed) data.movingJumpPhase = 0;
|
||||
|
||||
if(canFly) data.movingJumpPhase = 0;
|
||||
|
||||
// Handle 4 distinct cases: Walk, Jump, Land, Fly
|
||||
|
||||
|
||||
// Walk or start Jump
|
||||
if(onGroundFrom)
|
||||
{
|
||||
@ -304,13 +285,13 @@ public class MovingCheck extends Check {
|
||||
else
|
||||
{
|
||||
Location l = null;
|
||||
|
||||
if(data.movingSetBackPoint == null || flyingAllowed)
|
||||
|
||||
if(data.movingSetBackPoint == null || canFly)
|
||||
l = from;
|
||||
else
|
||||
l = data.movingSetBackPoint;
|
||||
|
||||
if(!flyingAllowed && data.movingJumpPhase > jumpingLimit)
|
||||
if(!canFly && data.movingJumpPhase > jumpingLimit)
|
||||
limit += jumpHeight - (data.movingJumpPhase-jumpingLimit) * 0.2D;
|
||||
else limit += jumpHeight;
|
||||
|
||||
@ -406,6 +387,21 @@ public class MovingCheck extends Check {
|
||||
data.movingTeleportTo = event.getTo();
|
||||
}
|
||||
|
||||
|
||||
public void updateVelocity(Player player) {
|
||||
NoCheatData data = plugin.getPlayerData(player);
|
||||
|
||||
Vector v = player.getVelocity();
|
||||
|
||||
// Compare the velocity vector to the existing movement freedom that we've from previous events
|
||||
double tmp = Math.abs(v.getX()*2D) + Math.abs(v.getZ()*2D);
|
||||
if(tmp > data.movingHorizFreedom)
|
||||
data.movingHorizFreedom = tmp;
|
||||
|
||||
if(v.getY() > data.maxYVelocity) {
|
||||
data.maxYVelocity = v.getY();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Perform actions that were specified in the config file
|
||||
* @param event
|
||||
|
@ -0,0 +1,25 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
|
||||
|
||||
public class MovingEntityListener extends EntityListener {
|
||||
|
||||
private MovingCheck check;
|
||||
|
||||
public MovingEntityListener(MovingCheck check) {
|
||||
this.check = check;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if(event.getEntity() instanceof Player) {
|
||||
check.updateVelocity((Player)event.getEntity());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -25,4 +25,5 @@ public class MovingListener extends PlayerListener {
|
||||
if(!event.isCancelled() && check.isActive())
|
||||
check.check(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.listeners;
|
||||
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
|
||||
@ -20,7 +22,16 @@ public class MovingMonitor extends PlayerListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
|
||||
check.teleported(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
check.updateVelocity(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
check.updateVelocity(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user