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

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent#getDamage() . 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: SlimefunBootsListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void stomp(EntityDamageEvent e) {
    Player p = (Player) e.getEntity();
    p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F);
    p.setVelocity(new Vector(0.0, 0.7, 0.0));

    for (Entity n : p.getNearbyEntities(4, 4, 4)) {
        if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) {
            Vector velocity = n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4);
            n.setVelocity(velocity);

            if (!(n instanceof Player) || (p.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, n.getLocation(), ProtectableAction.PVP))) {
                EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, e.getDamage() / 2);
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) ((LivingEntity) n).damage(e.getDamage() / 2);
            }
        }
    }

    for (BlockFace face : BlockFace.values()) {
        Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face);
        p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
    }
}
 
Example 2
Source File: DamageTakenListener.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(final EntityDamageEvent event) {

    final PlayerStat stat = PlayerStat.DAMAGE_TAKEN;

    if (!(event.getEntity() instanceof Player)) {
        // It was not a player that got damage
        return;
    }

    // Get player
    final Player player = (Player) event.getEntity();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    PlayerStatSpecification specification = new DamageTakenSpecification(player.getUniqueId(), event.getDamage(),
            player.getWorld().getName(), event.getCause().toString());

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

}
 
Example 3
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 4
Source File: KineticPlating.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void effect(EntityDamageEvent event) {
	if (!(event.getEntity() instanceof Player)) return;
	if (event.getCause() != EntityDamageEvent.DamageCause.FLY_INTO_WALL) return;

	Player player = (Player) event.getEntity();
	if (!player.hasPermission("minetinker.modifiers.kineticplating.use")) return;
	ItemStack elytra = player.getInventory().getChestplate();

	if (!modManager.hasMod(elytra, this)) return;

	int level = modManager.getModLevel(elytra, this);
	double damageMod = 1.0 - (this.amount * level);
	if (damageMod < 0.0) damageMod = 0.0;
	double oldDamage = event.getDamage();
	double newDamage = oldDamage * damageMod;
	event.setDamage(newDamage);
	ChatWriter.logModifier(player, event, this, elytra, String.format("Damage(%.2f -> %.2f [x%.2f])", oldDamage, newDamage, damageMod));
}
 
Example 5
Source File: BloodMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
    if(event.getEntity() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Location location = victim.getBoundingBox().center().toLocation(match.getWorld());
        if(event.getDamage() > 0 && location.getY() >= 0 && !victim.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
            EntityUtils.entities(match.getWorld(), Player.class)
                 .filter(player -> settings.getManager(player).getValue(Settings.BLOOD, Boolean.class, false))
                 .forEach(player -> {
                     if(event instanceof EntityDamageByEntityEvent) {
                         player.playEffect(location, Effect.STEP_SOUND, Material.REDSTONE_WIRE);
                     } else {
                         player.playEffect(location, Effect.STEP_SOUND, Material.LAVA);
                     }
                 });
        }
    }
}
 
Example 6
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageEvent event) {
    if(event.getDamage() <= 0) return;

    if(!(event.getEntity() instanceof Player)) return;
    Player player = (Player) event.getEntity();

    if(player.getGameMode() == GameMode.CREATIVE) return;

    if(player.isDead()) return;

    if(player.getNoDamageTicks() > 0) return;

    if(getResistanceFactor(player) <= 0) return;

    switch(event.getCause()) {
        case ENTITY_EXPLOSION:
        case BLOCK_EXPLOSION:
        case CUSTOM:
        case FALL:
        case FALLING_BLOCK:
        case LIGHTNING:
        case MELTING:
        case SUICIDE:
        case THORNS:
            return; // Skip damage causes that are not particularly likely to be followed by more damage

        case FIRE:
        case FIRE_TICK:
        case LAVA:
            if(hasFireResistance(player)) return;
            break;
    }

    // Record the player's damage with a timestamp
    this.recentDamage.put(player, new Damage(Instant.now(), event));
}
 
Example 7
Source File: SpellListener.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onListenerDamage(EntityDamageEvent event) {
    if (!ConfigManager.getInstance().getUseClassesAndSpells() || event.isCancelled() ||
            event.getDamage() < 1 || !(event.getEntity() instanceof LivingEntity)) {
        return;
    }
    LivingEntity livingEntity = (LivingEntity) event.getEntity();
    if (!damageListeners.containsKey(livingEntity)) {
        return;
    }
    AbilityListen abilityListener = damageListeners.get(livingEntity);
    if (abilityListener.spell.useAbilityFromListener(abilityListener.getCaster(), abilityListener.getLevel(), abilityListener.getConfig(), event.getEntity())) {
        event.setCancelled(true);
    }
}
 
