Search in sources :

Example 1 with ModelFlying

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

the class MovingListener method prepareCreativeFlyCheck.

private void prepareCreativeFlyCheck(final Player player, final Location from, final Location to, final PlayerMoveInfo moveInfo, final PlayerMoveData thisMove, final int multiMoveCount, final int tick, final MovingData data, final MovingConfig cc) {
    data.adjustFlySpeed(player.getFlySpeed(), tick, cc.speedGrace);
    data.adjustWalkSpeed(player.getWalkSpeed(), tick, cc.speedGrace);
    // TODO: Adjust height of PlayerLocation more efficiently / fetch model early.
    final ModelFlying model = cc.getModelFlying(player, moveInfo.from, data, cc);
    if (MovingConfig.ID_JETPACK_ELYTRA.equals(model.getId())) {
        final MCAccess mcAccess = this.mcAccess.getHandle();
        MovingUtil.setElytraProperties(player, moveInfo.from, from, cc.yOnGround, mcAccess);
        MovingUtil.setElytraProperties(player, moveInfo.to, to, cc.yOnGround, mcAccess);
        thisMove.set(moveInfo.from, moveInfo.to);
        if (multiMoveCount > 0) {
            thisMove.multiMoveCount = multiMoveCount;
        }
    }
    thisMove.modelFlying = model;
}
Also used : MCAccess(fr.neatmonster.nocheatplus.compat.MCAccess) ModelFlying(fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying)

Example 2 with ModelFlying

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

the class MovingConfig method getModelFlying.

public ModelFlying getModelFlying(final Player player, final PlayerLocation fromLocation, final MovingData data, final MovingConfig cc) {
    final GameMode gameMode = player.getGameMode();
    final ModelFlying modelGameMode = flyingModelGameMode.get(gameMode);
    switch(gameMode) {
        case SURVIVAL:
        case ADVENTURE:
        case CREATIVE:
            // Specific checks.
            break;
        default:
            // Default by game mode (spectator, yet unknown).
            return modelGameMode;
    }
    final boolean isGlidingWithElytra = Bridge1_9.isGlidingWithElytra(player) && MovingUtil.isGlidingWithElytraValid(player, fromLocation, data, cc);
    // Actual flying (ignoreAllowFlight is a legacy option for rocket boots like flying).
    if (player.isFlying() || !isGlidingWithElytra && !ignoreAllowFlight && player.getAllowFlight()) {
        return modelGameMode;
    }
    // Elytra.
    if (isGlidingWithElytra) {
        // Defensive: don't demand isGliding.
        return flyingModelElytra;
    }
    // Levitation.
    if (gameMode != GameMode.CREATIVE && !Double.isInfinite(Bridge1_9.getLevitationAmplifier(player)) && !fromLocation.isInLiquid()) {
        return flyingModelLevitation;
    }
    // Default by game mode.
    return modelGameMode;
}
Also used : GameMode(org.bukkit.GameMode) ModelFlying(fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying)

Example 3 with ModelFlying

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

the class CreativeFly method check.

