Search in sources :

Example 16 with IPlayerData

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

the class InventoryListener method onInventoryClick.

/**
 * We listen to InventoryClick events for the FastClick check.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onInventoryClick(final InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }
    final long now = System.currentTimeMillis();
    final HumanEntity entity = event.getWhoClicked();
    if (!(entity instanceof Player)) {
        return;
    }
    final Player player = (Player) entity;
    final IPlayerData pData = DataManager.getPlayerData(player);
    final InventoryData data = pData.getGenericInstance(InventoryData.class);
    final int slot = event.getSlot();
    if (pData.isDebugActive(checkType)) {
        outputDebugInventoryClick(player, slot, event, data);
    }
    if (slot == InventoryView.OUTSIDE || slot < 0) {
        data.lastClickTime = now;
        return;
    }
    final ItemStack cursor = event.getCursor();
    final ItemStack clicked = event.getCurrentItem();
    boolean cancel = false;
    // Illegal enchantment checks.
    try {
        if (!cancel && Items.checkIllegalEnchantments(player, clicked, pData)) {
            cancel = true;
            counters.addPrimaryThread(idIllegalItem, 1);
        }
    }// Hotfix (CB)
     catch (final ArrayIndexOutOfBoundsException e) {
    }
    try {
        if (!cancel && Items.checkIllegalEnchantments(player, cursor, pData)) {
            cancel = true;
            counters.addPrimaryThread(idIllegalItem, 1);
        }
    }// Hotfix (CB)
     catch (final ArrayIndexOutOfBoundsException e) {
    }
    // Fast inventory manipulation check.
    if (fastClick.isEnabled(player, pData)) {
        final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
        if (player.getGameMode() != GameMode.CREATIVE || !cc.fastClickSpareCreative) {
            if (fastClick.check(player, now, event.getView(), slot, cursor, clicked, event.isShiftClick(), data, cc, pData)) {
                // The check requested the event to be cancelled.
                cancel = true;
            }
            // Feed the improbable.
            Improbable.feed(player, 0.7f, System.currentTimeMillis());
        }
    }
    data.lastClickTime = now;
    if (cancel) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) HumanEntity(org.bukkit.entity.HumanEntity) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 17 with IPlayerData

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

the class Open method check.

/**
 * This check contains the isEnabled checking (!). Inventory is closed if set in the config.
 * @param player
 * @return If cancelling some event is opportune (open inventory and cancel flag set).
 */
