Search in sources :

Example 6 with MovingData

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

the class PassengerUtil method teleportWithPassengers.

/**
 * Teleport the player with vehicle, might temporarily eject the passengers and set
 * teleported in MovingData.
 *
 * @param vehicle
 *            The vehicle to teleport.
 * @param player
 *            The (original) player in charge, who'd also trigger
 *            violations. Should be originalPassengers[0].
 * @param location
 *            Location to teleport the vehicle to.
 * @param debug
 *            the debug
 * @param originalPassengers
 *            The passengers at the time, that is to be restored. Must not be null.
 * @param CheckPassengers Set to true to compare current with original passengers.
 */
public void teleportWithPassengers(final Entity vehicle, final Player player, final Location location, final boolean debug, final Entity[] originalPassengers, final boolean checkPassengers, final IPlayerData pData) {
    // TODO: Rubber band issue needs synchronizing with packet level and ignore certain incoming ones?
    // TODO: This handling could conflict with WorldGuard region flags.
    // TODO: Account for nested passengers and inconsistencies.
    // TODO: Conception: Restore the passengers at the time of setting the vehicle set back?
    final MovingData data = pData.getGenericInstance(MovingData.class);
    data.isVehicleSetBack = true;
    int otherPlayers = 0;
    boolean playerIsOriginalPassenger = false;
    for (int i = 0; i < originalPassengers.length; i++) {
        if (originalPassengers[i].equals(player)) {
            playerIsOriginalPassenger = true;
            break;
        } else if (originalPassengers[i] instanceof Player) {
            DataManager.getGenericInstance((Player) originalPassengers[i], MovingData.class).isVehicleSetBack = true;
            otherPlayers++;
        }
    }
    // false; // Some time in the future a teleport might work directly.
    boolean redoPassengers = true;
    // }
    if (!playerIsOriginalPassenger) {
        if (debug) {
            CheckUtils.debug(player, CheckType.MOVING_VEHICLE, "Vehicle set back: This player is not an original passenger.");
        }
    // redoPassengers = true;
    }
    boolean vehicleTeleported = false;
    boolean playerTeleported = false;
    int otherPlayersTeleported = 0;
    if (vehicle.isDead() || !vehicle.isValid()) {
        // TODO: Still consider teleporting the player.
        vehicleTeleported = false;
    } else {
        // } // TODO: other players flags reset etc.
        if (redoPassengers) {
            // Teleport the vehicle independently.
            // NOTE: VehicleExit fires, unknown TP fires.
            vehicle.eject();
            // TODO: Confirm eject worked, handle if not.
            vehicleTeleported = vehicle.teleport(LocUtil.clone(location), BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION);
        }
    }
    if (redoPassengers) {
        // Add the player first,  if not an original passenger (special case, idk, replaced by squids perhaps).
        if (!playerIsOriginalPassenger) {
            // (Not sure: always add first, until another case is needed.)
            teleportPlayerPassenger(player, vehicle, location, vehicleTeleported, data, debug);
        }
        // Add all other original passengers in a generic way, distinguish players.
        for (int i = 0; i < originalPassengers.length; i++) {
            final Entity passenger = originalPassengers[i];
            if (passenger.isValid() && !passenger.isDead()) {
                // Cross world cases?
                if (passenger instanceof Player) {
                    if (teleportPlayerPassenger((Player) passenger, vehicle, location, vehicleTeleported, DataManager.getGenericInstance((Player) passenger, MovingData.class), debug)) {
                        if (player.equals(passenger)) {
                            playerTeleported = true;
                        } else {
                            otherPlayersTeleported++;
                        }
                    }
                } else {
                    if (passenger.teleport(location, BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION) && vehicleTeleported && passenger.getLocation(useLoc2).distance(vehicle.getLocation(useLoc)) < 1.5) {
                        if (!handleVehicle.getHandle().addPassenger(passenger, vehicle)) {
                        // TODO: What?
                        }
                    }
                }
            }
        // Log skipped + failed non player entities.
        }
    }
    // Log resolution.
    if (debug) {
        CheckUtils.debug(player, CheckType.MOVING_VEHICLE, "Vehicle set back resolution: " + location + " pt=" + playerTeleported + " vt=" + vehicleTeleported + (otherPlayers > 0 ? (" opt=" + otherPlayersTeleported + "/" + otherPlayers) : ""));
    }
    useLoc.setWorld(null);
    useLoc2.setWorld(null);
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData)

