Search in sources :

Example 71 with IPlayerData

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

the class BlockBreakListener method onBlockBreak.

/**
 * We listen to BlockBreak events for obvious reasons.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onBlockBreak(final BlockBreakEvent event) {
    final long now = System.currentTimeMillis();
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    // TODO: Legacy / encapsulate fully there.
    if (Items.checkIllegalEnchantmentsAllHands(player, pData)) {
        event.setCancelled(true);
        counters.addPrimaryThread(idCancelDIllegalItem, 1);
    } else if (MovingUtil.hasScheduledPlayerSetBack(player)) {
        event.setCancelled(true);
    }
    // Cancelled events only leads to resetting insta break.
    if (event.isCancelled()) {
        isInstaBreak = AlmostBoolean.NO;
        return;
    }
    // TODO: maybe invalidate instaBreak on some occasions.
    final Block block = event.getBlock();
    boolean cancelled = false;
    // Do the actual checks, if still needed. It's a good idea to make computationally cheap checks first, because
    // it may save us from doing the computationally expensive checks.
    final BlockBreakConfig cc = pData.getGenericInstance(BlockBreakConfig.class);
    final BlockBreakData data = pData.getGenericInstance(BlockBreakData.class);
    final BlockInteractData bdata = pData.getGenericInstance(BlockInteractData.class);
    /*
         * Re-check if this is a block interacted with before. With instantly
         * broken blocks, this may be off by one orthogonally.
         */
    final int tick = TickTask.getTick();
    final boolean isInteractBlock = !bdata.getLastIsCancelled() && bdata.matchesLastBlock(tick, block);
    int skippedRedundantChecks = 0;
    final GameMode gameMode = player.getGameMode();
    // Has the player broken a block that was not damaged before?
    final boolean wrongBlockEnabled = wrongBlock.isEnabled(player, pData);
    if (wrongBlockEnabled && wrongBlock.check(player, block, cc, data, pData, isInstaBreak)) {
        cancelled = true;
    }
    // Has the player broken more blocks per second than allowed?
    if (!cancelled && frequency.isEnabled(player, pData) && frequency.check(player, tick, cc, data, pData)) {
        cancelled = true;
    }
    // Has the player broken blocks faster than possible?
    if (!cancelled && gameMode != GameMode.CREATIVE && fastBreak.isEnabled(player, pData) && fastBreak.check(player, block, isInstaBreak, cc, data, pData)) {
        cancelled = true;
    }
    // Did the arm of the player move before breaking this block?
    if (!cancelled && noSwing.isEnabled(player, pData) && noSwing.check(player, data, pData)) {
        cancelled = true;
    }
    final FlyingQueueHandle flyingHandle;
    final boolean reachEnabled = reach.isEnabled(player, pData);
    final boolean directionEnabled = direction.isEnabled(player, pData);
    if (reachEnabled || directionEnabled) {
        flyingHandle = new FlyingQueueHandle(pData);
        final Location loc = player.getLocation(useLoc);
        final double eyeHeight = MovingUtil.getEyeHeight(player);
        // Is the block really in reach distance?
        if (!cancelled) {
            if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_REACH)) {
                skippedRedundantChecks++;
            } else if (reachEnabled && reach.check(player, eyeHeight, block, data, cc)) {
                cancelled = true;
            }
        }
        // TODO: Skip if checks were run on this block (all sorts of hashes/conditions).
        if (!cancelled) {
            if (isInteractBlock && (bdata.isPassedCheck(CheckType.BLOCKINTERACT_DIRECTION) || bdata.isPassedCheck(CheckType.BLOCKINTERACT_VISIBLE))) {
                skippedRedundantChecks++;
            } else if (directionEnabled && direction.check(player, loc, eyeHeight, block, flyingHandle, data, cc, pData)) {
                cancelled = true;
            }
        }
        useLoc.setWorld(null);
    } else {
        flyingHandle = null;
    }
    // Destroying liquid blocks.
    if (!cancelled && BlockProperties.isLiquid(block.getType()) && !pData.hasPermission(Permissions.BLOCKBREAK_BREAK_LIQUID, player) && !NCPExemptionManager.isExempted(player, CheckType.BLOCKBREAK_BREAK)) {
        cancelled = true;
    }
    // On cancel...
    if (cancelled) {
        event.setCancelled(cancelled);
        // Reset damage position:
        // TODO: Review this (!), check if set at all !?
        data.clickedX = block.getX();
        data.clickedY = block.getY();
        data.clickedZ = block.getZ();
    } else {
        // Debug log (only if not cancelled, to avoid spam).
        if (pData.isDebugActive(CheckType.BLOCKBREAK)) {
            debugBlockBreakResult(player, block, skippedRedundantChecks, flyingHandle, pData);
        }
    }
    if (isInstaBreak.decideOptimistically()) {
        data.wasInstaBreak = now;
    } else {
        data.wasInstaBreak = 0;
    }
    // Adjust data.
    data.fastBreakBreakTime = now;
    // data.fastBreakfirstDamage = now;
    isInstaBreak = AlmostBoolean.NO;
}
Also used : Player(org.bukkit.entity.Player) BlockInteractData(fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractData) FlyingQueueHandle(fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle) GameMode(org.bukkit.GameMode) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 72 with IPlayerData

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