public boolean check(final Player player) {
    if (// TODO: POC: Item duplication with teleporting NPCS, having their inventory open.
    exeSet.getHandle().isRegardedAsNpc(player) || !isEnabled(player) || !InventoryUtil.hasInventoryOpen(player)) {
        return false;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
    if (cc.openClose) {
        final UUID id = player.getUniqueId();
        if (this.nestedPlayer == null || !id.equals(this.nestedPlayer)) {
            // (The second condition represents an error, but we don't handle alternating things just yet.)
            this.nestedPlayer = id;
            player.closeInventory();
            this.nestedPlayer = null;
        }
    }
    return cc.openCancelOther;
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) UUID(java.util.UUID)

Example 18 with IPlayerData

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

the class FightListener method onEntityDamage.

/**
 * We listen to EntityDamage events for obvious reasons.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityDamage(final EntityDamageEvent event) {
    final Entity damaged = event.getEntity();
    final Player damagedPlayer = damaged instanceof Player ? (Player) damaged : null;
    final FightData damagedData;
    final boolean damagedIsDead = damaged.isDead();
    final boolean damagedIsFake = !crossPlugin.getHandle().isNativeEntity(damaged);
    IPenaltyList penaltyList = null;
    if (damagedPlayer != null) {
        final IPlayerData damagedPData = DataManager.getPlayerData(damagedPlayer);
        damagedData = damagedPData.getGenericInstance(FightData.class);
        if (!damagedIsDead) {
            // (Do not test the savage.)
            if (damagedPData.isCheckActive(CheckType.FIGHT_GODMODE, damagedPlayer)) {
                if (penaltyList == null) {
                    penaltyList = new DefaultPenaltyList();
                }
                if (godMode.check(damagedPlayer, damagedIsFake, BridgeHealth.getRawDamage(event), damagedData, damagedPData)) {
                    // It requested to "cancel" the players invulnerability, so set their noDamageTicks to 0.
                    damagedPlayer.setNoDamageTicks(0);
                }
            }
            // Adjust buffer for fast heal checks.
            if (BridgeHealth.getHealth(damagedPlayer) >= BridgeHealth.getMaxHealth(damagedPlayer)) {
                // TODO: Might use the same FightData instance for GodMode.
                if (damagedData.fastHealBuffer < 0) {
                    // Reduce negative buffer with each full health.
                    damagedData.fastHealBuffer /= 2;
                }
                // Set reference time.
                damagedData.fastHealRefTime = System.currentTimeMillis();
            }
        // TODO: TEST: Check unused velocity for the damaged player. (Needs more efficient pre condition checks.)
        }
        if (damagedPData.isDebugActive(checkType)) {
            // TODO: Pass result to further checks for reference?
            UnusedVelocity.checkUnusedVelocity(damagedPlayer, CheckType.FIGHT, damagedPData);
        }
    } else {
        damagedData = null;
    }
    // Attacking entities.
    if (event instanceof EntityDamageByEntityEvent) {
        if (penaltyList == null) {
            penaltyList = new DefaultPenaltyList();
        }
        onEntityDamageByEntity(damaged, damagedPlayer, damagedIsDead, damagedIsFake, damagedData, (EntityDamageByEntityEvent) event, penaltyList);
    }
    if (penaltyList != null && !penaltyList.isEmpty()) {
        if (penaltyList.hasGenericPenalties()) {
            penaltyList.applyAllApplicableGenericPenalties(event);
        }
        if (penaltyList.hasNonGenericPenalties()) {
            penaltyList.applyNonGenericPenalties(event);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) DefaultPenaltyList(fr.neatmonster.nocheatplus.actions.types.penalty.DefaultPenaltyList) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) IPenaltyList(fr.neatmonster.nocheatplus.actions.types.penalty.IPenaltyList) EventHandler(org.bukkit.event.EventHandler)

Example 19 with IPlayerData

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

the class CombinedListener method onPlayerJoin.

/**
 * We listen to this event to prevent players from leaving while falling, so from avoiding fall damages.
 *
 * @param event
 *            the event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(final PlayerJoinEvent event) {
    // TODO: EventPriority
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final CombinedData data = pData.getGenericInstance(CombinedData.class);
    final CombinedConfig cc = pData.getGenericInstance(CombinedConfig.class);
    if (cc.invulnerableCheck && (cc.invulnerableTriggerAlways || cc.invulnerableTriggerFallDistance && player.getFallDistance() > 0)) {
        // TODO: maybe make a heuristic for small fall distances with ground under feet (prevents future abuse with jumping) ?
        final int invulnerableTicks = mcAccess.getHandle().getInvulnerableTicks(player);
        if (invulnerableTicks == Integer.MAX_VALUE) {
        // TODO: Maybe log a warning.
        } else {
            final int ticks = cc.invulnerableInitialTicksJoin >= 0 ? cc.invulnerableInitialTicksJoin : invulnerableTicks;
            data.invulnerableTick = TickTask.getTick() + ticks;
            mcAccess.getHandle().setInvulnerableTicks(player, 0);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 20 with IPlayerData

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

the class CombinedListener method onEntityDamage.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
    final Entity entity = event.getEntity();
    if (!(entity instanceof Player))
        return;
    final Player player = (Player) entity;
    final IPlayerData pData = DataManager.getPlayerData(player);
    final CombinedConfig cc = pData.getGenericInstance(CombinedConfig.class);
    if (!cc.invulnerableCheck)
        return;
    final DamageCause cause = event.getCause();
    // Ignored causes.
    if (cc.invulnerableIgnore.contains(cause))
        return;
    // Modified invulnerable ticks.
    Integer modifier = cc.invulnerableModifiers.get(cause);
    if (modifier == null)
        modifier = cc.invulnerableModifierDefault;
    final CombinedData data = pData.getGenericInstance(CombinedData.class);
    // TODO: account for tick task reset ? [it should not though, due to data resetting too, but API would allow it]
    if (TickTask.getTick() >= data.invulnerableTick + modifier.intValue())
        return;
    // Still invulnerable.
    event.setCancelled(true);
    counters.addPrimaryThread(idFakeInvulnerable, 1);
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) 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