Search in sources :

Example 36 with IPlayerData

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

the class VehicleChecks method onVehicleDestroyLowest.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onVehicleDestroyLowest(final VehicleDestroyEvent event) {
    // Prevent destroying ones own vehicle.
    final Entity attacker = event.getAttacker();
    if (attacker instanceof Player && passengerUtil.isPassenger(attacker, event.getVehicle())) {
        final Player player = (Player) attacker;
        final IPlayerData pData = DataManager.getPlayerData(player);
        final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
        if (cc.vehiclePreventDestroyOwn) {
            if (pData.isCheckActive(CheckType.MOVING_SURVIVALFLY, player) || pData.isCheckActive(CheckType.MOVING_CREATIVEFLY, player)) {
            }
            event.setCancelled(true);
            // TODO: This message must be configurable.
            player.sendMessage(ChatColor.DARK_RED + "Destroying your own vehicle is disabled.");
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) MovingConfig(fr.neatmonster.nocheatplus.checks.moving.MovingConfig) EventHandler(org.bukkit.event.EventHandler)

Example 37 with IPlayerData

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

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

Example 39 with IPlayerData

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

the class MovingListener method checkFallDamageEvent.

private void checkFallDamageEvent(final Player player, final EntityDamageEvent event) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    if (player.isInsideVehicle()) {
        // Ignore vehicles (noFallFallDistance will be inaccurate anyway).
        data.clearNoFallData();
        return;
    }
    final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
    final PlayerMoveInfo moveInfo = aux.usePlayerMoveInfo();
    final double yOnGround = Math.max(cc.noFallyOnGround, cc.yOnGround);
    final Location loc = player.getLocation(useLoc);
    moveInfo.set(player, loc, null, yOnGround);
    final PlayerLocation pLoc = moveInfo.from;
    pLoc.collectBlockFlags(yOnGround);
    if (event.isCancelled() || !MovingUtil.shouldCheckSurvivalFly(player, pLoc, data, cc, pData) || !noFall.isEnabled(player, pData)) {
        data.clearNoFallData();
        useLoc.setWorld(null);
        aux.returnPlayerMoveInfo(moveInfo);
        return;
    }
    final boolean debug = pData.isDebugActive(CheckType.MOVING_NOFALL);
    boolean allowReset = true;
    float fallDistance = player.getFallDistance();
    final float yDiff = (float) (data.noFallMaxY - loc.getY());
    // Raw damage.
    final double damage = BridgeHealth.getRawDamage(event);
    // TODO: Account for modifiers.
    if (debug) {
        debug(player, "Damage(FALL/PRE): " + damage + " / mc=" + player.getFallDistance() + " nf=" + data.noFallFallDistance + " yDiff=" + yDiff);
    }
    // NoFall bypass checks.
    if (!data.noFallSkipAirCheck) {
        // Cheat: let Minecraft gather and deal fall damage.
        /*
             * TODO: data.noFallSkipAirCheck is used to skip checking in
             * general, thus move into that block or not?
             */
        // TODO: Could consider skipping accumulated fall distance for NoFall in general as well.
        final float dataDist = Math.max(yDiff, data.noFallFallDistance);
        final double dataDamage = NoFall.getDamage(dataDist);
        if (damage > dataDamage + 0.5 || dataDamage <= 0.0) {
            // TODO: Also relate past y-distance(s) to the fall distance (mc).
            // Hot fix: allow fall damage in lava.
            /*
                 * TODO: Correctly model the half fall distance per in-lava move
                 * and taking fall damage in lava. Should have a block flag for
                 * this.
                 */
            final PlayerMoveData firstPastMove = data.playerMoves.getFirstPastMove();
            if (pLoc.isOnGround() && pLoc.isInLava() && firstPastMove.toIsValid && firstPastMove.yDistance < 0.0) {
                /*
                     * 1. Strictly someone could attempt to accumulate fall
                     * damage by help of fast place and pickup lava. 2. There
                     * are other cases not ending up in lava, but having a
                     * reduced fall distance (then bigger than nofall data).
                     */
                if (debug) {
                    debug(player, "NoFall/Damage: allow fall damage in lava (hotfix).");
                }
            } else if (noFallVL(player, "fakefall", data, cc)) {
                // NOTE: Double violations are possible with the in-air check below.
                // TODO: Differing sub checks, once cancel action...
                player.setFallDistance(dataDist);
                if (dataDamage <= 0.0) {
                    // Cancel the event.
                    event.setCancelled(true);
                    useLoc.setWorld(null);
                    aux.returnPlayerMoveInfo(moveInfo);
                    return;
                } else {
                    // Adjust and continue.
                    if (debug) {
                        debug(player, "NoFall/Damage: override player fall distance and damage (" + fallDistance + " -> " + dataDist + ").");
                    }
                    fallDistance = dataDist;
                    BridgeHealth.setRawDamage(event, dataDamage);
                }
            }
        }
        // Cheat: set ground to true in-air.
        // Be sure not to lose that block.
        // TODO: What is this and why is it right here?
        data.noFallFallDistance += 1.0;
        // TODO: Account for liquid too?
        if (!pLoc.isOnGround(1.0, 0.3, 0.1) && !pLoc.isResetCond() && !pLoc.isAboveLadder() && !pLoc.isAboveStairs()) {
            // Likely: force damage in mid-air by setting on-ground to true.
            if (noFallVL(player, "fakeground", data, cc) && data.hasSetBack()) {
                // Cancel the event and restore fall distance.
                // NoFall data will not be reset
                allowReset = false;
            }
        } else {
            // Legitimate damage: clear accounting data.
            data.vDistAcc.clear();
        // TODO: Why only reset in case of !data.noFallSkipAirCheck?
        // TODO: Also reset other properties.
        // TODO: Also reset in other cases (moved too quickly)?
        }
    }
    aux.returnPlayerMoveInfo(moveInfo);
    // Fall-back check (skip with jump amplifier).
    final double maxD = data.jumpAmplifier > 0.0 ? NoFall.getDamage((float) NoFall.getApplicableFallHeight(player, loc.getY(), data)) : NoFall.getDamage(Math.max(yDiff, Math.max(data.noFallFallDistance, fallDistance))) + (allowReset ? 0.0 : Magic.FALL_DAMAGE_DIST);
    if (maxD > damage) {
        // TODO: respect dealDamage ?
        BridgeHealth.setRawDamage(event, maxD);
        if (debug) {
            debug(player, "Adjust fall damage to: " + maxD);
        }
    }
    if (allowReset) {
        // Normal fall damage, reset data.
        data.clearNoFallData();
        if (debug) {
            debug(player, "Reset NoFall data on fall damage.");
        }
    } else {
        // (Do not cancel the event, otherwise: "moved too quickly exploit".)
        if (cc.noFallViolationReset) {
            data.clearNoFallData();
        }
        // Add player to hover checks.
        if (cc.sfHoverCheck && data.sfHoverTicks < 0) {
            data.sfHoverTicks = 0;
            hoverTicks.add(player.getName());
        }
    }
    // Entity fall-distance should be reset elsewhere.
    // Cleanup.
    useLoc.setWorld(null);
}
Also used : PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location)

