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

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent#setDamage() . 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: 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 2
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 3
Source File: Thor.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority= EventPriority.NORMAL)
public void checkStrike(EntityDamageEvent event)
{
	if(event.getEntityType() == EntityType.PLAYER && event.getCause() == DamageCause.LIGHTNING)
	{
		AnniPlayer player = AnniPlayer.getPlayer(event.getEntity().getUniqueId());
		if(player != null && !player.getKit().equals(this))
		{
			Object obj = player.getData("LH");
			if(obj != null)
			{
				Long l = (Long)obj;
				if(System.currentTimeMillis()-l <= 30000)
				{
					event.setCancelled(true);
					player.setData("LH", null);
					return;
				}
			}
			event.setDamage(4);
			player.setData("LH", System.currentTimeMillis());
		}
	}
}
 
Example 4
Source File: SentinelTrait.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Called when this sentinel gets hurt.
 */
public void whenImHurt(EntityDamageEvent event) {
    if (SentinelPlugin.debugMe) {
        debug("I'm hurt! By " + event.getCause().name() + " for " + event.getFinalDamage() + " hp");
    }
    switch (event.getCause()) {
        case FIRE:
        case FIRE_TICK:
        case LAVA:
        case MELTING:
            if (ticksSinceLastBurn <= 20) {
                event.setDamage(0);
                event.setCancelled(true);
                return;
            }
            ticksSinceLastBurn = 0;
            break;
    }
}
 
Example 5
Source File: EntityListener.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onDamage(EntityDamageEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.getEntity().setFireTicks(0);
        event.setDamage(0);
        event.setCancelled(true);
    }
}
 
Example 6
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 7
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 8
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onSpawnDamage(final EntityDamageEvent event) {
    if (!plugin.getWorldManager().isSkyWorld(event.getEntity().getWorld())) {
        return;
    }
    if (event.getEntity() instanceof Player && plugin.playerIsInSpawn((Player) event.getEntity()) && event.getCause() == EntityDamageEvent.DamageCause.VOID) {
        event.setDamage(-event.getDamage());
        event.setCancelled(true);
        plugin.getTeleportLogic().spawnTeleport((Player) event.getEntity(), true);
    }
}
 
Example 9
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onVisitorDamage(final EntityDamageEvent event) {
    // Only protect things in the Skyworld.
    if (!plugin.getWorldManager().isSkyWorld(event.getEntity().getWorld())) {
        return;
    }

    // Only protect visitors against damage if pvp is disabled:
    if (Settings.island_allowPvP) {
        return;
    }

    // This protection only applies to players:
    if (!(event.getEntity() instanceof Player)) {
        return;
    }

    // Don't protect players on their own islands:
    if (plugin.playerIsOnIsland((Player) event.getEntity())) {
        return;
    }

    if ((visitorFireProtected && FIRE_TRAP.contains(event.getCause()))
            || (visitorFallProtected && (event.getCause() == EntityDamageEvent.DamageCause.FALL))
            || (visitorMonsterProtected &&
                (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK
                || event.getCause() == EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK
                || event.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION
                || event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE
                || event.getCause() == EntityDamageEvent.DamageCause.MAGIC
                || event.getCause() == EntityDamageEvent.DamageCause.POISON))) {
        event.setDamage(-event.getDamage());
        event.setCancelled(true);
    }
}
 
Example 10
Source File: CombatSystem.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void eliteMobDamageGeneric(EntityDamageEvent event) {

    if (event.isCancelled()) return;
    if (!(event.getEntity() instanceof LivingEntity)) return;
    if (!EntityTracker.isEliteMob(event.getEntity())) return;
    if (event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK)) return;
    if (!event.getCause().equals(EntityDamageEvent.DamageCause.CUSTOM))
        event.setDamage(EntityDamageEvent.DamageModifier.BASE, event.getDamage());

}
 
Example 11
Source File: Scout.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void fallDamage(EntityDamageEvent event)
{
	if(event.getEntity().getType() == EntityType.PLAYER && event.getCause() == DamageCause.FALL)
	{
		Player p = (Player)event.getEntity();
		AnniPlayer pl = AnniPlayer.getPlayer(p.getUniqueId());
		if(pl != null && pl.getKit().equals(this))
		{
			event.setDamage(event.getDamage()/2);
		}
	}
}
 
Example 12
Source File: MeleeSymptom.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onAttack(EntityDamageEvent event) {
    super.onAttack(event);

    if(event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) {
        event.setDamage(modifier.apply(event.getDamage()));
    }
}
 
Example 13
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 14
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 15
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 16
Source File: HealthUtils.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public static void setDamage(final EntityDamageEvent e, final double damage) {
	e.setDamage(damage * 2);
}
 
Example 17
Source File: PreventCreeperPassiveEntityDamage.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void superCreeperCollateralDamageAvoider(EntityDamageEvent event) {

    if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {

        if (SuperMobProperties.isValidSuperMobType(event.getEntityType()) ||
                event.getEntity() instanceof Horse || event.getEntity() instanceof Villager ||
                event.getEntity() instanceof Bat || event.getEntity() instanceof ArmorStand ||
                event.getEntity() instanceof Rabbit) {

            event.setDamage(0);

        }

    }

}
 
Example 18
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();
        }
    }
}