Example 8
Source File: BestPvEListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.HIGHEST)
public void onPlayerDamage(EntityDamageEvent e){
    if (e.isCancelled()){
        return;
    }

    if (e.getDamage() < 0.2){
        return;
    }

    if (!(e.getEntity() instanceof Player)){
        return;
    }

    Player p = (Player) e.getEntity();
    UhcPlayer uhcPlayer = GameManager.getGameManager().getPlayersManager().getUhcPlayer(p);

    if (!pveList.containsKey(uhcPlayer)){
        return; // Only playing players on list
    }

    if (pveList.get(uhcPlayer)) {
        pveList.put(uhcPlayer, false);
        uhcPlayer.sendMessage(Lang.SCENARIO_BESTPVE_REMOVED);
    }

    if (p.getMaxHealth() > maxHealth){
        double hp = p.getHealth();

        if (hp < maxHealth){
            p.setMaxHealth(maxHealth);
        }else{
            p.setMaxHealth(hp + 1);
        }
    }
}
 
Example 9
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 10
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 11
Source File: Nightseeker.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
private void effect(Event e, EntityDamageEvent event, ItemStack tool, Player player) {
	if (!player.hasPermission("minetinker.modifiers.nightseeker.use")) {
		return;
	}

	int level = modManager.getModLevel(tool, this);
	if (level <= 0) return;

	final double damageMultiplier = Math.pow(this.damageMultiplierPerLevel + 1.0, level) - 1.0;
	long worldtime = player.getWorld().getTime() / 1000;
	double daytimeMultiplier;
	if (player.getWorld().getEnvironment() == World.Environment.NORMAL) {
		if (worldtime < 12) { //value range: -1.0 - 1.0
			daytimeMultiplier = -(6 - Math.abs(6 - worldtime)) / 6.0;
		} else {
			daytimeMultiplier = (6 - Math.abs(18 - worldtime)) / 6.0;
		}
	} else if (player.getWorld().getEnvironment() == World.Environment.NETHER) {
		daytimeMultiplier = -1.0;
	} else if (player.getWorld().getEnvironment() == World.Environment.THE_END) {
		daytimeMultiplier = 1.0;
	} else return;
	final double oldDamage = event.getDamage();

	double multi = (1.0 + damageMultiplier * daytimeMultiplier);
	if (multi < 0.0) multi = 0.0;
	String damagemultiplier = String.format("DamageMultiplier(%.2f * %.2f = %.2f)", damageMultiplier, daytimeMultiplier, damageMultiplier * daytimeMultiplier);
	if (modManager.isToolViable(tool)) { //Player attacked
		event.setDamage(oldDamage * multi);
		ChatWriter.logModifier(player, e, this, tool, damagemultiplier,
				String.format("Damage(%.2f -> %.2f [x%.2f])", oldDamage, event.getDamage(), multi));
	} else if (modManager.isArmorViable(tool)) { //Player got attacked
		if (multi == 0.0) multi = 0.00001;
		event.setDamage(oldDamage / multi);
		ChatWriter.logModifier(player, e, this, tool, damagemultiplier,
				String.format("Damage(%.2f -> %.2f [/%.2f])", oldDamage, event.getDamage(), multi));
	}
}
 
