Java Code Examples for org.bukkit.event.entity.EntityDamageEvent#setCancelled()
The following examples show how to use
org.bukkit.event.entity.EntityDamageEvent#setCancelled() .
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: 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 2
Source File: SentinelTrait.java From Sentinel with MIT License | 6 votes |
/** * 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 3
Source File: PlayerDamageListener.java From UhcCore with GNU General Public License v3.0 | 6 votes |
private void handleAnyDamage(EntityDamageEvent event){ if(event.getEntity() instanceof Player){ Player player = (Player) event.getEntity(); PlayersManager pm = GameManager.getGameManager().getPlayersManager(); UhcPlayer uhcPlayer = pm.getUhcPlayer(player); PlayerState uhcPlayerState = uhcPlayer.getState(); if(uhcPlayerState.equals(PlayerState.WAITING) || uhcPlayerState.equals(PlayerState.DEAD)){ event.setCancelled(true); } if (uhcPlayer.isFrozen()){ event.setCancelled(true); } } }
Example 4
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 5
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 6
Source File: PopperGizmo.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void entityDamage(final EntityDamageEvent event) { if(!(event instanceof EntityDamageByEntityEvent)) return; EntityDamageByEntityEvent realEvent = (EntityDamageByEntityEvent) event; if(!(realEvent.getDamager() instanceof Player) || !(realEvent.getEntity() instanceof Player)) return; final Player damager = (Player) realEvent.getDamager(); final Player victim = (Player) realEvent.getEntity(); if(victim.hasPermission(GizmoConfig.EXEMPT_PERMISSION)) return; if(!(Gizmos.gizmoMap.get(damager) instanceof PopperGizmo)) return; if(damager.getItemInHand().getType() != this.getIcon()) return; if(!damager.canSee(victim)) return; damager.hidePlayer(victim); damager.playSound(damager.getLocation(), Sound.BLOCK_LAVA_POP, 1f, 2f); Integer count = poppedCount.get(damager); if(count == null) count = 0; count++; poppedCount.put(damager, count); if(count % 10 == 0) { RaindropUtil.giveRaindrops( Users.playerId(damager), 1, null, new TranslatableComponent("gizmo.popper.raindropsResult", new Component(String.valueOf(count), net.md_5.bungee.api.ChatColor.GOLD)) ); } event.setCancelled(true); }
Example 7
Source File: PlayerEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@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 8
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 9
Source File: PetOwnerListener.java From SonarPet 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 10
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 11
Source File: DisableDamageMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void handleDamage(EntityDamageEvent event) { MatchPlayer victim = match.getParticipant(event.getEntity()); if (victim == null) return; DamageInfo damageInfo = match.needModule(TrackerMatchModule.class).resolveDamage(event); if (!canDamage(event.getCause(), victim, damageInfo)) { event.setCancelled(true); } }
Example 12
Source File: DeathStandsModule.java From UHC with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void on(EntityDamageEvent event) { if (event.getEntityType() != EntityType.ARMOR_STAND) return; if (!isProtectedArmourStand(event.getEntity())) return; // always cancel events, we choose when to break the stand event.setCancelled(true); final ArmorStand stand = (ArmorStand) event.getEntity(); final Location loc = stand.getLocation(); final World world = stand.getWorld(); // for the first 2 seconds don't allow breaking // to avoid accidental breaks after kill if (event.getEntity().getTicksLived() < 2 * TICKS_PER_SECOND) { world.playEffect(stand.getEyeLocation(), Effect.WITCH_MAGIC, 0); return; } // drop each of it's worn items for (final ItemStack stack : Maps.filterValues(getItems(stand), Predicates.not(EMPTY_ITEM)).values()) { world.dropItemNaturally(loc, stack); } // kill the stand now stand.remove(); }
Example 13
Source File: MobListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onEntityDamage(EntityDamageEvent event) { if (!(event.getEntity() instanceof LivingEntity)) { return; } if (!MobLib.isMobLibEntity((LivingEntity) event.getEntity())) { return; } switch (event.getCause()) { case SUFFOCATION: Location loc = event.getEntity().getLocation(); int y = loc.getWorld().getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY()+4; loc.setY(y); event.getEntity().teleport(loc); case CONTACT: case FALL: case FIRE: case FIRE_TICK: case LAVA: case MELTING: case DROWNING: case FALLING_BLOCK: case BLOCK_EXPLOSION: case ENTITY_EXPLOSION: case LIGHTNING: case MAGIC: event.setCancelled(true); break; default: break; } }
Example 14
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 15
Source File: KeepHealth.java From HubBasics with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onDamage(EntityDamageEvent event) { if (event.getEntityType() != EntityType.PLAYER) return; String world = event.getEntity().getWorld().getName().toLowerCase(); Player player = (Player) event.getEntity(); if (this.worldHealthMap.containsKey(world)) { player.setHealth(this.worldHealthMap.get(world)); AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); if (attribute != null) { attribute.setBaseValue(this.worldMaxHealthMap.get(world)); } event.setCancelled(true); } }
Example 16
Source File: BlockListener.java From Carbon with GNU Lesser General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onSlimeBlockFall(EntityDamageEvent evt) { if (evt.getCause().equals(DamageCause.FALL) && evt.getEntity().getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock().getType().equals(Carbon.injector().slimeMat)) evt.setCancelled(true); }
Example 17
Source File: Dead.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onEvent(EntityDamageEvent event) { super.onEvent(event); event.setCancelled(true); }
Example 18
Source File: Observing.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onEvent(EntityDamageEvent event) { super.onEvent(event); event.setCancelled(true); }
Example 19
Source File: Pickup.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onDamage(EntityDamageEvent event) { if(isSpawned() && event.getEntity().equals(entity.get())) { event.setCancelled(true); } }
Example 20
Source File: RocketGizmo.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler public void entityDamage(final EntityDamageEvent event) { if(!(event instanceof EntityDamageByEntityEvent)) return; EntityDamageByEntityEvent realEvent = (EntityDamageByEntityEvent) event; if(!(realEvent.getDamager() instanceof Player) || !(realEvent.getEntity() instanceof Player)) return; final Player damager = (Player) realEvent.getDamager(); final Player victim = (Player) realEvent.getEntity(); if(victim.hasPermission(GizmoConfig.EXEMPT_PERMISSION)) return; if(!(Gizmos.gizmoMap.get(damager) instanceof RocketGizmo)) return; if(damager.getItemInHand().getType() != this.getIcon()) return; boolean cancel = false; for(Rocket rocket : this.rockets) { if(rocket.getObserver().equals(damager) && rocket.getVictim().equals(victim)) { cancel = true; break; } } if(cancel) return; List<Firework> fireworks = Lists.newArrayList(); for(int i = 0; i < GizmoConfig.FIREWORK_COUNT; i++) { Firework firework = RocketUtils.getRandomFirework(victim.getLocation()); firework.setVelocity(firework.getVelocity().multiply(new Vector(1, GizmoConfig.ROCKET_VELOCITY_MOD, 1))); fireworks.add(firework); } this.rockets.add(new Rocket(damager, victim, fireworks)); RocketUtils.fakeDelta(damager, victim, new Vector(0, 3, 0)); RocketUtils.takeOff(damager, victim.getLocation()); Integer count = rocketedCount.get(damager); if(count == null) count = 0; count++; rocketedCount.put(damager, count); if(count % 10 == 0) { RaindropUtil.giveRaindrops( Users.playerId(damager), 1, null, new TranslatableComponent("gizmo.rocket.raindropsResult", new Component(String.valueOf(count), net.md_5.bungee.api.ChatColor.GOLD)) ); } event.setCancelled(true); }