Example 7 with MovingData

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

the class MovingUtil method checkUntrackedLocation.

/**
 * Detect if the given location is an untracked spot. This is spots for
 * which a player is at the location, but the moving data has another
 * "last to" position set for that player. Note that one matching player
 * with "last to" being consistent is enough to let this return null, world spawn is exempted.
 * <hr>
 * Pre-conditions:<br>
 * <li>Context-specific (e.g. activation flags for command, teleport).</li>
 * <li>See MovingUtils.shouldCheckUntrackedLocation.</li>
 *
 * @param loc
 * @return Corrected location, if loc is an "untracked location".
 */
public static Location checkUntrackedLocation(final Location loc) {
    // TODO: More efficient method to get entities at the same position (might use MCAccess).
    final Chunk toChunk = loc.getChunk();
    final Entity[] entities = toChunk.getEntities();
    MovingData untrackedData = null;
    for (int i = 0; i < entities.length; i++) {
        final Entity entity = entities[i];
        if (entity.getType() != EntityType.PLAYER) {
            continue;
        }
        final Location refLoc = entity.getLocation(useLoc);
        // TODO: Exempt other warps -> HASH based exemption (expire by time, keep high count)?
        if (TrigUtil.isSamePos(loc, refLoc) && (entity instanceof Player)) {
            final Player other = (Player) entity;
            final IPlayerData otherPData = DataManager.getPlayerData(other);
            final MovingData otherData = otherPData.getGenericInstance(MovingData.class);
            final PlayerMoveData otherLastMove = otherData.playerMoves.getFirstPastMove();
            if (!otherLastMove.toIsValid) {
                // TODO: Consider counting as tracked?
                continue;
            } else if (TrigUtil.isSamePos(refLoc, otherLastMove.to.getX(), otherLastMove.to.getY(), otherLastMove.to.getZ())) {
                // Tracked.
                return null;
            } else {
                // More leniency: allow moving inside of the same block.
                if (TrigUtil.isSameBlock(loc, otherLastMove.to.getX(), otherLastMove.to.getY(), otherLastMove.to.getZ()) && !BlockProperties.isPassable(refLoc.getWorld(), otherLastMove.to.getX(), otherLastMove.to.getY(), otherLastMove.to.getZ())) {
                    continue;
                }
                untrackedData = otherData;
            }
        }
    }
    // Cleanup.
    useLoc.setWorld(null);
    if (untrackedData == null) {
        return null;
    } else {
        // TODO: Count and log to TRACE_FILE, if multiple locations would match (!).
        final PlayerMoveData lastMove = untrackedData.playerMoves.getFirstPastMove();
        return new Location(loc.getWorld(), lastMove.to.getX(), lastMove.to.getY(), lastMove.to.getZ(), loc.getYaw(), loc.getPitch());
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) IDebugPlayer(fr.neatmonster.nocheatplus.components.debug.IDebugPlayer) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Chunk(org.bukkit.Chunk) CountableLocation(fr.neatmonster.nocheatplus.checks.net.model.CountableLocation) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation) Location(org.bukkit.Location)

Example 8 with MovingData

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

the class VehicleChecks method updateVehicleData.

