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);
}
}
Aggregations