Search in sources :

Example 1 with AccountEntry

use of fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry in project NoCheatPlus by NoCheatPlus.

the class MovingData method addVelocity.

/**
 * Add velocity to internal book-keeping.
 *
 * @param player
 * @param data
 * @param cc
 * @param vx
 * @param vy
 * @param vz
 * @param flags
 *            Flags to use with velocity entries.
 */
public void addVelocity(final Player player, final MovingConfig cc, final double vx, final double vy, final double vz, final long flags) {
    final int tick = TickTask.getTick();
    // TODO: Slightly odd to call this each time, might switch to a counter-strategy (move - remove).
    removeInvalidVelocity(tick - cc.velocityActivationTicks);
    if (pData.isDebugActive(CheckType.MOVING)) {
        CheckUtils.debug(player, CheckType.MOVING, "New velocity: " + vx + ", " + vy + ", " + vz);
    }
    // Always add vertical velocity.
    verVel.add(new SimpleEntry(tick, vy, flags, cc.velocityActivationCounter));
    // TODO: Should also switch to adding always.
    if (vx != 0.0 || vz != 0.0) {
        final double newVal = Math.sqrt(vx * vx + vz * vz);
        horVel.add(new AccountEntry(tick, newVal, cc.velocityActivationCounter, getHorVelValCount(newVal)));
    }
    // Set dirty flag here.
    // TODO: Set on using the velocity, due to latency !
    sfDirty = true;
    // TODO: Set on using the velocity, due to latency !
    sfNoLowJump = true;
}
Also used : SimpleEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry) AccountEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry)

Example 2 with AccountEntry

use of fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry in project NoCheatPlus by NoCheatPlus.

the class VehicleChecks method onPlayerVehicleLeave.

/**
 * Call on leaving or just having left a vehicle.
 * @param player
 * @param vehicle May be null in case of "not possible to determine".
 */
private void onPlayerVehicleLeave(final Player player, final Entity vehicle) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    final boolean debug = pData.isDebugActive(checkType);
    data.wasInVehicle = false;
    data.joinOrRespawn = false;
    // if (data.vehicleSetBackTaskId != -1) {
    // // Await set back.
    // // TODO: might still set ordinary set backs ?
    // return;
    // }
    final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
    // TODO: Loc can be inconsistent, determine which to use !
    final Location pLoc = player.getLocation(useLoc1);
    // The location to use as set back.
    Location loc = pLoc;
    // final Entity vehicle = player.getVehicle();
    if (vehicle != null) {
        final Location vLoc = vehicle.getLocation(useLoc2);
        // Workaround for some entities/animals that don't fire VehicleMoveEventS.
        if (!normalVehicles.contains(vehicle.getType()) || cc.noFallVehicleReset) {
            // Might allow one time cheat.
            data.noFallSkipAirCheck = true;
            data.clearNoFallData();
        }
        // Check consistency with vehicle location.
        if (MoveConsistency.getConsistency(vLoc, null, pLoc) == MoveConsistency.INCONSISTENT) {
            // TODO: Consider teleporting the player (...)
            // TODO: What with the case of vehicle moved to another world !?
            // 
            loc = vLoc;
            if (data.vehicleConsistency != MoveConsistency.INCONSISTENT) {
                // TODO: This may need re-setting on player move -> vehicle move.
                final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
                if (lastMove.toIsValid) {
                    final Location oldLoc = new Location(pLoc.getWorld(), lastMove.to.getX(), lastMove.to.getY(), lastMove.to.getZ());
                    if (MoveConsistency.getConsistency(oldLoc, null, pLoc) != MoveConsistency.INCONSISTENT) {
                        loc = oldLoc;
                    }
                }
            }
        }
        if (debug) {
            debug(player, "Vehicle leave: " + vehicle.getType() + "@" + pLoc.distance(vLoc));
        }
    }
    // Adjust loc if in liquid (meant for boats !?).
    if (BlockProperties.isLiquid(loc.getBlock().getType())) {
        loc.setY(Location.locToBlock(loc.getY()) + 1.25);
    }
    if (debug) {
        debug(player, "Vehicle leave: " + pLoc.toString() + (pLoc.equals(loc) ? "" : " / player at: " + pLoc.toString()));
    }
    aux.resetPositionsAndMediumProperties(player, loc, data, cc);
    data.setSetBack(loc);
    // Give some freedom to allow the "exiting move".
    data.removeAllVelocity();
    // TODO: Use-once entries usually are intended to allow one offset, but not jumping/flying on.
    data.addHorizontalVelocity(new AccountEntry(0.9, 1, 1));
    // TODO: Typical margin?
    data.addVerticalVelocity(new SimpleEntry(0.6, 1));
    useLoc1.setWorld(null);
    useLoc2.setWorld(null);
}
Also used : MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) SimpleEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) MovingConfig(fr.neatmonster.nocheatplus.checks.moving.MovingConfig) AccountEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry) Location(org.bukkit.Location) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)

Example 3 with AccountEntry

use of fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry in project NoCheatPlus by NoCheatPlus.

the class MovingListener method workaroundFlyNoFlyTransition.

/**
 * Add velocity, in order to work around issues with turning off flying,
 * triggering SurvivalFly. Asserts last distances are set.
 *
 * @param tick
 * @param data
 */
private void workaroundFlyNoFlyTransition(final Player player, final int tick, final boolean debug, final MovingData data) {
    final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
    final double amount = guessFlyNoFlyVelocity(player, data.playerMoves.getCurrentMove(), lastMove, data);
    // Clear active velocity due to adding actual speed here.
    data.clearActiveHorVel();
    data.addHorizontalVelocity(new AccountEntry(tick, amount, 1, MovingData.getHorVelValCount(amount)));
    data.addVerticalVelocity(new SimpleEntry(lastMove.yDistance, 2));
    data.addVerticalVelocity(new SimpleEntry(0.0, 2));
    data.setFrictionJumpPhase();
    // Reset fall height.
    // TODO: Later (e.g. 1.9) check for the ModelFlying, if fall damage is intended.
    data.clearNoFallData();
    // TODO: Might do without this in case of elytra, needs ensure NoFall doesn't kill the player (...).
    player.setFallDistance(0f);
    if (debug) {
        debug(player, "Fly-nofly transition: Add velocity.");
    }
}
Also used : PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) SimpleEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry) AccountEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry)

Aggregations

AccountEntry (fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry)3 SimpleEntry (fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry)3 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)2 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)1 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)1 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)1 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)1 Location (org.bukkit.Location)1