Search in sources :

Example 6 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class MovingListener method onPlayerBedLeave.

/**
 * We listen to this event to prevent player from flying by sending bed leaving packets.
 *
 * @param event
 *            the event
 */
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerBedLeave(final PlayerBedLeaveEvent event) {
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    if (pData.isCheckActive(bedLeave.getType(), player) && bedLeave.checkBed(player, pData)) {
        final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
        // Check if the player has to be reset.
        // To "cancel" the event, we teleport the player.
        final Location loc = player.getLocation(useLoc);
        final MovingData data = pData.getGenericInstance(MovingData.class);
        Location target = null;
        final PlayerMoveInfo moveInfo = aux.usePlayerMoveInfo();
        moveInfo.set(player, loc, null, cc.yOnGround);
        final boolean sfCheck = MovingUtil.shouldCheckSurvivalFly(player, moveInfo.from, data, cc, pData);
        aux.returnPlayerMoveInfo(moveInfo);
        if (sfCheck) {
            target = MovingUtil.getApplicableSetBackLocation(player, loc.getYaw(), loc.getPitch(), moveInfo.from, data, cc);
        }
        if (target == null) {
            // TODO: Add something to guess the best set back location (possibly data.guessSetBack(Location)).
            target = LocUtil.clone(loc);
        }
        if (sfCheck && cc.sfSetBackPolicyFallDamage && noFall.isEnabled(player, pData)) {
            // Check if to deal damage.
            double y = loc.getY();
            if (data.hasSetBack()) {
                y = Math.min(y, data.getSetBackY());
            }
            noFall.checkDamage(player, y, data, pData);
        }
        // Cleanup
        useLoc.setWorld(null);
        // Teleport.
        // Should be enough. | new Location(target.getWorld(), target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch());
        data.prepareSetBack(target);
        // TODO: schedule / other measures ?
        player.teleport(target, BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION);
    } else {
        // Reset bed ...
        pData.getGenericInstance(CombinedData.class).wasInBed = false;
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 7 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class MovingListener method checkUndoCancelledSetBack.

/**
 * Called for cancelled events only, before EventPriority.MONITOR.
 *
 * @param event
 */
private void checkUndoCancelledSetBack(final PlayerTeleportEvent event) {
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    // Revert cancel on set back (only precise match).
    if (data.hasTeleported()) {
        // Teleport by NCP.
        // TODO: What if not scheduled.
        undoCancelledSetBack(player, event, data, pData);
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 8 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class MovingListener method onPlayerVelocity.

/**
 * Player got a velocity packet. The server can't keep track of actual velocity values (by design), so we have to
 * try and do that ourselves. Very rough estimates.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerVelocity(final PlayerVelocityEvent event) {
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    // Ignore players who are in vehicles.
    if (player.isInsideVehicle()) {
        data.removeAllVelocity();
        return;
    }
    // Process velocity.
    final Vector velocity = event.getVelocity();
    final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
    data.addVelocity(player, cc, velocity.getX(), velocity.getY(), velocity.getZ());
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 9 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class VehicleChecks method onPlayerVehicleEnter.

/**
 * Assume entering a vehicle, event or join with being inside a vehicle. Set
 * back and past move overriding are done here, performing the necessary
 * consistency checking. Because teleporting players with their vehicle
 * means exit + teleport + re-enter, vehicle data should not be reset on
 * player teleportation.
 *
 * @param player
 * @param vehicle
 * @return True, if an event is to be cancelled.
 */
public boolean onPlayerVehicleEnter(final Player player, final Entity vehicle) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final boolean debug = pData.isDebugActive(checkType);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    if (!data.isVehicleSetBack && MovingUtil.hasScheduledPlayerSetBack(player.getUniqueId(), data)) {
        if (debug) {
            debug(player, "Vehicle enter: prevent, due to a scheduled set back.");
        }
        return true;
    }
    if (debug) {
        debug(player, "Vehicle enter: first vehicle: " + vehicle.getClass().getName());
    }
    // Check for nested vehicles.
    final Entity lastVehicle = passengerUtil.getLastNonPlayerVehicle(vehicle, true);
    if (lastVehicle == null) {
        data.clearVehicleData();
        if (debug) {
            debugNestedVehicleEnter(player);
        }
        return false;
    } else if (!lastVehicle.equals(vehicle)) {
        // TODO: Should in general skip checking these? Set backs don't yet work with these anyway (either... or ...).
        if (debug) {
            debug(player, "Vehicle enter: last of nested vehicles: " + lastVehicle.getClass().getName());
        }
        dataOnVehicleEnter(player, lastVehicle, data, pData);
    } else {
        // Proceed normally.
        dataOnVehicleEnter(player, vehicle, data, pData);
    }
    return false;
}
Also used : Entity(org.bukkit.entity.Entity) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 10 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData 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)

Aggregations

IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)74 Player (org.bukkit.entity.Player)55 EventHandler (org.bukkit.event.EventHandler)40 Location (org.bukkit.Location)22 PlayerLocation (fr.neatmonster.nocheatplus.utilities.location.PlayerLocation)12 Entity (org.bukkit.entity.Entity)8 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)7 NetData (fr.neatmonster.nocheatplus.checks.net.NetData)7 ItemStack (org.bukkit.inventory.ItemStack)7 PlayerMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)6 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)5 NetConfig (fr.neatmonster.nocheatplus.checks.net.NetConfig)5 Material (org.bukkit.Material)5 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)4 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)4 Block (org.bukkit.block.Block)4 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 FlyingQueueHandle (fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle)3 EntityType (org.bukkit.entity.EntityType)3 BlockInteractData (fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractData)2