org.bukkit.event.entity.EntityDamageEvent.DamageCause Java Examples
The following examples show how to use
org.bukkit.event.entity.EntityDamageEvent.DamageCause.
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 |
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: DisableDamageModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
public static DisableDamageModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException { SetMultimap<DamageCause, PlayerRelation> causes = HashMultimap.create(); for(Element damageCauseElement : doc.getRootElement().getChildren("disabledamage")) { for(Element damageEl : damageCauseElement.getChildren("damage")) { DamageCause cause = XMLUtils.parseEnum(damageEl, DamageCause.class, "damage type"); for(PlayerRelation damagerType : PlayerRelation.values()) { // Legacy syntax used "other" instead of "neutral" String attrName = damagerType.name().toLowerCase(); Node attr = damagerType == PlayerRelation.NEUTRAL ? Node.fromAttr(damageEl, attrName, "other") : Node.fromAttr(damageEl, attrName); if(XMLUtils.parseBoolean(attr, true)) { causes.put(cause, damagerType); // Bukkit 1.7.10 changed TNT from BLOCK_EXPLOSION to ENTITY_EXPLOSION, // so we include them both to keep old maps working. if(cause == DamageCause.BLOCK_EXPLOSION) { causes.put(DamageCause.ENTITY_EXPLOSION, damagerType); } } } } } return new DisableDamageModule(causes); }
Example #3
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 6 votes |
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) { EntityDamageEvent event; if (damager != null) { event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions); } else { event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions); } callEvent(event); if (!event.isCancelled()) { event.getEntity().setLastDamageCause(event); } return event; }
Example #4
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void onEntityDamage(EntityDamageEvent e) { if (e instanceof EntityDamageByEntityEvent && !(e.getCause() == DamageCause.BLOCK_EXPLOSION || e.getCause() == DamageCause.ENTITY_EXPLOSION)) return; Entity entity = e.getEntity(); if (plugin.getLWC().isProtectable(e.getEntity().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); if (protection != null) { if (e.getCause() != DamageCause.CONTACT) e.setCancelled(true); } } }
Example #5
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 #6
Source File: ArmorDurability.java From AdditionsAPI with MIT License | 6 votes |
/** * Calculates the damage that the armor will take for the specified damage. * This is according to the Vanilla Minecraft code, which divides the damage * by 4, increases it to at least 1 if it was less, and rounds it to an int. * There are also extra checks to prevent an armor piece to be damaged by a * forbidden {@link DamageCause} as well as calculations for adding extra * damage if the armor piece had Thorns. */ public int getArmorDamage(DamageCause cause, float damage, boolean hadThorns) { if (!damageCausesWithDurability.contains(cause)) return 0; damage = damage / 4.0F; if (damage < 1.0F) { damage = 1.0F; } if (hadThorns) return thornsExtraDamage + (int) damage; else return (int) damage; }
Example #7
Source File: EntityDamage.java From AdditionsAPI with MIT License | 6 votes |
@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 #8
Source File: DisableDamage.java From CardinalPGM with MIT License | 6 votes |
@EventHandler public void onEntityDamage(EntityDamageEvent event) { if (damageTypes.contains(event.getCause()) && (event.getCause() != DamageCause.BLOCK_EXPLOSION || event.getCause() != DamageCause.ENTITY_EXPLOSION)) { event.setCancelled(true); } else if (event.getCause() == DamageCause.BLOCK_EXPLOSION || event.getCause() == DamageCause.ENTITY_EXPLOSION) { if (event instanceof EntityDamageByEntityEvent) { if (event.getEntity() instanceof Player && TntTracker.getWhoPlaced(((EntityDamageByEntityEvent) event).getDamager()) != null) { Player player = (Player) event.getEntity(); UUID source = TntTracker.getWhoPlaced(((EntityDamageByEntityEvent) event).getDamager()); Match match = GameHandler.getGameHandler().getMatch(); if (Bukkit.getOfflinePlayer(source).isOnline()) { if (Bukkit.getPlayer(source).equals(player)) { event.setCancelled(!blockExplosionSelf); } else if (Teams.getTeamByPlayer(Bukkit.getPlayer(source)) == Teams.getTeamByPlayer(player)) { event.setCancelled(!blockExplosionAlly); } else if (Teams.getTeamByPlayer(Bukkit.getPlayer(source)) != Teams.getTeamByPlayer(player)) { event.setCancelled(!blockExplosionEnemy); } else { event.setCancelled(!blockExplosionOther); } } } } else if (damageTypes.contains(DamageCause.BLOCK_EXPLOSION)) event.setCancelled(true); } }
Example #9
Source File: DefaultComparators.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public Relation compare(final DamageCause dc, final EntityData e) { switch (dc) { case ENTITY_ATTACK: return Relation.get(e.isSupertypeOf(EntityData.fromClass(Entity.class))); case PROJECTILE: return Relation.get(e.isSupertypeOf(EntityData.fromClass(Projectile.class))); case WITHER: return Relation.get(e.isSupertypeOf(EntityData.fromClass(Wither.class))); case FALLING_BLOCK: return Relation.get(e.isSupertypeOf(EntityData.fromClass(FallingBlock.class))); //$CASES-OMITTED$ default: return Relation.NOT_EQUAL; } }
Example #10
Source File: Thor.java From AnnihilationPro with MIT License | 6 votes |
@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 #11
Source File: CraftEventFactory.java From Thermos with GNU General Public License v3.0 | 6 votes |
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) { EntityDamageEvent event; if (damager != null) { event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions); } else { event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions); } callEvent(event); if (!event.isCancelled()) { event.getEntity().setLastDamageCause(event); } return event; }
Example #12
Source File: FeatureEmulation.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { if (((event.getCause() == DamageCause.FIRE_TICK) || (event.getCause() == DamageCause.FIRE) || (event.getCause() == DamageCause.DROWNING))) { for (Player player : ServerPlatform.get().getMiscUtils().getNearbyPlayers(event.getEntity().getLocation(), 48, 128, 48)) { if (player != null) { Connection connection = ProtocolSupportAPI.getConnection(player); if ( (connection != null) && (connection.getVersion().getProtocolType() == ProtocolType.PC) && connection.getVersion().isBefore(ProtocolVersion.MINECRAFT_1_12) ) { connection.sendPacket(ServerPlatform.get().getPacketFactory().createEntityStatusPacket(event.getEntity(), 2)); } } } } }
Example #13
Source File: SpectateListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onSpectatorDamaged(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { final Player player = (Player) e.getEntity(); final GameMap gameMap = MatchManager.get().getSpectatorMap(player); if (gameMap == null) { return; } e.setCancelled(true); if (e.getCause() == DamageCause.VOID) { World world = gameMap.getCurrentWorld(); Location spectateSpawn = new Location(world, 0, 0, 0); player.teleport(spectateSpawn); } } }
Example #14
Source File: EffHealth.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { damageables = vars[0]; if (ItemStack.class.isAssignableFrom(damageables.getReturnType())) { if (!ChangerUtils.acceptsChange(damageables, ChangeMode.SET, ItemType.class)) { Skript.error(damageables + " cannot be changed, thus it cannot be damaged or repaired."); return false; } } damage = (Expression<Number>) vars[1]; heal = (matchedPattern >= 1); if (vars.length >= 3) dmgCause = (Expression<DamageCause>) vars[2]; return true; }
Example #15
Source File: PlayerDeathListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onDeath2(final PlayerDeathEvent v2) { final GameMap gameMap = MatchManager.get().getPlayerMap(v2.getEntity()); if (gameMap == null) { return; } final Player player = v2.getEntity(); v2.getEntity().getInventory().clear(); v2.getEntity().getInventory().setArmorContents(null); DamageCause damageCause = DamageCause.CUSTOM; if (v2.getEntity().getLastDamageCause() != null) { damageCause = v2.getEntity().getLastDamageCause().getCause(); } final DamageCause dCause = damageCause; v2.setDeathMessage(""); MatchManager.get().playerLeave(player, dCause, false, true, true); }
Example #16
Source File: ArenaDamageListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerDamaged(EntityDamageEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); GameMap gameMap = MatchManager.get().getPlayerMap(player); if (gameMap != null) { if (gameMap.getMatchState() == MatchState.ENDING || gameMap.getMatchState() == MatchState.WAITINGSTART) { event.setCancelled(true); return; } if (!gameMap.allowFallDamage()) { if (event.getCause().equals(DamageCause.FALL)) { event.setCancelled(true); } } } } }
Example #17
Source File: SlimefunBootsListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
public SlimefunBootsListener(SlimefunPlugin plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); cancelledEvents.put("ENDER_BOOTS", e -> e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) e).getDamager() instanceof EnderPearl); cancelledEvents.put("BOOTS_OF_THE_STOMPER", e -> { if (e.getCause() == DamageCause.FALL) { stomp(e); return true; } return false; }); cancelledEvents.put("SLIME_BOOTS", e -> e.getCause() == DamageCause.FALL); cancelledEvents.put("SLIME_STEEL_BOOTS", e -> e.getCause() == DamageCause.FALL); }
Example #18
Source File: BlacklistCategory.java From GriefDefender with MIT License | 6 votes |
public BlacklistCategory() { for (Flag flag : FlagRegistryModule.getInstance().getAll()) { this.flagIdBlacklist.put(flag.getName().toLowerCase(), new ArrayList<>()); } this.flagIdBlacklist.put("block-pre", new ArrayList<>()); this.entityDamageSourceBlacklist.add(DamageCause.CONTACT.name().toLowerCase()); this.entityDamageSourceBlacklist.add("cramming"); this.entityDamageSourceBlacklist.add(DamageCause.DROWNING.name().toLowerCase()); this.entityDamageSourceBlacklist.add(DamageCause.FALLING_BLOCK.name().toLowerCase()); this.entityDamageSourceBlacklist.add("flyintowall"); this.entityDamageSourceBlacklist.add(DamageCause.POISON.name().toLowerCase()); this.entityDamageSourceBlacklist.add(DamageCause.STARVATION.name().toLowerCase()); this.entityDamageSourceBlacklist.add(DamageCause.SUFFOCATION.name().toLowerCase()); this.entityDamageSourceBlacklist.add(DamageCause.SUICIDE.name().toLowerCase()); this.entityDamageSourceBlacklist.add(DamageCause.VOID.name().toLowerCase()); }
Example #19
Source File: DamageParser.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public DamageCause parseDamageCause(Element el) throws InvalidXMLException { DamageCause cause = DamageCause.valueOf(el.getTextNormalize().toUpperCase().replace(" ", "_")); if (cause == null) { throw new InvalidXMLException("Invalid damage cause '" + el.getValue() + "'.", el); } return cause; }
Example #20
Source File: GrapplingHookListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onFallDamage(EntityDamageEvent e) { if (!isEnabled()) { return; } if (e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL && invulnerability.remove(e.getEntity().getUniqueId())) { e.setCancelled(true); } }
Example #21
Source File: EntityEventHandler.java From GriefDefender with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onEntityDamage(EntityDamageByBlockEvent event) { if (event.getCause() == DamageCause.SUFFOCATION || event.getCause() == DamageCause.DROWNING) { return; } GDTimings.ENTITY_DAMAGE_EVENT.startTiming(); if (protectEntity(event, event.getDamager() == null ? event.getCause() : event.getDamager(), event.getEntity())) { event.setCancelled(true); } GDTimings.ENTITY_DAMAGE_EVENT.stopTiming(); }
Example #22
Source File: SeismicAxe.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void pushEntity(Player p, Entity entity) { Vector vector = entity.getLocation().toVector().subtract(p.getLocation().toVector()).normalize(); vector.multiply(STRENGTH); vector.setY(0.9); entity.setVelocity(vector); if (entity.getType() != EntityType.PLAYER || p.getWorld().getPVP()) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, entity, DamageCause.ENTITY_ATTACK, 6D); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { ((LivingEntity) entity).damage(DAMAGE); } } }
Example #23
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 #24
Source File: DisableDamageMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private static DamageCause getBlockDamageCause(Block block) { switch (block.getType()) { case LAVA: case STATIONARY_LAVA: return DamageCause.LAVA; case FIRE: return DamageCause.FIRE; default: return DamageCause.CONTACT; } }
Example #25
Source File: DamageControl.java From AnnihilationPro with MIT License | 5 votes |
public Map<DamageCause, Long> getImmunities(UUID id) { Map<DamageCause, Long> immunities = controllers.get(id); if(immunities == null) { immunities = new HashMap<>(2); controllers.put(id,immunities); } return immunities; }
Example #26
Source File: Scout.java From AnnihilationPro with MIT License | 5 votes |
@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 #27
Source File: Assassin.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void damageHandler(EntityDamageEvent event) { if(event.getEntityType() == EntityType.PLAYER) { AnniPlayer p = AnniPlayer.getPlayer(event.getEntity().getUniqueId()); if(p != null && p.getKit().equals(this) && p.getData("Cur") != null) { if(event.getCause() == DamageCause.FALL) event.setCancelled(true); else endLeap((Player)event.getEntity(),p); } } }
Example #28
Source File: ClassesTest.java From Skript with GNU General Public License v3.0 | 5 votes |
@Test public void test() { final Object[] random = { // Java (byte) 127, (short) 2000, -1600000, 1L << 40, -1.5f, 13.37, "String", // Skript SkriptColor.BLACK, StructureType.RED_MUSHROOM, WeatherType.THUNDER, new Date(System.currentTimeMillis()), new Timespan(1337), new Time(12000), new Timeperiod(1000, 23000), new Experience(15), new Direction(0, Math.PI, 10), new Direction(new double[] {0, 1, 0}), new EntityType(new SimpleEntityData(HumanEntity.class), 300), new CreeperData(), new SimpleEntityData(Snowball.class), new HorseData(Variant.SKELETON_HORSE), new WolfData(), new XpOrbData(50), // Bukkit - simple classes only GameMode.ADVENTURE, InventoryType.CHEST, DamageCause.FALL, // there is also at least one variable for each class on my test server which are tested whenever the server shuts down. }; for (final Object o : random) { Classes.serialize(o); // includes a deserialisation test } }
Example #29
Source File: DefaultComparators.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public Relation compare(final DamageCause dc, final ItemType t) { switch (dc) { case FIRE: return Relation.get(t.isOfType(Material.LAVA)); case LAVA: return Relation.get(t.equals(lava)); case MAGIC: return Relation.get(t.isOfType(Material.POTION)); //$CASES-OMITTED$ default: return Relation.NOT_EQUAL; } }
Example #30
Source File: PlayerQuitListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerQuit(final PlayerQuitEvent a1) { final String id = a1.getPlayer().getUniqueId().toString(); Party party = Party.getParty(a1.getPlayer()); if (party != null) { party.removeMember(a1.getPlayer()); } final GameMap gameMap = MatchManager.get().getPlayerMap(a1.getPlayer()); if (gameMap == null) { new BukkitRunnable() { @Override public void run() { PlayerStat.removePlayer(id); } }.runTaskLater(SkyWarsReloaded.get(), 5); return; } MatchManager.get().playerLeave(a1.getPlayer(), DamageCause.CUSTOM, true, true, true); if (PlayerStat.getPlayerStats(id) != null) { new BukkitRunnable() { @Override public void run() { PlayerStat.removePlayer(id); } }.runTaskLater(SkyWarsReloaded.get(), 20); } }