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

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent#isCancelled() . 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: WarpPowderListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamage(EntityDamageEvent event) {
    if (event.isCancelled() || !(event.getEntity() instanceof Player)) {
        return;
    }

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

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();

    if (gPlayer.isSpectator) {
        return;
    }

    WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class);
    if (warpPowder != null) {
        warpPowder.cancelTeleport(true, true);
    }
}
 
Example 2
Source File: MagnetShoesListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamage(EntityDamageEvent event) {
    if (event.isCancelled() || !(event.getEntity() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getEntity();
    if (Main.isPlayerInGame(player)) {
        ItemStack boots = player.getInventory().getBoots();
        if (boots != null) {
            String magnetShoes = APIUtils.unhashFromInvisibleStringStartsWith(boots, MAGNET_SHOES_PREFIX);
            if (magnetShoes != null) {
                int probability = Integer.parseInt(magnetShoes.split(":")[2]);
                int randInt = MiscUtils.randInt(0, 100);
                if (randInt <= probability) {
                    event.setCancelled(true);
                    player.damage(event.getDamage());
                }
            }
        }
    }
}
 
Example 3
Source File: WarpPowderListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamage(EntityDamageEvent event) {
    if (event.isCancelled() || !(event.getEntity() instanceof Player)) {
        return;
    }

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

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();

    if (gPlayer.isSpectator) {
        return;
    }

    WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class);
    if (warpPowder != null) {
        warpPowder.cancelTeleport(true, true);
    }
}
 
Example 4
Source File: MagnetShoesListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamage(EntityDamageEvent event) {
    if (event.isCancelled() || !(event.getEntity() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getEntity();
    if (Main.isPlayerInGame(player)) {
        ItemStack boots = player.getInventory().getBoots();
        if (boots != null) {
            String magnetShoes = APIUtils.unhashFromInvisibleStringStartsWith(boots, MAGNET_SHOES_PREFIX);
            if (magnetShoes != null) {
                int probability = Integer.parseInt(magnetShoes.split(":")[2]);
                int randInt = MiscUtils.randInt(0, 100);
                if (randInt <= probability) {
                    event.setCancelled(true);
                    player.damage(event.getDamage());
                }
            }
        }
    }
}
 
Example 5
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 6
Source File: NoCleanListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerDamage(EntityDamageEvent e){

    if (e.getEntityType() != EntityType.PLAYER || e.isCancelled()){
        return;
    }

    if (
            e.getCause() != EntityDamageEvent.DamageCause.FIRE &&
            e.getCause() != EntityDamageEvent.DamageCause.LAVA &&
            e.getCause() != EntityDamageEvent.DamageCause.FIRE_TICK){
        return;
    }

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

    if (pvpCooldown.containsKey(player.getUniqueId())){
        if (pvpCooldown.get(player.getUniqueId()) > System.currentTimeMillis()){
            e.setCancelled(true);
        }
    }
}
 
Example 7
Source File: HealthDisplay.java    From EliteMobs with GNU General Public License v3.0 6 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_HEALTH_FOR_ELITE_MOBS)) {
        if (EntityTracker.isEliteMob(event.getEntity()))
            displayHealth((LivingEntity) event.getEntity(), event.getFinalDamage());
        else if (EntityTracker.isSuperMob(event.getEntity()))
            displayHealth((LivingEntity) event.getEntity(), event.getFinalDamage());

    } else
        displayHealth((LivingEntity) event.getEntity(), event.getFinalDamage());

}
 
Example 8
Source File: EntityDamage.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
	if (event.isCancelled())
		return;

	DamageCause cause = event.getCause();
	Entity damagee = event.getEntity();
	EntityType damageeType = damagee.getType();
	// PlayerCustomArmorDamageEvent
	if (damageeType == EntityType.PLAYER) {
		Player player = (Player) damagee;
		PlayerInventory inv = player.getInventory();
		for (ItemStack armor : inv.getArmorContents())
			// TODO: Speed up
			if (armor != null && armor.getType() != Material.AIR && AdditionsAPI.isCustomItem(armor)
					&& new CustomItemStack(armor).getCustomItem() instanceof CustomArmor
					&& new CustomItemStack(armor).getCustomItem()
							.getDurabilityMechanics() instanceof ArmorDurability) {
				CustomArmor cArmor = (CustomArmor) new CustomItemStack(armor).getCustomItem();
				Bukkit.getServer().getPluginManager().callEvent(new PlayerCustomArmorDamageEvent(player, armor,
						cArmor, cause, (float) event.getDamage(), armor.containsEnchantment(Enchantment.THORNS)));
			}
	}
}
 
