Search in sources :

Example 6 with PlayerMoveInfo

use of fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo in project NoCheatPlus by NoCheatPlus.

the class AuxMoving method resetPositionsAndMediumProperties.

/**
 * Convenience method to do both data.resetPositions and
 * data.adjustMediumProperties, wrapping given loc with a PlayerLocation
 * instance.
 *
 * @param player
 * @param loc
 * @param data
 * @param cc
 */
public void resetPositionsAndMediumProperties(final Player player, final Location loc, final MovingData data, final MovingConfig cc) {
    final PlayerMoveInfo moveInfo = usePlayerMoveInfo();
    moveInfo.set(player, loc, null, cc.yOnGround);
    data.resetPlayerPositions(moveInfo.from);
    data.adjustMediumProperties(moveInfo.from);
    returnPlayerMoveInfo(moveInfo);
}
Also used : PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)

Example 7 with PlayerMoveInfo

use of fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo in project NoCheatPlus by NoCheatPlus.

the class AuxMoving method clear.

/**
 * Clear parked MovingInfo instances. Called on reload and data removal and
 * setMCAccess.
 */
public void clear() {
    // (Players)
    for (final PlayerMoveInfo info : parkedPlayerMoveInfo) {
        info.cleanup();
    }
    parkedPlayerMoveInfo.clear();
    // (Vehicles)
    for (final VehicleMoveInfo info : parkedVehicleMoveInfo) {
        info.cleanup();
    }
    parkedVehicleMoveInfo.clear();
}
Also used : PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo) VehicleMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.VehicleMoveInfo)

Example 8 with PlayerMoveInfo

use of fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo in project NoCheatPlus by NoCheatPlus.

the class MovingListener method checkFallDamageEvent.

private void checkFallDamageEvent(final Player player, final EntityDamageEvent event) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    if (player.isInsideVehicle()) {
        // Ignore vehicles (noFallFallDistance will be inaccurate anyway).
        data.clearNoFallData();
        return;
    }
    final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
    final PlayerMoveInfo moveInfo = aux.usePlayerMoveInfo();
    final double yOnGround = Math.max(cc.noFallyOnGround, cc.yOnGround);
    final Location loc = player.getLocation(useLoc);
    moveInfo.set(player, loc, null, yOnGround);
    final PlayerLocation pLoc = moveInfo.from;
    pLoc.collectBlockFlags(yOnGround);
    if (event.isCancelled() || !MovingUtil.shouldCheckSurvivalFly(player, pLoc, data, cc, pData) || !noFall.isEnabled(player, pData)) {
        data.clearNoFallData();
        useLoc.setWorld(null);
        aux.returnPlayerMoveInfo(moveInfo);
        return;
    }
    final boolean debug = pData.isDebugActive(CheckType.MOVING_NOFALL);
    boolean allowReset = true;
    float fallDistance = player.getFallDistance();
    final float yDiff = (float) (data.noFallMaxY - loc.getY());
    // Raw damage.
    final double damage = BridgeHealth.getRawDamage(event);
    // TODO: Account for modifiers.
    if (debug) {
        debug(player, "Damage(FALL/PRE): " + damage + " / mc=" + player.getFallDistance() + " nf=" + data.noFallFallDistance + " yDiff=" + yDiff);
    }
    // NoFall bypass checks.
    if (!data.noFallSkipAirCheck) {
        // Cheat: let Minecraft gather and deal fall damage.
        /*
             * TODO: data.noFallSkipAirCheck is used to skip checking in
             * general, thus move into that block or not?
             */
        // TODO: Could consider skipping accumulated fall distance for NoFall in general as well.
        final float dataDist = Math.max(yDiff, data.noFallFallDistance);
        final double dataDamage = NoFall.getDamage(dataDist);
        if (damage > dataDamage + 0.5 || dataDamage <= 0.0) {
            // TODO: Also relate past y-distance(s) to the fall distance (mc).
            // Hot fix: allow fall damage in lava.
            /*
                 * TODO: Correctly model the half fall distance per in-lava move
                 * and taking fall damage in lava. Should have a block flag for
                 * this.
                 */
            final PlayerMoveData firstPastMove = data.playerMoves.getFirstPastMove();
            if (pLoc.isOnGround() && pLoc.isInLava() && firstPastMove.toIsValid && firstPastMove.yDistance < 0.0) {
                /*
                     * 1. Strictly someone could attempt to accumulate fall
                     * damage by help of fast place and pickup lava. 2. There
                     * are other cases not ending up in lava, but having a
                     * reduced fall distance (then bigger than nofall data).
                     */
                if (debug) {
                    debug(player, "NoFall/Damage: allow fall damage in lava (hotfix).");
                }
            } else if (noFallVL(player, "fakefall", data, cc)) {
                // NOTE: Double violations are possible with the in-air check below.
                // TODO: Differing sub checks, once cancel action...
                player.setFallDistance(dataDist);
                if (dataDamage <= 0.0) {
                    // Cancel the event.
                    event.setCancelled(true);
                    useLoc.setWorld(null);
                    aux.returnPlayerMoveInfo(moveInfo);
                    return;
                } else {
                    // Adjust and continue.
                    if (debug) {
                        debug(player, "NoFall/Damage: override player fall distance and damage (" + fallDistance + " -> " + dataDist + ").");
                    }
                    fallDistance = dataDist;
                    BridgeHealth.setRawDamage(event, dataDamage);
                }
            }
        }
        // Cheat: set ground to true in-air.
        // Be sure not to lose that block.
        // TODO: What is this and why is it right here?
        data.noFallFallDistance += 1.0;
        // TODO: Account for liquid too?
        if (!pLoc.isOnGround(1.0, 0.3, 0.1) && !pLoc.isResetCond() && !pLoc.isAboveLadder() && !pLoc.isAboveStairs()) {
            // Likely: force damage in mid-air by setting on-ground to true.
            if (noFallVL(player, "fakeground", data, cc) && data.hasSetBack()) {
                // Cancel the event and restore fall distance.
                // NoFall data will not be reset
                allowReset = false;
            }
        } else {
            // Legitimate damage: clear accounting data.
            data.vDistAcc.clear();
        // TODO: Why only reset in case of !data.noFallSkipAirCheck?
        // TODO: Also reset other properties.
        // TODO: Also reset in other cases (moved too quickly)?
        }
    }
    aux.returnPlayerMoveInfo(moveInfo);
    // Fall-back check (skip with jump amplifier).
    final double maxD = data.jumpAmplifier > 0.0 ? NoFall.getDamage((float) NoFall.getApplicableFallHeight(player, loc.getY(), data)) : NoFall.getDamage(Math.max(yDiff, Math.max(data.noFallFallDistance, fallDistance))) + (allowReset ? 0.0 : Magic.FALL_DAMAGE_DIST);
    if (maxD > damage) {
        // TODO: respect dealDamage ?
        BridgeHealth.setRawDamage(event, maxD);
        if (debug) {
            debug(player, "Adjust fall damage to: " + maxD);
        }
    }
    if (allowReset) {
        // Normal fall damage, reset data.
        data.clearNoFallData();
        if (debug) {
            debug(player, "Reset NoFall data on fall damage.");
        }
    } else {
        // (Do not cancel the event, otherwise: "moved too quickly exploit".)
        if (cc.noFallViolationReset) {
            data.clearNoFallData();
        }
        // Add player to hover checks.
        if (cc.sfHoverCheck && data.sfHoverTicks < 0) {
            data.sfHoverTicks = 0;
            hoverTicks.add(player.getName());
        }
    }
    // Entity fall-distance should be reset elsewhere.
    // Cleanup.
    useLoc.setWorld(null);
}
Also used : PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location)

