Java Code Examples for org.bukkit.event.entity.EntityDamageEvent.DamageCause#ENTITY_EXPLOSION
The following examples show how to use
org.bukkit.event.entity.EntityDamageEvent.DamageCause#ENTITY_EXPLOSION .
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: 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 2
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 3
Source File: TestFireworksListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Test public void testFireworkDamage() { Player player = server.addPlayer(); Firework firework = Mockito.mock(Firework.class); FireworkMeta meta = new FireworkMetaMock(); meta.setDisplayName(ChatColor.GREEN + "Slimefun Research"); Mockito.when(firework.getType()).thenReturn(EntityType.FIREWORK); Mockito.when(firework.getFireworkMeta()).thenReturn(meta); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_EXPLOSION, 6.0); server.getPluginManager().callEvent(event); Assertions.assertTrue(event.isCancelled()); }