Example 9
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 10
Source File: Kraken.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onSuffocate(EntityDamageEvent event) {

    if (event.isCancelled()) return;
    if (!event.getEntity().getType().equals(EntityType.SQUID)) return;
    if (!isKraken((Squid) event.getEntity())) return;
    if (!event.getCause().equals(EntityDamageEvent.DamageCause.DROWNING) &&
            !event.getCause().equals(EntityDamageEvent.DamageCause.FIRE)) return;

    event.setCancelled(true);

}
 
Example 11
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 12
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 13
Source File: HealthUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/** Apply damage to an entity
 * @param e Entity to apply damage to
 * @param d Amount of hearts to damage
 */
public static void damage(final Damageable e, final double d) {
	if (d < 0) {
		heal(e, -d);
		return;
	}
	EntityDamageEvent event = new EntityDamageEvent(e, DamageCause.CUSTOM, d * 2);
	Bukkit.getPluginManager().callEvent(event);
	if (event.isCancelled()) return;
	e.damage(event.getDamage());
}
 
Example 14
Source File: RescuePlatformListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onFallDamage(EntityDamageEvent event) {
    Entity entity = event.getEntity();
    if (event.isCancelled() || !(entity instanceof Player)) {
        return;
    }

    Player player = ((Player) entity).getPlayer();
    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();
    if (gPlayer.isSpectator) {
        return;
    }

    RescuePlatform rescuePlatform = (RescuePlatform) game.getFirstActivedSpecialItemOfPlayer(player, RescuePlatform.class);
    if (rescuePlatform != null && event.getCause() == EntityDamageEvent.DamageCause.FALL) {
        Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
        if (block != null) {
            if (block.getType() == rescuePlatform.getMaterial()) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 15
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 16
Source File: RescuePlatformListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onFallDamage(EntityDamageEvent event) {
    Entity entity = event.getEntity();
    if (event.isCancelled() || !(entity instanceof Player)) {
        return;
    }

    Player player = ((Player) entity).getPlayer();
    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();
    if (gPlayer.isSpectator) {
        return;
    }

    RescuePlatform rescuePlatform = (RescuePlatform) game.getFirstActivedSpecialItemOfPlayer(player, RescuePlatform.class);
    if (rescuePlatform != null && event.getCause() == EntityDamageEvent.DamageCause.FALL) {
        Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
        if (block != null) {
            if (block.getType() == rescuePlatform.getMaterial()) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 17
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());

    }

}
 
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();
        }
    }
}
 
Example 19
Source File: WarpPowderListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onDamage(EntityDamageEvent dmg) {
  if (dmg.isCancelled()) {
    return;
  }

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

  Player player = (Player) dmg.getEntity();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  if (game.isSpectator(player)) {
    return;
  }

  WarpPowder powder = null;
  for (SpecialItem item : game.getSpecialItems()) {
    if (!(item instanceof WarpPowder)) {
      continue;
    }

    powder = (WarpPowder) item;
    if (!powder.getPlayer().equals(player)) {
      powder = null;
      continue;
    }
    break;
  }

  if (powder != null) {
    powder.cancelTeleport(true, true);
    return;
  }
}
 
Example 20
Source File: EventValidator.java    From EliteMobs with GNU General Public License v3.0 3 votes vote down vote up
public static EliteMobEntity getEventEliteMob(ElitePower mobPower, EntityDamageEvent event) {

        if (event.isCancelled()) return null;

        if (!(event.getEntity() instanceof LivingEntity)) return null;

        EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity());

        if (eliteMobEntity == null) return null;

        if (!EntityTracker.hasPower(mobPower, eliteMobEntity)) return null;

        return eliteMobEntity;

    }