Example 12
Source File: Poisonous.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
	if (event.getCause() != EntityDamageEvent.DamageCause.POISON) return;
	if (!(event.getEntity() instanceof Player)) return;
	if (!this.effectHealsPlayer) return;

	Player player = (Player) event.getEntity();
	if (!player.hasPermission("minetinker.modifiers.poisonous.use")) {
		return;
	}

	boolean hasPoisonous = false;
	ItemStack armor = null;
	for (ItemStack stack : player.getInventory().getArmorContents()) {
		if (stack == null) continue;
		if (modManager.hasMod(stack, this)) {
			hasPoisonous = true;
			armor = stack;
			break;
		}
	}

	if (!hasPoisonous) return;

	double damage = event.getDamage();
	if (damage > 0) {
		event.setDamage(0);
		double health = player.getHealth();
		player.setHealth(Math.min(health + damage, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
		ChatWriter.logModifier(player, event, this, armor, String.format("Health(%.2f -> %.2f)", health, player.getHealth()));
	}
}
 
Example 13
Source File: Sunblazer.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
private void effect(Event e, EntityDamageEvent event, ItemStack tool, Player player) {
	if (!player.hasPermission("minetinker.modifiers.sunblazer.use")) {
		return;
	}

	int level = modManager.getModLevel(tool, this);
	if (level <= 0) return;

	final double damageMultiplier = Math.pow(this.damageMultiplierPerLevel + 1.0, level) - 1.0;
	long worldtime = player.getWorld().getTime() / 1000;
	double daytimeMultiplier;
	if (player.getWorld().getEnvironment() == World.Environment.NORMAL) {
		if (worldtime >= 12) { //value range: -1.0 - 1.0
			daytimeMultiplier = -(6 - Math.abs(18 - worldtime)) / 6.0;
		} else {
			daytimeMultiplier = (6 - Math.abs(6 - worldtime)) / 6.0;
		}
	} else if (player.getWorld().getEnvironment() == World.Environment.NETHER) {
		daytimeMultiplier = 1.0;
	} else if (player.getWorld().getEnvironment() == World.Environment.THE_END) {
		daytimeMultiplier = -1.0;
	} else return;

	final double oldDamage = event.getDamage();

	double multi = (1.0 + damageMultiplier * daytimeMultiplier);
	if (multi < 0.0) multi = 0.0;
	String damagemultiplier = String.format("DamageMultiplier(%.2f * %.2f = %.2f)", damageMultiplier, daytimeMultiplier, damageMultiplier * daytimeMultiplier);
	if (modManager.isToolViable(tool)) { //Player attacked
		event.setDamage(oldDamage * multi);
		ChatWriter.logModifier(player, e, this, tool, damagemultiplier,
				String.format("Damage(%.2f -> %.2f [x%.2f])", oldDamage, event.getDamage(), multi));
	} else if (modManager.isArmorViable(tool)) { //Player got attacked
		if (multi == 0.0) multi = 0.00001;
		event.setDamage(oldDamage / multi);
		ChatWriter.logModifier(player, e, this, tool, damagemultiplier,
				String.format("Damage(%.2f -> %.2f [/%.2f])", oldDamage, event.getDamage(), multi));
	}
}
 
Example 14
Source File: Withered.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
	if (event.getCause() != EntityDamageEvent.DamageCause.WITHER) return;
	if (!(event.getEntity() instanceof Player)) return;
	if (!this.effectHealsPlayer) return;

	Player player = (Player) event.getEntity();
	if (!player.hasPermission("minetinker.modifiers.withered.use")) {
		return;
	}

	boolean hasWither = false;
	ItemStack armor = null;
	for (ItemStack stack : player.getInventory().getArmorContents()) {
		if (stack == null) continue;
		if (modManager.hasMod(stack, this)) {
			hasWither = true;
			armor = stack;
			break;
		}
	}

	if (!hasWither) return;

	double damage = event.getDamage();
	if (damage > 0) {
		event.setDamage(0);
		double health = player.getHealth();
		player.setHealth(Math.min(health + damage, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
		ChatWriter.logModifier(player, event, this, armor, String.format("Health(%.2f -> %.2f)", health, player.getHealth()));
	}
}
 
Example 15
Source File: CombatLogTracker.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageEvent event) {
  if (event.getDamage() <= 0) return;

  if (!(event.getEntity() instanceof Player)) return;
  Player player = (Player) event.getEntity();

  if (player.getGameMode() == GameMode.CREATIVE) return;

  if (player.isDead()) return;

  if (player.getNoDamageTicks() > 0) return;

  if (getResistanceFactor(player) <= 0) return;

  switch (event.getCause()) {
    case ENTITY_EXPLOSION:
    case BLOCK_EXPLOSION:
    case CUSTOM:
    case FALL:
    case FALLING_BLOCK:
    case LIGHTNING:
    case MELTING:
    case SUICIDE:
    case THORNS:
      return; // Skip damage causes that are not particularly likely to be followed by more damage

    case FIRE:
    case FIRE_TICK:
    case LAVA:
      if (hasFireResistance(player)) return;
      break;
  }

  // Record the player's damage with a timestamp
  this.recentDamage.put(player, new Damage(Instant.now(), event));
}
 
Example 16
Source File: SharedHealthListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler (priority = EventPriority.HIGH)
public void onPlayerDamage(EntityDamageEvent e){
    // Check if entity is player
    if (e.getEntityType() != EntityType.PLAYER){
        return;
    }

    if (e.isCancelled()){
        return;
    }

    // Check if GameState is Playing | Deathmatch
    GameState state = getGameManager().getGameState();
    if (state != GameState.PLAYING && state != GameState.DEATHMATCH){
        return;
    }

    UhcPlayer uhcPlayer = getPlayersManager().getUhcPlayer((Player) e.getEntity());

    // Check if player is playing
    if (uhcPlayer.getState() != PlayerState.PLAYING){
        return;
    }

    // If solo player don't share damage
    List<UhcPlayer> onlinePlayingMembers = uhcPlayer.getTeam().getOnlinePlayingMembers();
    if (onlinePlayingMembers.size() <= 1){
        return;
    }

    double damage = e.getDamage()/onlinePlayingMembers.size();
    e.setDamage(damage);

    for (UhcPlayer uhcMember : onlinePlayingMembers){
        if (uhcMember == uhcPlayer){
            continue;
        }

        try {
            uhcMember.getPlayer().damage(damage);
        }catch (UhcPlayerNotOnlineException ex){
            ex.printStackTrace();
        }
    }
}
 
Example 17
Source File: HealthUtils.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public static double getDamage(final EntityDamageEvent e) {
	return e.getDamage() / 2;
}
 
Example 18
Source File: DamageDisplay.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onHit(EntityDamageEvent event) {

    if (event.isCancelled()) return;

    if (!(event.getEntity() instanceof LivingEntity) || event.getEntity() instanceof ArmorStand) return;

    if (ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.ONLY_SHOW_DAMAGE_FOR_ELITE_MOBS)) {

        if (EntityTracker.isEliteMob(event.getEntity()) && event.getEntity() instanceof LivingEntity) {
            if (event.getDamage() > 0) displayDamage(event.getEntity(), event.getFinalDamage());
        } else if (EntityTracker.isSuperMob(event.getEntity()))
            displayDamage(event.getEntity(), event.getFinalDamage());

    } else {

        if (event.getDamage() > 0) displayDamage(event.getEntity(), event.getFinalDamage());

    }

}