Search in sources :

Example 1 with IPenaltyList

use of fr.neatmonster.nocheatplus.actions.types.penalty.IPenaltyList 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)

Aggregations

DefaultPenaltyList (fr.neatmonster.nocheatplus.actions.types.penalty.DefaultPenaltyList)1 IPenaltyList (fr.neatmonster.nocheatplus.actions.types.penalty.IPenaltyList)1 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1