Java Code Examples for org.bukkit.event.entity.EntityDamageEvent#getEntity()
The following examples show how to use
org.bukkit.event.entity.EntityDamageEvent#getEntity() .
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 |
@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: MagnetShoesListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@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: Taunt.java From EliteMobs with GNU General Public License v3.0 | 6 votes |
@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 4
Source File: FlagAnvilSpleef.java From HeavySpleef with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = false) public void onEntityDamage(EntityDamageEvent e) { if (e.getCause() != DamageCause.FALLING_BLOCK) { return; } Entity damaged = e.getEntity(); if (!(damaged instanceof Player)) { return; } SpleefPlayer player = getHeavySpleef().getSpleefPlayer(damaged); if (!game.isIngame(player)) { return; } e.setCancelled(false); }
Example 5
Source File: LivingEntityShopListener.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) void onEntityDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); // block damaging of shopkeepers if (plugin.isShopkeeper(entity)) { event.setCancelled(true); if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent evt = (EntityDamageByEntityEvent) event; if (evt.getDamager() instanceof Monster) { Monster monster = (Monster) evt.getDamager(); // reset target, future targeting should get prevented somewhere else: if (entity.equals(monster.getTarget())) { monster.setTarget(null); } } } } }
Example 6
Source File: NoCleanListener.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@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: ListenerFlight.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true) public void onDamage(EntityDamageEvent e) { EntityDamageEvent.DamageCause cause = e.getCause(); if(cause != EntityDamageEvent.DamageCause.FALL) return; FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); if(!config.getBoolean("flight.prevent-fall-damage")) return; Entity entity = e.getEntity(); if(!(entity instanceof Player)) return; Player player = (Player) entity; UUID uuid = player.getUniqueId(); if(!this.preventFallDamage.contains(uuid)) return; e.setCancelled(true); this.preventFallDamage.remove(uuid); }
Example 8
Source File: JoinRequester.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof Player)) { return; } SpleefPlayer player = heavySpleef.getSpleefPlayer(entity); if (!checking.containsKey(player)) { return; } handleFail(player, FailCause.DAMAGE, null); }
Example 9
Source File: TitleRespawn.java From CardinalPGM with MIT License | 5 votes |
@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: Withered.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@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 11
Source File: TalismanListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onDamageGet(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { if (e.getCause() == DamageCause.LAVA) { Talisman.checkFor(e, SlimefunItems.TALISMAN_LAVA); } if (e.getCause() == DamageCause.DROWNING) { Talisman.checkFor(e, SlimefunItems.TALISMAN_WATER); } if (e.getCause() == DamageCause.FALL) { Talisman.checkFor(e, SlimefunItems.TALISMAN_ANGEL); } if (e.getCause() == DamageCause.FIRE) { Talisman.checkFor(e, SlimefunItems.TALISMAN_FIRE); } if (e.getCause() == DamageCause.ENTITY_ATTACK) { Talisman.checkFor(e, SlimefunItems.TALISMAN_KNIGHT); Talisman.checkFor(e, SlimefunItems.TALISMAN_WARRIOR); } if (e.getCause() == DamageCause.PROJECTILE && ((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) { Projectile projectile = (Projectile) ((EntityDamageByEntityEvent) e).getDamager(); if (Talisman.checkFor(e, SlimefunItems.TALISMAN_WHIRLWIND)) { returnProjectile((Player) e.getEntity(), projectile); } } } }
Example 12
Source File: DieObjective.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@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 13
Source File: ArrowBlockerListener.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent ev) { if (!ev.getCause().equals(DamageCause.PROJECTILE)) { return; } if (!ev.getEntityType().equals(EntityType.PLAYER)) { return; } Player player = (Player) ev.getEntity(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (!isBlockerActive(player, game)) { return; } ev.setCancelled(true); }
Example 14
Source File: CombatSystem.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@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 15
Source File: PetOwnerListener.java From EchoPet with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerDamage(EntityDamageEvent event) { if (event.getEntity() instanceof Player) { Player p = (Player) event.getEntity(); if (event.getCause() == EntityDamageEvent.DamageCause.FALL) { IPet pet = EchoPet.getManager().getPet(p); if (pet != null && pet.isOwnerRiding()) { event.setCancelled(true); } } } }
Example 16
Source File: NoFallListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDamage(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { if (e.getCause().equals(EntityDamageEvent.DamageCause.FALL)) { e.setCancelled(true); } } }
Example 17
Source File: DamageDisplay.java From EliteMobs with GNU General Public License v3.0 | 4 votes |
@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: ViewInventoryMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void updateMonitoredDamage(final EntityDamageEvent event) { if(event.getEntity() instanceof Player) { this.scheduleCheck((Player) event.getEntity()); } }
Example 19
Source File: ObserverModule.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onViewingEntityDamage(EntityDamageEvent event) { if (event.getEntity() instanceof Player) { refreshView(event.getEntity().getUniqueId()); } }
Example 20
Source File: WarpPowderListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@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; } }