Search in sources :

Example 26 with IPlayerData

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

the class BlockPlaceListener method onProjectileLaunch.

/**
 * We listen to ProjectileLaunch events to prevent players from launching projectiles too quickly.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
    // The shooter needs to be a player.
    final Projectile projectile = event.getEntity();
    final Player player = BridgeMisc.getShooterPlayer(projectile);
    if (player == null) {
        return;
    }
    if (MovingUtil.hasScheduledPlayerSetBack(player)) {
        // TODO: Should log.
        event.setCancelled(true);
        return;
    }
    // And the projectile must be one the following:
    EntityType type = event.getEntityType();
    switch(type) {
        case ENDER_PEARL:
            break;
        case ENDER_SIGNAL:
            break;
        case EGG:
            break;
        case SNOWBALL:
            break;
        case THROWN_EXP_BOTTLE:
            break;
        case SPLASH_POTION:
            break;
        default:
            return;
    }
    // Do the actual check...
    final IPlayerData pData = DataManager.getPlayerData(player);
    final BlockPlaceConfig cc = pData.getGenericInstance(BlockPlaceConfig.class);
    boolean cancel = false;
    if (speed.isEnabled(player, pData)) {
        final long now = System.currentTimeMillis();
        final Location loc = player.getLocation(useLoc);
        if (Combined.checkYawRate(player, loc.getYaw(), now, loc.getWorld().getName(), pData)) {
            // Yawrate (checked extra).
            cancel = true;
        }
        if (speed.check(player, cc, pData)) {
            // If the check was positive, cancel the event.
            cancel = true;
        } else if (Improbable.check(player, 0.6f, now, "blockplace.speed", pData)) {
            // Combined fighting speed.
            cancel = true;
        }
    }
    // Ender pearl glitch (ab-) use.
    if (!cancel && type == EntityType.ENDER_PEARL) {
        if (!pData.getGenericInstance(CombinedConfig.class).enderPearlCheck) {
        // Do nothing !
        // TODO: Might have further flags?
        } else if (!BlockProperties.isPassable(projectile.getLocation(useLoc))) {
            // Launch into a block.
            // TODO: This might be a general check later.
            cancel = true;
        } else {
            if (!BlockProperties.isPassable(player.getEyeLocation(), projectile.getLocation(useLoc))) {
                // (Spare a useLoc2, for this is seldom rather.)
                // Something between player
                // TODO: This might be a general check later.
                cancel = true;
            } else {
                final Material mat = player.getLocation(useLoc).getBlock().getType();
                final long flags = BlockProperties.F_CLIMBABLE | BlockProperties.F_LIQUID | BlockProperties.F_IGN_PASSABLE;
                if (!BlockProperties.isAir(mat) && (BlockProperties.getBlockFlags(mat) & flags) == 0 && !mcAccess.getHandle().hasGravity(mat)) {
                    // Still fails on piston traps etc.
                    if (!BlockProperties.isPassable(player.getLocation(), projectile.getLocation()) && !BlockProperties.isOnGroundOrResetCond(player, player.getLocation(), pData.getGenericInstance(MovingConfig.class).yOnGround)) {
                        cancel = true;
                    }
                }
            }
        }
        if (cancel) {
            counters.addPrimaryThread(idEnderPearl, 1);
        }
    }
    // Cancelled ?
    if (cancel) {
        event.setCancelled(true);
    }
    // Cleanup.
    useLoc.setWorld(null);
}
Also used : EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Material(org.bukkit.Material) MovingConfig(fr.neatmonster.nocheatplus.checks.moving.MovingConfig) Projectile(org.bukkit.entity.Projectile) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 27 with IPlayerData

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

the class BlockPlaceListener method onBlockPlace.

/**
 * We listen to BlockPlace events for obvious reasons.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockPlace(final BlockPlaceEvent event) {
    final Block block = event.getBlockPlaced();
    final Block blockAgainst = event.getBlockAgainst();
    // Skip any null blocks.
    if (block == null || blockAgainst == null) {
        return;
    }
    // TODO: What if same block?
    // TODO: Revise material use (not block.get... ?)
    // final Material mat = block.getType();
    final Player player = event.getPlayer();
    final Material placedMat;
    if (hasGetReplacedState) {
        placedMat = event.getBlockPlaced().getType();
    } else if (Bridge1_9.hasGetItemInOffHand()) {
        final ItemStack stack = event.getItemInHand();
        placedMat = BlockProperties.isAir(stack) ? Material.AIR : stack.getType();
    } else {
        // Safety first.
        placedMat = Bridge1_9.getItemInMainHand(player).getType();
    }
    boolean cancelled = false;
    // TODO: Use for data + config getting etc.
    final IPlayerData pData = DataManager.getPlayerData(player);
    final BlockPlaceData data = pData.getGenericInstance(BlockPlaceData.class);
    final BlockPlaceConfig cc = pData.getGenericInstance(BlockPlaceConfig.class);
    final BlockInteractData bdata = pData.getGenericInstance(BlockInteractData.class);
    final int tick = TickTask.getTick();
    // isInteractBlock - the block placed against is the block last interacted with.
    final boolean isInteractBlock = !bdata.getLastIsCancelled() && bdata.matchesLastBlock(tick, blockAgainst);
    int skippedRedundantChecks = 0;
    final boolean debug = pData.isDebugActive(CheckType.BLOCKPLACE);
    final boolean shouldSkipSome;
    if (blockMultiPlaceEvent != null && event.getClass() == blockMultiPlaceEvent) {
        if (placedMat == Material.BEDROCK || Bridge1_9.hasEndCrystalItem() && placedMat == Bridge1_9.END_CRYSTAL_ITEM) {
            shouldSkipSome = true;
        } else {
            if (debug) {
                debug(player, "Block place " + event.getClass().getName() + " " + placedMat);
            }
            shouldSkipSome = false;
        }
    } else {
        shouldSkipSome = false;
    }
    if (placedMat == Material.SIGN) {
        // Might move to MONITOR priority.
        data.autoSignPlacedTime = System.currentTimeMillis();
        // Always hash as sign post for improved compatibility with Lockette etc.
        data.autoSignPlacedHash = getBlockPlaceHash(block, Material.SIGN);
    }
    // Don't run checks, if a set back is scheduled.
    if (!cancelled && pData.isPlayerSetBackScheduled()) {
        cancelled = true;
    }
    // Fast place check.
    if (!cancelled && fastPlace.isEnabled(player, pData)) {
        if (fastPlace.check(player, block, tick, data, cc, pData)) {
            cancelled = true;
        } else {
            // Feed the improbable.
            Improbable.feed(player, 0.5f, System.currentTimeMillis(), pData);
        }
    }
    // No swing check (player doesn't swing their arm when placing a lily pad).
    if (!cancelled && !cc.noSwingExceptions.contains(placedMat) && noSwing.isEnabled(player, pData) && noSwing.check(player, data, cc)) {
        // Consider skipping all insta placables or using simplified version (true or true within time frame).
        cancelled = true;
    }
    final FlyingQueueHandle flyingHandle;
    final boolean reachCheck = pData.isCheckActive(CheckType.BLOCKPLACE_REACH, player);
    final boolean directionCheck = pData.isCheckActive(CheckType.BLOCKPLACE_DIRECTION, player);
    if (reachCheck || directionCheck) {
        flyingHandle = new FlyingQueueHandle(pData);
        final Location loc = player.getLocation(useLoc);
        final double eyeHeight = MovingUtil.getEyeHeight(player);
        // Reach check (distance).
        if (!cancelled && !shouldSkipSome) {
            if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_REACH)) {
                skippedRedundantChecks++;
            } else if (reachCheck && reach.check(player, eyeHeight, block, data, cc)) {
                cancelled = true;
            }
        }
        // Direction check.
        if (!cancelled && !shouldSkipSome) {
            if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_DIRECTION)) {
                skippedRedundantChecks++;
            } else if (directionCheck && direction.check(player, loc, eyeHeight, block, flyingHandle, data, cc, pData)) {
                cancelled = true;
            }
        }
        useLoc.setWorld(null);
    } else {
        flyingHandle = null;
    }
    // Surrounding material.
    if (!cancelled && against.isEnabled(player, pData) && against.check(player, block, placedMat, blockAgainst, isInteractBlock, data, cc, pData)) {
        cancelled = true;
    }
    // If one of the checks requested to cancel the event, do so.
    if (cancelled) {
        event.setCancelled(cancelled);
    } else {
        // Debug log (only if not cancelled, to avoid spam).
        if (debug) {
            debugBlockPlace(player, placedMat, block, blockAgainst, skippedRedundantChecks, flyingHandle, pData);
        }
    }
// Cleanup
// Reminder(currently unused): useLoc.setWorld(null);
}
Also used : Player(org.bukkit.entity.Player) BlockInteractData(fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractData) FlyingQueueHandle(fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle) Material(org.bukkit.Material) Block(org.bukkit.block.Block) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 28 with IPlayerData

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

the class BlockPlaceListener method onSignChange.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onSignChange(final SignChangeEvent event) {
    if (event.getClass() != SignChangeEvent.class) {
        // TODO: Don't understand why two consecutive events editing the same block are a problem.
        return;
    }
    final Player player = event.getPlayer();
    final Block block = event.getBlock();
    final String[] lines = event.getLines();
    if (block == null || lines == null || player == null) {
        // Somewhat defensive.
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    if (autoSign.isEnabled(player, pData) && autoSign.check(player, block, lines, pData)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 29 with IPlayerData

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

the class BlockBreakListener method checkBlockDamage.

private void checkBlockDamage(final Player player, final Block block, final Cancellable event) {
    final long now = System.currentTimeMillis();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final BlockBreakData data = pData.getGenericInstance(BlockBreakData.class);
    // Do not care about null blocks.
    if (block == null) {
        return;
    }
    final int tick = TickTask.getTick();
    // Skip if already set to the same block without breaking within one tick difference.
    final ItemStack stack = Bridge1_9.getItemInMainHand(player);
    final Material tool = stack == null ? null : stack.getType();
    if (data.toolChanged(tool)) {
    // Update.
    } else if (tick < data.clickedTick || now < data.fastBreakfirstDamage || now < data.fastBreakBreakTime) {
    // Time/tick ran backwards: Update.
    // Tick running backwards should not happen in the main thread unless for reload. A plugin could reset it (not intended).
    } else if (data.fastBreakBreakTime < data.fastBreakfirstDamage && data.clickedX == block.getX() && data.clickedZ == block.getZ() && data.clickedY == block.getY()) {
        // Preserve first damage time.
        if (tick - data.clickedTick <= 1) {
            return;
        }
    }
    // (Always set, the interact event only fires once: the first time.)
    // Only record first damage:
    data.setClickedBlock(block, tick, now, tool);
    // Compare with BlockInteract data (debug first).
    if (pData.isDebugActive(CheckType.BLOCKBREAK)) {
        BlockInteractListener.debugBlockVSBlockInteract(player, this.checkType, block, "checkBlockDamage", Action.LEFT_CLICK_BLOCK, pData);
    }
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 30 with IPlayerData

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

the class Captcha method resetCaptcha.

@Override
public void resetCaptcha(Player player) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    ChatData data = pData.getGenericInstance(ChatData.class);
    synchronized (data) {
        resetCaptcha(player, pData.getGenericInstance(ChatConfig.class), data, pData);
    }
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

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