/**
 * @param player
 * @param from
 * @param to
 * @param data
 * @param cc
 * @param time Milliseconds.
 * @return
 */
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc, final IPlayerData pData, final long time, final int tick, final boolean useBlockChangeTracker) {
    // Reset tags, just in case.
    tags.clear();
    final boolean debug = pData.isDebugActive(type);
    // Some edge data for this move.
    final GameMode gameMode = player.getGameMode();
    final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
    // if (!data.thisMove.from.extraPropertiesValid) {
    // // TODO: Confine by model config flag or just always do [if the latter: do it in the listener]?
    // data.thisMove.setExtraProperties(from, to);
    // }
    final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
    final ModelFlying model = thisMove.modelFlying;
    // Proactive reset of elytraBoost (MC 1.11.2).
    if (data.fireworksBoostDuration > 0) {
        if (!lastMove.valid || lastMove.flyCheck != CheckType.MOVING_CREATIVEFLY || lastMove.modelFlying != model || data.fireworksBoostTickExpire < tick) {
            data.fireworksBoostDuration = 0;
        } else {
            data.fireworksBoostDuration--;
        }
    }
    // Calculate some distances.
    final double yDistance = thisMove.yDistance;
    final double hDistance = thisMove.hDistance;
    final boolean flying = gameMode == BridgeMisc.GAME_MODE_SPECTATOR || player.isFlying();
    final boolean sprinting = time <= data.timeSprinting + cc.sprintingGrace;
    // Lost ground, if set so.
    if (model.getGround()) {
        MovingUtil.prepareFullCheck(from, to, thisMove, Math.max(cc.yOnGround, cc.noFallyOnGround));
        if (!thisMove.from.onGroundOrResetCond) {
            if (from.isSamePos(to)) {
                if (// Copy and paste from sf.
                lastMove.toIsValid && lastMove.hDistance > 0.0 && lastMove.yDistance < -0.3 && LostGround.lostGroundStill(player, from, to, hDistance, yDistance, sprinting, lastMove, data, cc, tags)) {
                // Nothing to do.
                }
            } else if (LostGround.lostGround(player, from, to, hDistance, yDistance, sprinting, lastMove, data, cc, useBlockChangeTracker ? blockChangeTracker : null, tags)) {
            // Nothing to do.
            }
        }
    }
    // Horizontal distance check.
    double[] resH = hDist(player, from, to, hDistance, yDistance, sprinting, flying, lastMove, time, model, data, cc);
    double limitH = resH[0];
    double resultH = resH[1];
    // Check velocity.
    if (resultH > 0) {
        double hFreedom = data.getHorizontalFreedom();
        if (hFreedom < resultH) {
            // Use queued velocity if possible.
            hFreedom += data.useHorizontalVelocity(resultH - hFreedom);
        }
        if (hFreedom > 0.0) {
            resultH = Math.max(0.0, resultH - hFreedom);
            if (resultH <= 0.0) {
                limitH = hDistance;
            }
            tags.add("hvel");
        }
    } else {
        // TODO: test/check !
        data.clearActiveHorVel();
    }
    // Normalize to % of a block.
    resultH *= 100.0;
    if (resultH > 0.0) {
        tags.add("hdist");
    }
    // Vertical move.
    // Limit.
    double limitV = 0.0;
    // Violation (normalized to 100 * 1 block, applies if > 0.0).
    double resultV = 0.0;
    // Distinguish checking method by y-direction of the move.
    if (yDistance > 0.0) {
        // Ascend.
        double[] res = vDistAscend(from, to, yDistance, flying, thisMove, lastMove, model, data, cc);
        resultV = Math.max(resultV, res[1]);
        limitV = res[0];
    } else if (yDistance < 0.0) {
        // Descend.
        double[] res = vDistDescend(from, to, yDistance, flying, lastMove, model, data, cc);
        resultV = Math.max(resultV, res[1]);
        limitV = res[0];
    } else {
        // Keep altitude.
        double[] res = vDistZero(from, to, yDistance, flying, lastMove, model, data, cc);
        resultV = Math.max(resultV, res[1]);
        limitV = res[0];
    }
    // Velocity.
    if (resultV > 0.0 && data.getOrUseVerticalVelocity(yDistance) != null) {
        resultV = 0.0;
        tags.add("vvel");
    }
    // Add tag for maximum height check (silent set back).
    final double maximumHeight = model.getMaxHeight() + player.getWorld().getMaxHeight();
    if (to.getY() > maximumHeight) {
        // TODO: Allow use velocity there (would need a flag to signal the actual check below)?
        tags.add("maxheight");
    }
    // Normalize to % of a block.
    resultV *= 100.0;
    if (resultV > 0.0) {
        tags.add("vdist");
    }
    final double result = Math.max(0.0, resultH) + Math.max(0.0, resultV);
    if (debug) {
        outpuDebugMove(player, hDistance, limitH, yDistance, limitV, model, tags, data);
    }
    // Violation handling.
    // Might get altered below.
    Location setBack = null;
    if (result > 0.0) {
        // Increment violation level.
        data.creativeFlyVL += result;
        // 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.creativeFlyVL, result, cc.creativeFlyActions);
        if (vd.needsParameters()) {
            vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
            vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
            vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", TrigUtil.distance(from, to)));
            if (!tags.isEmpty()) {
                vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
            }
        }
        if (executeActions(vd).willCancel()) {
            // Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()"
            // to allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
            // (OK)
            setBack = data.getSetBack(to);
        }
    } else {
        // Maximum height check (silent set back).
        if (to.getY() > maximumHeight) {
            // (OK)
            setBack = data.getSetBack(to);
            if (debug) {
                debug(player, "Maximum height exceeded, silent set-back.");
            }
        }
        if (setBack == null) {
            // Slowly reduce the violation level with each event.
            data.creativeFlyVL *= 0.97;
        }
    }
    // Return setBack, if set.
    if (setBack != null) {
        // Check for max height of the set back.
        if (setBack.getY() > maximumHeight) {
            // Correct the y position.
            setBack.setY(getCorrectedHeight(maximumHeight, setBack.getWorld()));
            if (debug) {
                debug(player, "Maximum height exceeded by set back, correct to: " + setBack.getY());
            }
        }
        data.sfJumpPhase = 0;
        return setBack;
    } else {
        // Adjust the set back and other last distances.
        data.setSetBack(to);
        // Adjust jump phase.
        if (!thisMove.from.onGroundOrResetCond && !thisMove.to.onGroundOrResetCond) {
            data.sfJumpPhase++;
        } else if (thisMove.touchedGround && !thisMove.to.onGroundOrResetCond) {
            data.sfJumpPhase = 1;
        } else {
            data.sfJumpPhase = 0;
        }
        return null;
    }
}
Also used : GameMode(org.bukkit.GameMode) PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) ModelFlying(fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location)

Aggregations

ModelFlying (fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying)3 GameMode (org.bukkit.GameMode)2 ViolationData (fr.neatmonster.nocheatplus.checks.ViolationData)1 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)1 MCAccess (fr.neatmonster.nocheatplus.compat.MCAccess)1 PlayerLocation (fr.neatmonster.nocheatplus.utilities.location.PlayerLocation)1 Location (org.bukkit.Location)1