the class ChatListener method onPlayerLogin.

/**
 * We listen to this type of events to prevent spambots from login to the server.
 *
 * @param event
 *            the event
 */
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerLogin(final PlayerLoginEvent event) {
    if (event.getResult() != Result.ALLOWED)
        return;
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final ChatConfig cc = pData.getGenericInstance(ChatConfig.class);
    final ChatData data = pData.getGenericInstance(ChatData.class);
    // Reset captcha of player if needed.
    synchronized (data) {
        captcha.resetCaptcha(player, cc, data, pData);
    }
    // Fast relog check.
    if (relog.isEnabled(player, pData) && relog.unsafeLoginCheck(player, cc, data, pData)) {
        event.disallow(Result.KICK_OTHER, cc.relogKickMessage);
    } else if (logins.isEnabled(player, pData) && logins.check(player, cc, data)) {
        event.disallow(Result.KICK_OTHER, cc.loginsKickMessage);
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 73 with IPlayerData

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

the class ChatListener method playerJoins.

@Override
public void playerJoins(final Player player) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final ChatConfig cc = pData.getGenericInstance(ChatConfig.class);
    final ChatData data = pData.getGenericInstance(ChatData.class);
    /*
         * TODO: The isEnabled check must be done with IWorldData (no locking).
         * Specifically because enabling/disabling checks should be done in the
         * primary thread, regardless of the capabilities of WorldDataManager
         * implementation.
         */
    synchronized (data) {
        if (captcha.isEnabled(player, pData)) {
            if (captcha.shouldCheckCaptcha(player, cc, data, pData)) {
                // shouldCheckCaptcha: only if really enabled.
                // TODO: Later: add check for cc.captchaOnLogin or so (before shouldCheckCaptcha).
                // TODO: maybe schedule this to come after other plugins messages.
                captcha.sendNewCaptcha(player, cc, data);
            }
        }
    }
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 74 with IPlayerData

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

the class Color method check.

/**
 * Checks a player.
 *
 * @param player
 *            the player
 * @param message
 *            the message
 * @param isMainThread
 *            is the thread the main thread
 * @return the string
 */
public String check(final Player player, final String message, final boolean isMainThread) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final ChatConfig cc = pData.getGenericInstance(ChatConfig.class);
    final ChatData data = pData.getGenericInstance(ChatData.class);
    // Keep related to ChatData used lock.
    synchronized (data) {
        // If the message contains colors...
        if (message.contains("\247")) {
            // Increment the violation level of the player.
            data.colorVL++;
            // Find out if we need to remove the colors or not.
            if (executeActions(player, data.colorVL, 1D, cc.colorActions).willCancel())
                // Remove color codes.
                return message.replaceAll("\302\247.", "").replaceAll("\247.", "");
        }
    }
    return message;
}
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