Search in sources :

Example 41 with IPlayerData

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

the class MovingListener method onPlayerPortalLowest.

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerPortalLowest(final PlayerPortalEvent event) {
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
    if (MovingUtil.hasScheduledPlayerSetBack(player)) {
        if (pData.isDebugActive(checkType)) {
            debug(player, "[PORTAL] Prevent use, due to a scheduled set back.");
        }
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 42 with IPlayerData

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

the class MovingListener method playerJoins.

@Override
public void playerJoins(final Player player) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    dataOnJoin(player, player.getLocation(useLoc), false, pData.getGenericInstance(MovingData.class), pData.getGenericInstance(MovingConfig.class), pData.isDebugActive(checkType));
    // Cleanup.
    useLoc.setWorld(null);
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 43 with IPlayerData

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

the class MovingListener method onPlayerRespawn.

/**
 * When a player respawns, all information related to the moving checks
 * becomes invalid.
 *
 * @param event
 *            the event
 */
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerRespawn(final PlayerRespawnEvent event) {
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    // TODO: Prevent/cancel scheduled teleport (use PlayerData/task for teleport, or a sequence count).
    data.clearMostMovingCheckData();
    // To force dataOnJoin to set it to loc.
    data.resetSetBack();
    // Handle respawn like join.
    dataOnJoin(player, event.getRespawnLocation(), true, data, pData.getGenericInstance(MovingConfig.class), pData.isDebugActive(checkType));
    // Patch up issues.
    if (Bridge1_9.hasGetItemInOffHand() && player.isBlocking()) {
        // Attempt to fix server-side-only blocking after respawn.
        redoShield(player);
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 44 with IPlayerData

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

the class MovingListener method handleEntityToggleGlideEvent.

/**
 * @param entity
 * @param isGliding
 * @return True, if the event is to be cancelled.
 */
private boolean handleEntityToggleGlideEvent(final Entity entity, final boolean isGliding) {
    // Ignore non players.
    if (!(entity instanceof Player)) {
        return false;
    }
    final Player player = (Player) entity;
    if (isGliding && !Bridge1_9.isGlidingWithElytra(player)) {
        // Includes check for elytra item.
        final PlayerMoveInfo info = aux.usePlayerMoveInfo();
        // Only restrict very near ground.
        info.set(player, player.getLocation(info.useLoc), null, 0.001);
        final IPlayerData pData = DataManager.getPlayerData(player);
        final MovingData data = pData.getGenericInstance(MovingData.class);
        final boolean res = !MovingUtil.canLiftOffWithElytra(player, info.from, data);
        info.cleanup();
        aux.returnPlayerMoveInfo(info);
        if (res && pData.isDebugActive(checkType)) {
            debug(player, "Prevent toggle glide on.");
        }
        return res;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)

Example 45 with IPlayerData

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

the class MovingListener method onPlayerTeleportMonitor.

/**
 * MONITOR: Adjust data to what happened.
 *
 * @param event
 */
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onPlayerTeleportMonitor(final PlayerTeleportEvent event) {
    // Evaluate result and adjust data.
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    // Invalidate first-move thing.
    // TODO: Might conflict with 'moved wrongly' on join.
    data.joinOrRespawn = false;
    // Special cases.
    final Location to = event.getTo();
    if (event.isCancelled()) {
        onPlayerTeleportMonitorCancelled(player, event, to, data, pData);
        return;
    } else if (to == null) {
        // Weird event.
        onPlayerTeleportMonitorNullTarget(player, event, to, data, pData);
        return;
    }
    final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
    // Detect our own player set backs.
    if (data.hasTeleported() && onPlayerTeleportMonitorHasTeleported(player, event, to, data, cc, pData)) {
        return;
    }
    // Skip extra data adjustments during special teleport, e.g. vehicle set back.
    boolean skipExtras = false;
    // Detect our own vehicle set backs (...).
    if (data.isVehicleSetBack) {
        // Uncertain if this is vehicle leave or vehicle enter.
        if (event.getCause() != BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION) {
            // TODO: Unexpected, what now?
            NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, CheckType.MOVING_VEHICLE) + "Unexpected teleport cause on vehicle set back: " + event.getCause());
        }
        // TODO: Consider to verify, if this is somewhere near the vehicle as expected (might need storing more data for a set back).
        skipExtras = true;
    }
    // Normal teleport
    final double fallDistance = data.noFallFallDistance;
    // final LiftOffEnvelope oldEnv = data.liftOffEnvelope; // Remember for workarounds.
    data.clearFlyData();
    data.clearPlayerMorePacketsData();
    data.setSetBack(to);
    // Important against concurrent modification exception.
    data.sfHoverTicks = -1;
    if (cc.loadChunksOnTeleport) {
        MovingUtil.ensureChunksLoaded(player, to, "teleport", data, cc, pData);
    }
    aux.resetPositionsAndMediumProperties(player, to, data, cc);
    // TODO: Decide to remove the LiftOffEnvelope thing completely.
    // if (TrigUtil.maxDistance(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ())  <= 12.0) {
    // // TODO: Might happen with bigger distances (mainly ender pearl thrown at others).
    // // Keep old lift-off envelope.
    // data.liftOffEnvelope = oldEnv;
    // }
    // Reset stuff.
    // TODO: Not sure.
    Combined.resetYawRate(player, to.getYaw(), System.currentTimeMillis(), true, pData);
    data.resetTeleported();
    if (!skipExtras) {
        // TODO: Detect transition from valid flying that needs resetting the fall distance.
        if (event.getCause() == TeleportCause.UNKNOWN) {
            // Always keep fall damage.
            player.setFallDistance((float) fallDistance);
            data.noFallFallDistance = (float) fallDistance;
        } else if (fallDistance > 1.0 && fallDistance - player.getFallDistance() > 0.0) {
            // Reset fall distance if set so in the config.
            if (!cc.noFallTpReset) {
                // (Set fall distance if set to not reset.)
                player.setFallDistance((float) fallDistance);
                data.noFallFallDistance = (float) fallDistance;
            } else if (fallDistance >= Magic.FALL_DAMAGE_DIST) {
                data.noFallSkipAirCheck = true;
            }
        }
        if (event.getCause() == TeleportCause.ENDER_PEARL) {
            // Prevent NoFall violations for ender-pearls.
            data.noFallSkipAirCheck = true;
        }
    }
    // Cross world teleportation issues with the end.
    final Location from = event.getFrom();
    if (from != null && // Currently only related to this.
    event.getCause() == TeleportCause.END_PORTAL && !from.getWorld().getName().equals(to.getWorld().getName())) {
        // Less java, though.
        // Remember the position teleported from.
        data.crossWorldFrom = new SimplePositionWithLook(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch());
    } else {
        // Reset last cross world position.
        data.crossWorldFrom = null;
    }
    // Log.
    if (pData.isDebugActive(checkType)) {
        debugTeleportMessage(player, event, "(normal)", to);
    }
}
Also used : Player(org.bukkit.entity.Player) SimplePositionWithLook(fr.neatmonster.nocheatplus.components.location.SimplePositionWithLook) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

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