private void updateVehicleData(final Player player, final MovingData data, final Entity vehicle, final VehicleMoveInfo moveInfo, final List<Entity> passengers) {
    for (final Entity passenger : passengers) {
        if ((passenger instanceof Player) && !player.equals(passenger)) {
            final Player otherPlayer = (Player) passenger;
            final MovingData otherData = DataManager.getGenericInstance(otherPlayer, MovingData.class);
            otherData.resetVehiclePositions(moveInfo.to);
            // TODO: Reset all precisely to what there is or this or what not.
            otherData.vehicleSetBacks.resetAllLazily(data.vehicleSetBacks.getOldestValidEntry());
            otherData.wasInVehicle = true;
            // TODO: VehicleMoves: should adjust fully ?
            otherData.vehicleMoves.invalidate();
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData)

Example 9 with MovingData

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

the class VehicleChecks method onVehicleUpdate.

/**
 * This should always fire, prefer over VehicleMoveEvent, if possible.
 *
 * @param event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVehicleUpdate(final VehicleUpdateEvent event) {
    // TODO: VehicleUpdateEvent. How to track teleporting of the vehicle?
    // TODO: Track just left vehicle/entity positions otherwise (on tick + vehicle update)?
    // TODO: No problem: (?) update 'authorized state' if no player passenger.
    final Vehicle vehicle = event.getVehicle();
    final EntityType vehicleType = vehicle.getType();
    if (!normalVehicles.contains(vehicleType)) {
        // A little extra sweep to check for debug flags.
        normalVehicles.add(vehicleType);
        if (worldDataManager.getWorldData(vehicle.getWorld()).isDebugActive(checkType)) {
            debug(null, "VehicleUpdateEvent fired for: " + vehicleType);
        }
    }
    // TODO: Detect if a VehicleMove event will fire (not strictly possible without nms, depends on visibility of fields, possibly estimate instead?).
    if (vehicle.getVehicle() != null) {
        // Do ignore events for vehicles inside of other vehicles.
        return;
    }
    final Player player = passengerUtil.getFirstPlayerPassenger(vehicle);
    if (player == null || player.isDead()) {
        return;
    }
    if (vehicle.isDead() || !vehicle.isValid()) {
        // TODO: Actually force dismount?
        onPlayerVehicleLeave(player, vehicle);
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    // final MovingConfig cc = MovingConfig.getConfig(player);
    final boolean debug = pData.isDebugActive(checkType);
    if (debug) {
        final Location loc = vehicle.getLocation(useLoc1);
        debug(player, "VehicleUpdateEvent: " + vehicleType + " " + loc);
        useLoc1.setWorld(null);
    }
    onVehicleUpdate(vehicle, vehicleType, player, false, data, pData, debug);
}
Also used : Vehicle(org.bukkit.entity.Vehicle) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Location(org.bukkit.Location) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation) EventHandler(org.bukkit.event.EventHandler)

Example 10 with MovingData

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

the class VehicleSetBackTask method run.

@Override
public void run() {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    data.vehicleSetBackTaskId = -1;
    try {
        NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(PassengerUtil.class).teleportWithPassengers(vehicle, player, location, debug, passengers, true, pData);
    } catch (Throwable t) {
        StaticLog.logSevere(t);
    }
}
Also used : MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PassengerUtil(fr.neatmonster.nocheatplus.utilities.entity.PassengerUtil)

Aggregations

MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)13 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)7 Player (org.bukkit.entity.Player)7 Location (org.bukkit.Location)6 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)5 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)5 Entity (org.bukkit.entity.Entity)4 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)3 EventHandler (org.bukkit.event.EventHandler)3 PlayerMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)2 CountableLocation (fr.neatmonster.nocheatplus.checks.net.model.CountableLocation)2 PlayerLocation (fr.neatmonster.nocheatplus.utilities.location.PlayerLocation)2 EntityType (org.bukkit.entity.EntityType)2 Vehicle (org.bukkit.entity.Vehicle)2 ViolationData (fr.neatmonster.nocheatplus.checks.ViolationData)1 LocationTrace (fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace)1 PlayerSetBackMethod (fr.neatmonster.nocheatplus.checks.moving.player.PlayerSetBackMethod)1 AccountEntry (fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry)1 SimpleEntry (fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry)1 IDebugPlayer (fr.neatmonster.nocheatplus.components.debug.IDebugPlayer)1