Search in sources :

Example 1 with EntityUseAction

use of com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction 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)

Aggregations

PacketContainer (com.comphenix.protocol.events.PacketContainer)1 EntityUseAction (com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction)1 NetConfig (fr.neatmonster.nocheatplus.checks.net.NetConfig)1 NetData (fr.neatmonster.nocheatplus.checks.net.NetData)1 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)1 Player (org.bukkit.entity.Player)1