Example 9 with PlayerMoveInfo

use of fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo in project NoCheatPlus by NoCheatPlus.

the class MovingListener method handleEntityToggleGlideEvent.

/**
 * @param entity
 * @param isGliding
 * @return True, if the event is to be cancelled.
 */
private boolean handleEntityToggleGlideEvent(final Entity entity, final boolean isGliding) {
    // Ignore non players.
    if (!(entity instanceof Player)) {
        return false;
    }
    final Player player = (Player) entity;
    if (isGliding && !Bridge1_9.isGlidingWithElytra(player)) {
        // Includes check for elytra item.
        final PlayerMoveInfo info = aux.usePlayerMoveInfo();
        // Only restrict very near ground.
        info.set(player, player.getLocation(info.useLoc), null, 0.001);
        final IPlayerData pData = DataManager.getPlayerData(player);
        final MovingData data = pData.getGenericInstance(MovingData.class);
        final boolean res = !MovingUtil.canLiftOffWithElytra(player, info.from, data);
        info.cleanup();
        aux.returnPlayerMoveInfo(info);
        if (res && pData.isDebugActive(checkType)) {
            debug(player, "Prevent toggle glide on.");
        }
        return res;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)

Example 10 with PlayerMoveInfo

use of fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo in project NoCheatPlus by NoCheatPlus.

the class MovingListener method checkOnTickHover.

/**
 * Check for hovering.<br>
 * NOTE: Makes use of useLoc, without resetting it.
 */
private void checkOnTickHover() {
    // Pessimistic.
    final List<String> rem = new ArrayList<String>(hoverTicks.size());
    final PlayerMoveInfo info = aux.usePlayerMoveInfo();
    for (final String playerName : hoverTicks) {
        // TODO: put players into the set (+- one tick would not matter ?)
        // TODO: might add an online flag to data !
        final Player player = DataManager.getPlayerExact(playerName);
        if (player == null || !player.isOnline()) {
            rem.add(playerName);
            continue;
        }
        final IPlayerData pData = DataManager.getPlayerData(player);
        final MovingData data = pData.getGenericInstance(MovingData.class);
        if (player.isDead() || player.isSleeping() || player.isInsideVehicle()) {
            data.sfHoverTicks = -1;
        // (Removed below.)
        }
        if (data.sfHoverTicks < 0) {
            data.sfHoverLoginTicks = 0;
            rem.add(playerName);
            continue;
        } else if (data.sfHoverLoginTicks > 0) {
            // Additional "grace period".
            data.sfHoverLoginTicks--;
            continue;
        }
        final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
        // Check if enabled at all.
        if (!cc.sfHoverCheck) {
            rem.add(playerName);
            data.sfHoverTicks = -1;
            continue;
        }
        // Increase ticks here.
        data.sfHoverTicks += hoverTicksStep;
        if (data.sfHoverTicks < cc.sfHoverTicks) {
            // Don't do the heavier checking here, let moving checks reset these.
            continue;
        }
        if (checkHover(player, data, cc, pData, info)) {
            rem.add(playerName);
        }
    }
    hoverTicks.removeAll(rem);
    aux.returnPlayerMoveInfo(info);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)

Aggregations

PlayerMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)12 Location (org.bukkit.Location)7 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)6 PlayerLocation (fr.neatmonster.nocheatplus.utilities.location.PlayerLocation)6 Player (org.bukkit.entity.Player)6 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)3 EventHandler (org.bukkit.event.EventHandler)3 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)2 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)2 ArrayList (java.util.ArrayList)2 ViolationData (fr.neatmonster.nocheatplus.checks.ViolationData)1 CombinedData (fr.neatmonster.nocheatplus.checks.combined.CombinedData)1 LocationTrace (fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace)1 VehicleMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.VehicleMoveInfo)1