Example 40 with IPlayerData

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

the class MovingListener method onCancelledMove.

/**
 * Adjust data for a cancelled move. No teleport event will fire, but an
 * outgoing position is sent. Note that event.getFrom() may be overridden by
 * a plugin, which the server will ignore, but can lead to confusion.
 *
 * @param player
 * @param from
 * @param tick
 * @param now
 * @param mData
 * @param data
 */
private void onCancelledMove(final Player player, final Location from, final int tick, final long now, final MovingData mData, final MovingConfig mCc, final CombinedData data, final IPlayerData pData) {
    final boolean debug = pData.isDebugActive(checkType);
    // Detect our own set back, choice of reference location.
    if (mData.hasTeleported()) {
        final Location ref = mData.getTeleported();
        // Initiate further action depending on settings.
        final PlayerSetBackMethod method = mCc.playerSetBackMethod;
        if (method.shouldUpdateFrom()) {
            // Attempt to do without a PlayerTeleportEvent as follow up.
            // TODO: Doing this on MONITOR priority is problematic, despite optimal.
            LocUtil.set(from, ref);
        }
        if (method.shouldSchedule()) {
            // Schedule the teleport, because it might be faster than the next incoming packet.
            final IPlayerData pd = DataManager.getPlayerData(player);
            if (pd.isPlayerSetBackScheduled()) {
                debug(player, "Teleport (set back) already scheduled to: " + ref);
            } else if (debug) {
                pd.requestPlayerSetBack();
                if (debug) {
                    debug(player, "Schedule teleport (set back) to: " + ref);
                }
            }
        }
    // (Position adaption will happen with the teleport on tick, or with the next move.)
    }
    // Assume the implicit teleport to the from-location (no Bukkit event fires).
    // Not reset frequency, but do set yaw.
    Combined.resetYawRate(player, from.getYaw(), now, false, pData);
    aux.resetPositionsAndMediumProperties(player, from, mData, mCc);
    // TODO: Should probably leave this to the teleport event!
    mData.resetTrace(player, from, tick, mcAccess.getHandle(), mCc);
    // Expect a teleport to the from location (packet balance, no Bukkit event will fire).
    if (pData.isCheckActive(CheckType.NET_FLYINGFREQUENCY, player)) {
        // TODO: A summary method.
        pData.getGenericInstance(NetData.class).teleportQueue.onTeleportEvent(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch());
    }
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerSetBackMethod(fr.neatmonster.nocheatplus.checks.moving.player.PlayerSetBackMethod) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location)

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