Java Code Examples for org.bukkit.event.entity.EntityDamageEvent#getFinalDamage()

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent#getFinalDamage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReceivedDamageEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamageReceived(EntityDamageEvent event) {
    if(event.getEntity() instanceof LivingEntity){
        if(StackTools.hasValidStackData(event.getEntity())){
            LivingEntity entity = (LivingEntity) event.getEntity();
            if(sm.getCustomConfig().getBoolean("kill-step-damage.enabled")){
                double healthAfter = entity.getHealth() - event.getFinalDamage();
                if(healthAfter <= 0){
                    entity.setMetadata(GlobalValues.LEFTOVER_DAMAGE, new FixedMetadataValue(sm, Math.abs(healthAfter)));
                }
            }

            if(!sm.getCustomConfig().getStringList("multiply-damage-received.cause-blacklist")
                    .contains(event.getCause().toString())) {
                if(event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){
                    return;
                }
                int stackSize = StackTools.getSize(entity);
                double extraDamage = event.getDamage() + ((event.getDamage() * (stackSize - 1) * 0.25));
                event.setDamage(extraDamage);
            }
        }
    }
}
 
Example 2
Source File: Taunt.java    From EliteMobs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamaged(EntityDamageEvent event) {

    if (!(event.getEntity() instanceof LivingEntity) ||
            ((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0 ||
            !event.getEntity().isValid())
        return;

    EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity());
    if (eliteMobEntity == null) return;
    if (EntityTracker.hasPower(this, event.getEntity())) {
        Entity entity = event.getEntity();

        if (event.getCause().equals(EntityDamageEvent.DamageCause.PROJECTILE))
            nametagProcessor(entity, DAMAGED_BY_BOW_LIST);
        else
            nametagProcessor(entity, GENERIC_DAMAGED_LIST);

    }

}
 
Example 3
Source File: PercentHealthObjectiveModule.java    From UHC with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void on(EntityDamageEvent event) {
    final Entity entity = event.getEntity();
    if (!(entity instanceof Player)) {
        return;
    }

    final Player player = (Player) entity;

    // If the event was cancelled, another plugin may have edited the health
    // Update instantly with the current health
    if (event.isCancelled()) {
        updatePlayer(player);
        return;
    }

    // Calculate new health based on final damage instead of waiting for one tick
    final double oldHealth = player.getHealth();
    final double finalDamage = event.getFinalDamage();
    final double newHealth = Math.max(oldHealth - finalDamage, 0);

    updatePlayer(player, newHealth);
}
 
Example 4
Source File: ShieldPlayerModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
void onEvent(EntityDamageEvent event) {
  if (event.getFinalDamage() > 0) {
    // Absorbed damage is applied to the shield before any potion effect
    double shieldDamage = -event.getDamage(EntityDamageEvent.DamageModifier.ABSORPTION);
    logger.fine(
        "Absorbing damage with shield: shield=" + shieldHealth + " shieldDamage=" + shieldDamage);
    shieldHealth = Math.max(0, shieldHealth - shieldDamage);

    damage();
  }
}
 
Example 5
Source File: Berserk.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(EntityDamageEvent event) {
	if (!(event.getEntity() instanceof Player)) {
		return;
	}

	Player player = (Player) event.getEntity();

	if (!player.hasPermission("minetinker.modifiers.berserk.use")) {
		return;
	}

	ItemStack chest = player.getInventory().getChestplate();

	if (!modManager.isArmorViable(chest)) {
		return;
	}

	int modifierLevel = modManager.getModLevel(chest, this);

	if (modifierLevel <= 0) {
		return;
	}

	double lifeAfterDamage = player.getHealth() - event.getFinalDamage();
	AttributeInstance healthAttr = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);

	double maxHealth = 20;

	if (healthAttr != null) {
		maxHealth = healthAttr.getValue();
	}

	if (player.getHealth() / maxHealth > trigger / 100.0 && lifeAfterDamage / maxHealth <= trigger / 100.0) {
		player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, boostTime, modifierLevel - 1));
		ChatWriter.logModifier(player, event, this, chest,
				"Time(" + boostTime + ")", "Amplifier(" + (modifierLevel - 1) + ")");
	}
}
 
Example 6
Source File: ShieldPlayerModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
void onEvent(EntityDamageEvent event) {
    if(event.getFinalDamage() > 0) {
        // Absorbed damage is applied to the shield before any potion effect
        double shieldDamage = -event.getDamage(EntityDamageEvent.DamageModifier.ABSORPTION);
        logger.fine("Absorbing damage with shield: shield=" + shieldHealth + " shieldDamage=" + shieldDamage);
        shieldHealth = Math.max(0, shieldHealth - shieldDamage);

        damage();
    }
}
 
Example 7
Source File: Balrog.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(EntityDamageEvent event) {

    if (event.isCancelled()) return;
    if (!balrogList.contains(event.getEntity())) return;
    if (event.getFinalDamage() < 2) return;

    spawnTrashMobs((Silverfish) event.getEntity());
    spawnTrashMobs((Silverfish) event.getEntity());

}
 
Example 8
Source File: DieObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onLastDamage(EntityDamageEvent event) {
    if (!cancel) {
        return;
    }
    if (event.getEntity() instanceof Player) {
        final Player player = (Player) event.getEntity();
        final String playerID = PlayerConverter.getID(player);
        if (containsPlayer(playerID) && player.getHealth() - event.getFinalDamage() <= 0
                && checkConditions(playerID)) {
            event.setCancelled(true);
            player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
            player.setFoodLevel(20);
            player.setExhaustion(4);
            player.setSaturation(20);
            for (PotionEffect effect : player.getActivePotionEffects()) {
                player.removePotionEffect(effect.getType());
            }
            if (location != null) {
                try {
                    player.teleport(location.getLocation(playerID));
                } catch (QuestRuntimeException e) {
                    LogUtils.getLogger().log(Level.SEVERE, "Couldn't execute onLastDamage in DieObjective");
                    LogUtils.logThrowable(e);
                }
            }
            new BukkitRunnable() {
                @Override
                public void run() {
                    player.setFireTicks(0);

                }
            }.runTaskLater(BetonQuest.getInstance(), 1);
            completeObjective(playerID);
        }
    }
}
 
Example 9
Source File: TitleRespawn.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
    if (!(event.getEntity() instanceof Player)) return;
    Player player = (Player) event.getEntity();
    double finalHealth = player.getHealth() - event.getFinalDamage();
    if (finalHealth > 0.01) return;
    player.setMaxHealth(20);
    player.setHealth(player.getMaxHealth());
    event.setDamage(1);
    player.setLastDamageCause(event);
    killPlayer(player, null, event.getCause());
}
 
Example 10
Source File: HealthUtils.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public static double getFinalDamage(final EntityDamageEvent e) {
	return e.getFinalDamage() / 2;
}