mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-24 16:31:29 +01:00
Reviewing several places for use of Double.MAX_VALUE and similar.
(No game-changing stuff.)
This commit is contained in:
parent
ce5a90201c
commit
9c29d32a98
@ -67,10 +67,12 @@ public class BlockBreakListener extends CheckListener {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// Illegal enchantments hotfix check.
|
||||
if (Items.checkIllegalEnchantments(player, player.getItemInHand())) event.setCancelled(true);
|
||||
if (Items.checkIllegalEnchantments(player, player.getItemInHand())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Cancelled events only leads to resetting insta break.
|
||||
if (event.isCancelled()){
|
||||
if (event.isCancelled()) {
|
||||
isInstaBreak = false;
|
||||
return;
|
||||
}
|
||||
@ -92,38 +94,45 @@ public class BlockBreakListener extends CheckListener {
|
||||
final GameMode gameMode = player.getGameMode();
|
||||
|
||||
// Has the player broken a block that was not damaged before?
|
||||
if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block, cc, data, isInstaBreak))
|
||||
if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block, cc, data, isInstaBreak)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Has the player broken more blocks per second than allowed?
|
||||
if (!cancelled && frequency.isEnabled(player) && frequency.check(player, cc, data))
|
||||
if (!cancelled && frequency.isEnabled(player) && frequency.check(player, cc, data)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Has the player broken blocks faster than possible?
|
||||
if (!cancelled && gameMode != GameMode.CREATIVE && fastBreak.isEnabled(player) && fastBreak.check(player, block, isInstaBreak, cc, data))
|
||||
if (!cancelled && gameMode != GameMode.CREATIVE && fastBreak.isEnabled(player) && fastBreak.check(player, block, isInstaBreak, cc, data)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Did the arm of the player move before breaking this block?
|
||||
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data))
|
||||
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Is the block really in reach distance?
|
||||
if (!cancelled && reach.isEnabled(player) && reach.check(player, block, data))
|
||||
if (!cancelled && reach.isEnabled(player) && reach.check(player, block, data)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Did the player look at the block at all?
|
||||
if (!cancelled && direction.isEnabled(player) && direction.check(player, block, data))
|
||||
if (!cancelled && direction.isEnabled(player) && direction.check(player, block, data)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Destroying liquid blocks.
|
||||
if (!cancelled && BlockProperties.isLiquid(block.getTypeId()) && !player.hasPermission(Permissions.BLOCKBREAK_BREAK_LIQUID) && !NCPExemptionManager.isExempted(player, CheckType.BLOCKBREAK_BREAK)){
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// At least one check failed and demanded to cancel the event.
|
||||
if (cancelled){
|
||||
// On cancel...
|
||||
if (cancelled) {
|
||||
event.setCancelled(cancelled);
|
||||
// Reset damage position:
|
||||
// TODO: Review this (!), check if set at all !?
|
||||
data.clickedX = block.getX();
|
||||
data.clickedY = block.getY();
|
||||
data.clickedZ = block.getZ();
|
||||
@ -133,11 +142,12 @@ public class BlockBreakListener extends CheckListener {
|
||||
// data.clickedX = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
if (isInstaBreak){
|
||||
if (isInstaBreak) {
|
||||
data.wasInstaBreak = now;
|
||||
}
|
||||
else
|
||||
else {
|
||||
data.wasInstaBreak = 0;
|
||||
}
|
||||
|
||||
// Adjust data.
|
||||
data.fastBreakBreakTime = now;
|
||||
@ -214,7 +224,9 @@ public class BlockBreakListener extends CheckListener {
|
||||
} else if (tick < data.clickedTick) {
|
||||
// Update.
|
||||
} else if (data.fastBreakBreakTime < data.fastBreakfirstDamage && data.clickedX == block.getX() && data.clickedZ == block.getZ() && data.clickedY == block.getY()){
|
||||
if (tick - data.clickedTick <= 1 ) return;
|
||||
if (tick - data.clickedTick <= 1 ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// (Always set, the interact event only fires once: the first time.)
|
||||
// Only record first damage:
|
||||
|
@ -131,7 +131,7 @@ public class FightData extends ACheckData {
|
||||
// Shared
|
||||
public String lastWorld = "";
|
||||
public int lastAttackTick = 0;
|
||||
public double lastAttackedX = Integer.MAX_VALUE;
|
||||
public double lastAttackedX = Double.MAX_VALUE;
|
||||
public double lastAttackedY;
|
||||
public double lastAttackedZ;
|
||||
|
||||
@ -197,4 +197,12 @@ public class FightData extends ACheckData {
|
||||
// Start with full fast-heal buffer.
|
||||
fastHealBuffer = cc.fastHealBuffer;
|
||||
}
|
||||
|
||||
public void onWorldChange() {
|
||||
angleHits.clear();
|
||||
lastAttackedX = Double.MAX_VALUE;
|
||||
lastAttackTick = 0;
|
||||
lastWorld = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
||||
final long msAge; // Milliseconds the ticks actually took.
|
||||
final double normalizedMove; // Blocks per second.
|
||||
// TODO: relative distance (player - target)!
|
||||
if (data.lastAttackedX == Integer.MAX_VALUE || tick < data.lastAttackTick || worldChanged || tick - data.lastAttackTick > 20){
|
||||
if (data.lastAttackedX == Double.MAX_VALUE || tick < data.lastAttackTick || worldChanged || tick - data.lastAttackTick > 20){
|
||||
// TODO: 20 ?
|
||||
tickAge = 0;
|
||||
targetMove = 0.0;
|
||||
@ -460,8 +460,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event){
|
||||
final FightData data = FightData.getData(event.getPlayer());
|
||||
data.angleHits.clear();
|
||||
FightData.getData(event.getPlayer()).onWorldChange();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
|
||||
|
@ -1325,7 +1325,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
||||
loc = vLoc; //
|
||||
if (data.vehicleConsistency != MoveConsistency.INCONSISTENT) {
|
||||
final Location oldLoc = new Location(pLoc.getWorld(), data.toX, data.toY, data.toZ);
|
||||
if (MoveConsistency.getConsistency(oldLoc, null, pLoc) != MoveConsistency.INCONSISTENT) {
|
||||
if (data.toX != Double.MAX_VALUE && MoveConsistency.getConsistency(oldLoc, null, pLoc) != MoveConsistency.INCONSISTENT) {
|
||||
loc = oldLoc;
|
||||
}
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ public class SurvivalFly extends Check {
|
||||
}
|
||||
|
||||
// Invalidation of vertical velocity.
|
||||
if (data.verticalVelocityUsed > cc.velocityGraceTicks && yDistance <= 0 && data.sfLastYDist > 0) {
|
||||
if (data.verticalVelocityUsed > cc.velocityGraceTicks && yDistance <= 0 && data.sfLastYDist > 0 && data.sfLastYDist != Double.MAX_VALUE) {
|
||||
// data.verticalFreedom = 0; // TODO: <- why?
|
||||
data.verticalVelocityCounter = 0;
|
||||
data.verticalVelocity = 0;
|
||||
@ -641,7 +641,7 @@ public class SurvivalFly extends Check {
|
||||
if (cc.survivalFlyAccountingV) {
|
||||
// Currently only for "air" phases.
|
||||
// Vertical.
|
||||
if (yDirChange && data.sfLastYDist > 0) {
|
||||
if (yDirChange && data.sfLastYDist > 0) { // (Double.MAX_VALUE is checked above.)
|
||||
// Change to descending phase.
|
||||
data.vDistAcc.clear();
|
||||
// Allow adding 0.
|
||||
@ -723,6 +723,7 @@ public class SurvivalFly extends Check {
|
||||
|
||||
/**
|
||||
* Check on change of y direction.
|
||||
* <br>Note: data.sfLastYDist must not be Double.MAX_VALUE when calling this.
|
||||
* @param yDistance
|
||||
* @param vDistanceAboveLimit
|
||||
* @return vDistanceAboveLimit
|
||||
@ -741,7 +742,9 @@ public class SurvivalFly extends Check {
|
||||
vDistanceAboveLimit = Math.max(vDistanceAboveLimit, Math.abs(yDistance));
|
||||
tags.add("ychincfly");
|
||||
}
|
||||
else tags.add("ychincair");
|
||||
else {
|
||||
tags.add("ychincair");
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
@ -873,7 +876,7 @@ public class SurvivalFly extends Check {
|
||||
allowHop = false; // Magic!
|
||||
|
||||
// 2x horizontal speed increase detection.
|
||||
if (hDistance - data.sfLastHDist >= walkSpeed * 0.5 && data.bunnyhopDelay == bunnyHopMax - 1) {
|
||||
if (data.sfLastHDist != Double.MAX_VALUE && hDistance - data.sfLastHDist >= walkSpeed * 0.5 && data.bunnyhopDelay == bunnyHopMax - 1) {
|
||||
if (data.sfLastYDist == 0.0 && (data.fromWasReset || data.toWasReset) && yDistance >= 0.4) {
|
||||
// TODO: Confine to last was hop (according to so far input on this topic).
|
||||
tags.add(DOUBLE_BUNNY);
|
||||
@ -964,7 +967,7 @@ public class SurvivalFly extends Check {
|
||||
// Check workarounds.
|
||||
if (yDistance <= 0.5) {
|
||||
// TODO: mediumLiftOff: refine conditions (general) , to should be near water level.
|
||||
if (data.mediumLiftOff == MediumLiftOff.GROUND && !BlockProperties.isLiquid(from.getTypeIdAbove()) || !to.isInLiquid() || (toOnGround || data.sfLastYDist - yDistance >= 0.010 || to.isAboveStairs())) {
|
||||
if (data.mediumLiftOff == MediumLiftOff.GROUND && !BlockProperties.isLiquid(from.getTypeIdAbove()) || !to.isInLiquid() || (toOnGround || data.sfLastYDist != Double.MAX_VALUE && data.sfLastYDist - yDistance >= 0.010 || to.isAboveStairs())) {
|
||||
vAllowedDistance = walkSpeed * modSwim + 0.5;
|
||||
vDistanceAboveLimit = yDistance - vAllowedDistance;
|
||||
}
|
||||
@ -1088,7 +1091,7 @@ public class SurvivalFly extends Check {
|
||||
|
||||
// Half block step up.
|
||||
if (yDistance <= 0.5 && hDistance < 0.5 && setBackYDistance <= 1.3 + 0.2 * data.jumpAmplifier && to.isOnGround()) {
|
||||
if (data.sfLastYDist < 0 || from.isOnGround(0.5 - Math.abs(yDistance))) {
|
||||
if (data.sfLastYDist < 0.0 || from.isOnGround(0.5 - Math.abs(yDistance))) {
|
||||
return applyLostGround(player, from, true, data, "step");
|
||||
}
|
||||
// else data.stats.addStats(data.stats.getId("sfLostGround_" + "step", true), 0);
|
||||
@ -1100,9 +1103,9 @@ public class SurvivalFly extends Check {
|
||||
// TODO: Check use of jump-amplifier.
|
||||
// TODO: Might check fall distance.
|
||||
// && data.sfJumpPhase > 3 <- Seems to be a problem with cake on a block + jump over both mini edges (...).
|
||||
if (data.fromX != Double.MAX_VALUE && yDistance > 0 && data.sfLastYDist < 0 && !to.isOnGround()) {
|
||||
if (data.fromX != Double.MAX_VALUE && yDistance > 0 && data.sfLastYDist < 0.0 && !to.isOnGround()) {
|
||||
// TODO: Check if last-y-dist or sprinting should be considered.
|
||||
if (setBackYDistance > 0D && setBackYDistance <= 1.5D + 0.2 * data.jumpAmplifier || setBackYDistance < 0 && Math.abs(setBackYDistance) < 3.0) {
|
||||
if (setBackYDistance > 0.0 && setBackYDistance <= 1.5D + 0.2 * data.jumpAmplifier || setBackYDistance < 0.0 && Math.abs(setBackYDistance) < 3.0) {
|
||||
// Interpolate from last to-coordinates to the from
|
||||
// coordinates (with some safe-guard).
|
||||
final double dX = from.getX() - data.fromX;
|
||||
@ -1155,7 +1158,7 @@ public class SurvivalFly extends Check {
|
||||
// TODO: <= 7 might work with speed II, not sure with above.
|
||||
// TODO: account for speed/sprint
|
||||
// TODO: account for half steps !?
|
||||
if (from.isOnGround(0.6, 0.4, 0, 0L) ) {
|
||||
if (from.isOnGround(0.6, 0.4, 0.0, 0L) ) {
|
||||
// TODO: further narrow down bounds ?
|
||||
// Temporary "fix".
|
||||
return applyLostGround(player, from, true, data, "pyramid");
|
||||
@ -1164,7 +1167,7 @@ public class SurvivalFly extends Check {
|
||||
}
|
||||
|
||||
// Check for jumping up strange blocks like flower pots on top of other blocks.
|
||||
if (yDistance == 0 && data.sfLastYDist > 0 && data.sfLastYDist < 0.25 && data.sfJumpPhase <= 6 + data.jumpAmplifier * 3 && setBackYDistance > 1.0 && setBackYDistance < 1.5 + 0.2 * data.jumpAmplifier && !to.isOnGround()) {
|
||||
if (yDistance == 0.0 && data.sfLastYDist > 0.0 && data.sfLastYDist < 0.25 && data.sfJumpPhase <= 6 + data.jumpAmplifier * 3.0 && setBackYDistance > 1.0 && setBackYDistance < 1.5 + 0.2 * data.jumpAmplifier && !to.isOnGround()) {
|
||||
// TODO: confine by block types ?
|
||||
if (from.isOnGround(0.25, 0.4, 0, 0L) ) {
|
||||
// Temporary "fix".
|
||||
@ -1174,7 +1177,7 @@ public class SurvivalFly extends Check {
|
||||
}
|
||||
}
|
||||
// Lost ground while falling onto/over edges of blocks.
|
||||
if (yDistance < 0 && hDistance <= 0.5 && data.sfLastYDist < 0 && yDistance > data.sfLastYDist && !to.isOnGround()) {
|
||||
if (yDistance < 0 && hDistance <= 0.5 && data.sfLastYDist < 0.0 && yDistance > data.sfLastYDist && !to.isOnGround()) {
|
||||
// TODO: Should this be an extra lost-ground(to) check, setting toOnGround [for no-fall no difference]?
|
||||
// TODO: yDistance <= 0 might be better.
|
||||
// Also clear accounting data.
|
||||
|
@ -407,7 +407,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.MOVING_TEMPKICKILLEGAL, true);
|
||||
set(ConfPaths.MOVING_LOADCHUNKS_JOIN, true);
|
||||
set(ConfPaths.MOVING_SPRINTINGGRACE, 2.0);
|
||||
set(ConfPaths.MOVING_ASSUMESPRINT, false);
|
||||
set(ConfPaths.MOVING_ASSUMESPRINT, true);
|
||||
set(ConfPaths.MOVING_SPEEDGRACE, 4.0);
|
||||
|
||||
// TODO: An extra file might suit these.
|
||||
|
Loading…
Reference in New Issue
Block a user