Search in sources :

Example 21 with IPlayerData

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

the class Gutenberg method onEditBook.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEditBook(final PlayerEditBookEvent event) {
    final Player player = event.getPlayer();
    if (!isEnabled(player)) {
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
    final BookMeta newMeta = event.getNewBookMeta();
    final int pages = newMeta.getPageCount();
    if (pages <= 50) {
        // Legitimate.
        return;
    }
    // Violation.
    final int vl = pages - 50;
    if (executeActions(player, vl, vl, cc.gutenbergActions).willCancel()) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) BookMeta(org.bukkit.inventory.meta.BookMeta) EventHandler(org.bukkit.event.EventHandler)

Example 22 with IPlayerData

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

the class KeepAliveAdapter method onPacketReceiving.

@Override
public void onPacketReceiving(final PacketEvent event) {
    final long time = System.currentTimeMillis();
    final Player player = event.getPlayer();
    if (player == null) {
        counters.add(ProtocolLibComponent.idNullPlayer, 1);
        event.setCancelled(true);
        return;
    }
    // Always update last received time.
    final IPlayerData pData = DataManager.getPlayerData(player);
    final NetData data = pData.getGenericInstance(NetData.class);
    data.lastKeepAliveTime = time;
    final NetConfig cc = pData.getGenericInstance(NetConfig.class);
    // TODO: Better integration with god-mode check / trigger reset ndt.
    if (frequencyCheck.isEnabled(player, pData) && frequencyCheck.check(player, time, data, cc, pData)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) NetConfig(fr.neatmonster.nocheatplus.checks.net.NetConfig) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 23 with IPlayerData

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

the class MovingFlying method processConfirmTeleport.

private void processConfirmTeleport(final PacketEvent event) {
    final PacketContainer packet = event.getPacket();
    final StructureModifier<Integer> integers = packet.getIntegers();
    if (integers.size() != 1) {
        noConfirmTeleportPacket();
        return;
    }
    // TODO: Cross check legacy types (if they even had an integer).
    Integer teleportId = integers.read(0);
    if (teleportId == null) {
        // TODO: Not sure ...
        return;
    }
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final NetData data = pData.getGenericInstance(NetData.class);
    final AlmostBoolean matched = data.teleportQueue.processAck(teleportId);
    if (matched.decideOptimistically()) {
        ActionFrequency.subtract(System.currentTimeMillis(), 1, data.flyingFrequencyAll);
    }
    if (pData.isDebugActive(this.checkType)) {
        // TODO: FlyingFrequency / NET_MOVING? + check others who depend
        debug(player, "Confirm teleport packet" + (matched.decideOptimistically() ? (" (matched=" + matched + ")") : "") + ": " + teleportId);
    }
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) Player(org.bukkit.entity.Player) AlmostBoolean(fr.neatmonster.nocheatplus.compat.AlmostBoolean) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 24 with IPlayerData

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

the class UseEntityAdapter method onPacketReceiving.

@Override
public void onPacketReceiving(final PacketEvent event) {
    final long time = System.currentTimeMillis();
    final Player player = event.getPlayer();
    if (player == null) {
        // TODO: Warn once?
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    final NetData data = pData.getGenericInstance(NetData.class);
    // Always set last received time.
    data.lastKeepAliveTime = time;
    // Quick return, if no checks are active.
    if (!pData.isCheckActive(CheckType.NET_ATTACKFREQUENCY, player)) {
        return;
    }
    final PacketContainer packet = event.getPacket();
    // MIGHT: use entity, use block both on packet level?
    boolean isAttack = false;
    boolean packetInterpreted = false;
    if (legacySet != null) {
        // Attempt to extract legacy information.
        final int flags = getAction_legacy(packet);
        if ((flags & INTERPRETED) != 0) {
            packetInterpreted = true;
            if ((flags & ATTACK) != 0) {
                isAttack = true;
            }
        }
    }
    if (!packetInterpreted) {
        // Handle as if latest.
        final StructureModifier<EntityUseAction> actions;
        actions = packet.getEntityUseActions();
        if (actions.size() == 1 && actions.read(0) == EntityUseAction.ATTACK) {
            isAttack = true;
            packetInterpreted = true;
        }
    }
    if (!packetInterpreted) {
        // TODO: Log warning once, if the packet could not be interpreted.
        return;
    }
    // Run checks.
    boolean cancel = false;
    // AttackFrequency
    if (isAttack) {
        final NetConfig cc = pData.getGenericInstance(NetConfig.class);
        if (attackFrequency.isEnabled(player, pData) && attackFrequency.check(player, time, data, cc, pData)) {
            cancel = true;
        }
    }
    if (cancel) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) PacketContainer(com.comphenix.protocol.events.PacketContainer) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) EntityUseAction(com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction) NetConfig(fr.neatmonster.nocheatplus.checks.net.NetConfig) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 25 with IPlayerData

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

the class BlockInteractListener method onPlayerInteractMonitor.

@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onPlayerInteractMonitor(final PlayerInteractEvent event) {
    // Set event resolution.
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final BlockInteractData data = pData.getGenericInstance(BlockInteractData.class);
    data.setPlayerInteractEventResolution(event);
    // }
    if ((event.getAction() == Action.RIGHT_CLICK_AIR) && event.isCancelled() && event.useItemInHand() != Result.DENY) {
        final ItemStack stack = Bridge1_9.getUsedItem(player, event);
        if (stack != null && BridgeMisc.maybeElytraBoost(player, stack.getType())) {
            final int power = BridgeMisc.getFireworksPower(stack);
            final MovingData mData = pData.getGenericInstance(MovingData.class);
            final int ticks = Math.max((1 + power) * 20, 30);
            mData.fireworksBoostDuration = ticks;
            // Expiration tick: not general latency, rather a minimum margin for sudden congestion.
            mData.fireworksBoostTickExpire = TickTask.getTick() + ticks;
            // TODO: Implement using it in CreativeFly.
            if (pData.isDebugActive(CheckType.MOVING)) {
                debug(player, "Elytra boost (power " + power + "): " + stack);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) ItemStack(org.bukkit.inventory.ItemStack) 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