Search in sources :

Example 1 with SimpleEntry

use of fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry 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 SimpleEntry

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

the class MovingData method useVerticalVelocity.

/**
 * Get the first matching velocity entry (invalidate others). Sets
 * verVelUsed if available.
 *
 * @param amount
 * @return
 */
public SimpleEntry useVerticalVelocity(final double amount) {
    final SimpleEntry available = verVel.use(amount, TOL_VVEL);
    if (available != null) {
        playerMoves.getCurrentMove().verVelUsed = available;
        sfDirty = true;
    // TODO: Consider sfNoLowJump = true;
    }
    return available;
}
Also used : SimpleEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry)

Example 3 with SimpleEntry

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

the class MovingListener method onPreparedBounceSupport.

/**
 * Handle a prepare bounce.
 *
 * @param player
 * @param from
 * @param to
 * @param lastMove
 * @param lastMove2
 * @param tick
 * @param data
 * @return True, if bounce has been used, i.e. to do without fall damage.
 */
private boolean onPreparedBounceSupport(final Player player, final Location from, final Location to, final PlayerMoveData thisMove, final PlayerMoveData lastMove, final int tick, final MovingData data) {
    if (to.getY() > from.getY() || to.getY() == from.getY() && data.verticalBounce.value < 0.13) {
        // Apply bounce.
        if (to.getY() == from.getY()) {
            // Fake use velocity here.
            data.prependVerticalVelocity(new SimpleEntry(tick, 0.0, 1));
            data.getOrUseVerticalVelocity(0.0);
            if (lastMove.toIsValid && lastMove.yDistance < 0.0) {
                // Renew the bounce effect.
                data.verticalBounce = new SimpleEntry(tick, data.verticalBounce.value, 1);
            }
        } else {
            data.useVerticalBounce(player);
        }
        return true;
    // TODO: Find % of verticalBounce.value or abs. value for X: yDistance > 0, deviation from effect < X -> set sfNoLowJump
    } else {
        data.verticalBounce = null;
        return false;
    }
}
Also used : SimpleEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry)

Example 4 with SimpleEntry

use of fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry 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 5 with SimpleEntry

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

the class MovingListener method checkPastStateBounceAscend.

private BounceType checkPastStateBounceAscend(final Player player, final PlayerLocation from, final PlayerLocation to, final PlayerMoveData thisMove, final PlayerMoveData lastMove, final int tick, final boolean debug, final MovingData data, final MovingConfig cc) {
    // TODO: More preconditions.
    // TODO: Nail down to more precise side conditions for larger jumps, if possible.
    final UUID worldId = from.getWorld().getUID();
    // Possibly a "lost use of slime".
    // TODO: Might need to cover push up, after ordinary slime bounce.
    // TODO: Work around 0-dist?
    // TODO: Adjust amount based on side conditions (center push or off center, distance to block top).
    double amount = -1.0;
    final BlockChangeEntry entryBelowY_POS = blockChangeTracker.getBlockChangeEntryMatchFlags(data.blockChangeRef, tick, worldId, from.getBlockX(), from.getBlockY() - 1, from.getBlockZ(), Direction.Y_POS, BlockProperties.F_BOUNCE25);
    if (// Center push.
    entryBelowY_POS != null || // Off center push.
    thisMove.yDistance < 1.515 && from.matchBlockChangeMatchResultingFlags(blockChangeTracker, data.blockChangeRef, Direction.Y_POS, Math.min(.415, thisMove.yDistance), BlockProperties.F_BOUNCE25)) {
        if (debug) {
            debug(player, "Direct block push with bounce (" + (entryBelowY_POS == null ? "off_center)." : "center)."));
        }
        amount = Math.min(Math.max(0.505, 1.0 + (double) from.getBlockY() - from.getY() + 1.515), 2.525);
        /*
             * TODO: EXACT MAGIC.
             */
        if (entryBelowY_POS != null) {
            data.blockChangeRef.updateSpan(entryBelowY_POS);
        }
    }
    // Center push while being on the top height of the pushed block already (or 0.5 above (!)).
    if (amount < 0.0 && // TODO: MAGIC EVERYWHERE
    lastMove.toIsValid && lastMove.yDistance >= 0.0 && lastMove.yDistance <= 0.505 && // TODO: Margin?
    from.getY() - (double) from.getBlockY() == lastMove.yDistance) {
        final BlockChangeEntry entry2BelowY_POS = blockChangeTracker.getBlockChangeEntryMatchFlags(data.blockChangeRef, tick, worldId, from.getBlockX(), from.getBlockY() - 2, from.getBlockZ(), Direction.Y_POS, BlockProperties.F_BOUNCE25);
        if (entry2BelowY_POS != null) // TODO: Does off center push exist with this very case?
        {
            if (debug) {
                debug(player, "Foot position block push with bounce (" + (entry2BelowY_POS == null ? "off_center)." : "center)."));
            }
            amount = Math.min(Math.max(0.505, 1.0 + (double) from.getBlockY() - from.getY() + 1.515), // TODO: EXACT MAGIC.
            2.015 - lastMove.yDistance);
            if (entryBelowY_POS != null) {
                data.blockChangeRef.updateSpan(entry2BelowY_POS);
            }
        }
    }
    // Finally add velocity if set.
    if (amount >= 0.0) {
        /*
             * TODO: USE EXISTING velocity with bounce flag set first, then peek
             * / add. (might while peek -> has bounce flag: remove velocity)
             */
        data.removeLeadingQueuedVerticalVelocityByFlag(VelocityFlags.ORIGIN_BLOCK_BOUNCE);
        /*
             * TODO: Concepts for limiting... max amount based on side
             * conditions such as block height+1.5, max coordinate, max
             * amount per use, ALLOW_ZERO flag/boolean and set in
             * constructor, demand max. 1 zero dist during validity. Bind
             * use to initial xz coordinates... Too precise = better with
             * past move tracking, or a sub-class of SimpleEntry with better
             * access signatures including thisMove.
             */
        /*
             * TODO: Also account for current yDistance here? E.g. Add two
             * entries, split based on current yDistance?
             */
        final SimpleEntry vel = new SimpleEntry(tick, amount, FLAGS_VELOCITY_BOUNCE_BLOCK_MOVE_ASCEND, 4);
        data.verticalBounce = vel;
        data.useVerticalBounce(player);
        data.useVerticalVelocity(thisMove.yDistance);
        // }
        if (debug) {
            debug(player, "checkPastStateBounceAscend: set velocity: " + vel);
        }
        // TODO: Exact type to return.
        return BounceType.STATIC_PAST_AND_PUSH;
    }
    // TODO: There is a special case with 1.0 up on pistons pushing horizontal only (!).
    return BounceType.NO_BOUNCE;
}
Also used : SimpleEntry(fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry) BlockChangeEntry(fr.neatmonster.nocheatplus.compat.blocks.changetracker.BlockChangeTracker.BlockChangeEntry) UUID(java.util.UUID)

Aggregations

SimpleEntry (fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry)7 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)3 AccountEntry (fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry)3 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)1 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)1 BlockChangeEntry (fr.neatmonster.nocheatplus.compat.blocks.changetracker.BlockChangeTracker.BlockChangeEntry)1 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)1 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)1 UUID (java.util.UUID)1 Location (org.bukkit.Location)1