From 3dea6580e40fc3ad7f9c5a13ae70b755b2c58568 Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 25 Nov 2014 23:53:03 +0100 Subject: [PATCH] Spaces. --- .../nocheatplus/checks/fight/Critical.java | 60 +++--- .../nocheatplus/checks/moving/NoFall.java | 190 +++++++++--------- 2 files changed, 125 insertions(+), 125 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java index 730984fd..71ee50bf 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java @@ -40,58 +40,58 @@ public class Critical extends Check { */ public boolean check(final Player player, final Location loc, final FightData data, final FightConfig cc) { boolean cancel = false; - - final float mcFallDistance = player.getFallDistance(); - final MovingConfig mCc = MovingConfig.getConfig(player); - if (mcFallDistance > 0.0 && cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){ - final MovingData mData = MovingData.getData(player); - - if (MovingListener.shouldCheckSurvivalFly(player, mData, mCc) && CheckType.MOVING_NOFALL.isEnabled(player)){ - // TODO: Set max y in MovingListener, to be independent of sf/nofall! - player.sendMessage("Critical: fd=" + mcFallDistance + "(" + mData.noFallFallDistance +") y=" + loc.getY() + ((mData.hasSetBack() && mData.getSetBackY() < mData.noFallMaxY) ? (" jumped=" + StringUtil.fdec3.format(mData.noFallMaxY - mData.getSetBackY())): "")); - } - } + + final float mcFallDistance = player.getFallDistance(); + final MovingConfig mCc = MovingConfig.getConfig(player); + if (mcFallDistance > 0.0 && cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){ + final MovingData mData = MovingData.getData(player); + + if (MovingListener.shouldCheckSurvivalFly(player, mData, mCc) && CheckType.MOVING_NOFALL.isEnabled(player)){ + // TODO: Set max y in MovingListener, to be independent of sf/nofall! + player.sendMessage("Critical: fd=" + mcFallDistance + "(" + mData.noFallFallDistance +") y=" + loc.getY() + ((mData.hasSetBack() && mData.getSetBackY() < mData.noFallMaxY) ? (" jumped=" + StringUtil.fdec3.format(mData.noFallMaxY - mData.getSetBackY())): "")); + } + } // Check if the hit was a critical hit (positive fall distance, entity in the air, not on ladder, not in liquid // and without blindness effect). - - // TODO: Skip the on-ground check somehow? - // TODO: Implement low jump penalty. + + // TODO: Skip the on-ground check somehow? + // TODO: Implement low jump penalty. if (mcFallDistance > 0f && !player.hasPotionEffect(PotionEffectType.BLINDNESS)){ - // Might be a violation. - final MovingData dataM = MovingData.getData(player); - if (dataM.sfLowJump || player.getFallDistance() < cc.criticalFallDistance && !BlockProperties.isOnGroundOrResetCond(player, loc, mCc.yOnGround)){ - final MovingConfig ccM = MovingConfig.getConfig(player); - if (MovingListener.shouldCheckSurvivalFly(player, dataM, ccM)){ + // Might be a violation. + final MovingData dataM = MovingData.getData(player); + if (dataM.sfLowJump || player.getFallDistance() < cc.criticalFallDistance && !BlockProperties.isOnGroundOrResetCond(player, loc, mCc.yOnGround)){ + final MovingConfig ccM = MovingConfig.getConfig(player); + if (MovingListener.shouldCheckSurvivalFly(player, dataM, ccM)){ final double deltaFallDistance = (cc.criticalFallDistance - player.getFallDistance()) / cc.criticalFallDistance; // TODO: Cleanup: velocity is more like the gravity constant. final double deltaVelocity = (cc.criticalVelocity - Math.abs(player.getVelocity().getY())) / cc.criticalVelocity; double delta = deltaFallDistance > 0D ? deltaFallDistance : 0D + deltaVelocity > 0D ? deltaVelocity : 0D; - + final List tags = new ArrayList(); - + // Player failed the check, but this is influenced by lag so don't do it if there was lag. if (TickTask.getLag(1000, true) < 1.5){ - // TODO: 1.5 is a fantasy value. + // TODO: 1.5 is a fantasy value. // Increment the violation level. data.criticalVL += delta; } else{ - tags.add("lag"); - delta = 0; + tags.add("lag"); + delta = 0; } - + // Execute whatever actions are associated with this check and the violation level and find out if we // should cancel the event. final ViolationData vd = new ViolationData(this, player, data.criticalVL, delta, cc.criticalActions); if (vd.needsParameters()){ - if (dataM.sfLowJump){ - tags.add("sf_lowjump"); - } - vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+")); + if (dataM.sfLowJump){ + tags.add("sf_lowjump"); + } + vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+")); } cancel = executeActions(vd); - } + } } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java index 87f5e2cf..8d722965 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java @@ -18,9 +18,9 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation; * A check to see if people cheat by tricking the server to not deal them fall damage. */ public class NoFall extends Check { - - /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */ - private final Location useLoc = new Location(null, 0, 0, 0); + + /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */ + private final Location useLoc = new Location(null, 0, 0, 0); /** * Instantiates a new no fall check. @@ -28,7 +28,7 @@ public class NoFall extends Check { public NoFall() { super(CheckType.MOVING_NOFALL); } - + /** * Calculate the damage in hearts from the given fall distance. * @param fallDistance @@ -37,7 +37,7 @@ public class NoFall extends Check { protected static final double getDamage(final float fallDistance){ return fallDistance - 3.0; } - + /** * Deal damage if appropriate. To be used for if the player is on ground somehow. * @param mcPlayer @@ -45,10 +45,10 @@ public class NoFall extends Check { * @param y */ private final void handleOnGround(final Player player, final double y, final boolean reallyOnGround, final MovingData data, final MovingConfig cc) { -// final int pD = getDamage(mcPlayer.fallDistance); -// final int nfD = getDamage(data.noFallFallDistance); -// final int yD = getDamage((float) (data.noFallMaxY - y)); -// final int maxD = Math.max(Math.max(pD, nfD), yD); + // final int pD = getDamage(mcPlayer.fallDistance); + // final int nfD = getDamage(data.noFallFallDistance); + // final int yD = getDamage((float) (data.noFallMaxY - y)); + // final int maxD = Math.max(Math.max(pD, nfD), yD); final double maxD = getDamage(Math.max((float) (data.noFallMaxY - y), Math.max(data.noFallFallDistance, player.getFallDistance()))); if (maxD >= 1.0){ // Damage to be dealt. @@ -58,38 +58,38 @@ public class NoFall extends Check { } // TODO: might not be necessary: if (mcPlayer.invulnerableTicks <= 0) [no damage event for resetting] data.noFallSkipAirCheck = true; - dealFallDamage(player, maxD); + dealFallDamage(player, maxD); } else data.clearNoFallData(); } - + private final void adjustFallDistance(final Player player, final double minY, final boolean reallyOnGround, final MovingData data, final MovingConfig cc) { - final float noFallFallDistance = Math.max(data.noFallFallDistance, (float) (data.noFallMaxY - minY)); - if (noFallFallDistance >= 3.0){ - final float fallDistance = player.getFallDistance(); - if (noFallFallDistance - fallDistance >= 0.5f || noFallFallDistance >= 3.5f && noFallFallDistance < 3.5f){ - player.setFallDistance(noFallFallDistance); - } - } + final float noFallFallDistance = Math.max(data.noFallFallDistance, (float) (data.noFallMaxY - minY)); + if (noFallFallDistance >= 3.0){ + final float fallDistance = player.getFallDistance(); + if (noFallFallDistance - fallDistance >= 0.5f || noFallFallDistance >= 3.5f && noFallFallDistance < 3.5f){ + player.setFallDistance(noFallFallDistance); + } + } data.clearNoFallData(); - } + } private void dealFallDamage(final Player player, final double damage) { - // TODO: Byte code compatibility ? - final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage); + // TODO: Byte code compatibility ? + final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()){ - // TODO: account for no damage ticks etc. - player.setLastDamageCause(event); + // TODO: account for no damage ticks etc. + player.setLastDamageCause(event); mcAccess.dealFallDamage(player, BridgeHealth.getDamage(event)); } // TODO: let this be done by the damage event (!). -// data.clearNoFallData(); // -> currently done in the damage eventhandling method. + // data.clearNoFallData(); // -> currently done in the damage eventhandling method. player.setFallDistance(0); - } + } - /** + /** * Checks a player. Expects from and to using cc.yOnGround. * * @param player @@ -100,37 +100,37 @@ public class NoFall extends Check { * the to */ public void check(final Player player, final Location loc, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) { - - final double fromY = from.getY(); - final double toY = to.getY(); - - // TODO: account for player.getLocation.getY (how exactly ?) - final double yDiff = toY - fromY; - - final double oldNFDist = data.noFallFallDistance; - - // Reset-cond is not touched by yOnGround. - // TODO: Distinguish water depth vs. fall distance ? - final boolean fromReset = from.isResetCond(); - final boolean toReset = to.isResetCond(); - - // Adapt yOnGround if necessary (sf uses another setting). - if (yDiff < 0 && cc.yOnGround < cc.noFallyOnGround) { - // In fact this is somewhat heuristic, but it seems to work well. - // Missing on-ground seems to happen with running down pyramids rather. - // TODO: Should be obsolete. - adjustYonGround(from, to , cc.noFallyOnGround); - } - + + final double fromY = from.getY(); + final double toY = to.getY(); + + // TODO: account for player.getLocation.getY (how exactly ?) + final double yDiff = toY - fromY; + + final double oldNFDist = data.noFallFallDistance; + + // Reset-cond is not touched by yOnGround. + // TODO: Distinguish water depth vs. fall distance ? + final boolean fromReset = from.isResetCond(); + final boolean toReset = to.isResetCond(); + + // Adapt yOnGround if necessary (sf uses another setting). + if (yDiff < 0 && cc.yOnGround < cc.noFallyOnGround) { + // In fact this is somewhat heuristic, but it seems to work well. + // Missing on-ground seems to happen with running down pyramids rather. + // TODO: Should be obsolete. + adjustYonGround(from, to , cc.noFallyOnGround); + } + final boolean fromOnGround = from.isOnGround(); final boolean toOnGround = to.isOnGround(); - - + + // TODO: early returns (...) - + final double pY = loc.getY(); final double minY = Math.min(fromY, Math.min(toY, pY)); - + if (fromReset){ // Just reset. data.clearNoFallData(); @@ -147,8 +147,8 @@ public class NoFall extends Check { else if (toOnGround){ // Check if to deal damage. if (yDiff < 0){ - // In this case the player has traveled further: add the difference. - data.noFallFallDistance -= yDiff; + // In this case the player has traveled further: add the difference. + data.noFallFallDistance -= yDiff; } if (cc.noFallDealDamage) handleOnGround(player, minY, true, data, cc); else adjustFallDistance(player, minY, true, data, cc); @@ -156,57 +156,57 @@ public class NoFall extends Check { else{ // Ensure fall distance is correct, or "anyway"? } - + // Set reference y for nofall (always). // TODO: Consider setting this before handleOnGround (at least for resetTo). data.noFallMaxY = Math.max(Math.max(fromY, Math.max(toY, pY)), data.noFallMaxY); - + // TODO: fall distance might be behind (!) // TODO: should be the data.noFallMaxY be counted in ? final float mcFallDistance = player.getFallDistance(); // Note: it has to be fetched here. data.noFallFallDistance = Math.max(mcFallDistance, data.noFallFallDistance); - + // Add y distance. if (!toReset && !toOnGround && yDiff < 0){ data.noFallFallDistance -= yDiff; } else if (cc.noFallAntiCriticals && (toReset || toOnGround || (fromReset || fromOnGround || data.noFallAssumeGround) && yDiff >= 0)){ - final double max = Math.max(data.noFallFallDistance, mcFallDistance); - if (max > 0.0 && max < 0.75){ // (Ensure this does not conflict with deal-damage set to false.) + final double max = Math.max(data.noFallFallDistance, mcFallDistance); + if (max > 0.0 && max < 0.75){ // (Ensure this does not conflict with deal-damage set to false.) if (cc.debug){ - NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " NoFall: Reset fall distance (anticriticals): mc=" + mcFallDistance +" / nf=" + data.noFallFallDistance); + NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " NoFall: Reset fall distance (anticriticals): mc=" + mcFallDistance +" / nf=" + data.noFallFallDistance); } - if (data.noFallFallDistance > 0){ - data.noFallFallDistance = 0; - } - if (mcFallDistance > 0){ - player.setFallDistance(0); - } - } + if (data.noFallFallDistance > 0){ + data.noFallFallDistance = 0; + } + if (mcFallDistance > 0){ + player.setFallDistance(0); + } + } } - + if (cc.debug){ - NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " NoFall: mc=" + mcFallDistance +" / nf=" + data.noFallFallDistance + (oldNFDist < data.noFallFallDistance ? " (+" + (data.noFallFallDistance - oldNFDist) + ")" : "") + " | ymax=" + data.noFallMaxY); + NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " NoFall: mc=" + mcFallDistance +" / nf=" + data.noFallFallDistance + (oldNFDist < data.noFallFallDistance ? " (+" + (data.noFallFallDistance - oldNFDist) + ")" : "") + " | ymax=" + data.noFallMaxY); } - + } - - /** + + /** * Set yOnGround for from and to, if needed, should be obsolete. * @param from * @param to * @param cc */ private void adjustYonGround(final PlayerLocation from, final PlayerLocation to, final double yOnGround) { - if (!from.isOnGround()){ - from.setyOnGround(yOnGround); - } - if (!to.isOnGround()){ - to.setyOnGround(yOnGround); - } - } + if (!from.isOnGround()){ + from.setyOnGround(yOnGround); + } + if (!to.isOnGround()){ + to.setyOnGround(yOnGround); + } + } - /** + /** * Quit or kick: adjust fall distance if necessary. * @param player */ @@ -214,20 +214,20 @@ public class NoFall extends Check { final MovingData data = MovingData.getData(player); final float fallDistance = player.getFallDistance(); if (data.noFallFallDistance - fallDistance > 0.0) { - final double playerY = player.getLocation(useLoc).getY(); - useLoc.setWorld(null); - if (player.getAllowFlight() || player.isFlying() || player.getGameMode() == GameMode.CREATIVE) { - // Forestall potential issues with flying plugins. - player.setFallDistance(0f); - data.noFallFallDistance = 0f; - data.noFallMaxY = playerY; - } else { + final double playerY = player.getLocation(useLoc).getY(); + useLoc.setWorld(null); + if (player.getAllowFlight() || player.isFlying() || player.getGameMode() == GameMode.CREATIVE) { + // Forestall potential issues with flying plugins. + player.setFallDistance(0f); + data.noFallFallDistance = 0f; + data.noFallMaxY = playerY; + } else { // Might use tolerance, might log, might use method (compare: MovingListener.onEntityDamage). // Might consider triggering violations here as well. final float yDiff = (float) (data.noFallMaxY - playerY); final float maxDist = Math.max(yDiff, Math.max(data.noFallFallDistance, fallDistance)); player.setFallDistance(maxDist); - } + } } } @@ -236,10 +236,10 @@ public class NoFall extends Check { * @param player * @param data */ - public void checkDamage(final Player player, final MovingData data, final double y) { - final MovingConfig cc = MovingConfig.getConfig(player); - // Deal damage. - handleOnGround(player, y, false, data, cc); - } - + public void checkDamage(final Player player, final MovingData data, final double y) { + final MovingConfig cc = MovingConfig.getConfig(player); + // Deal damage. + handleOnGround(player, y, false, data, cc); + } + }