new PotionSplashEvent(this, affectedIntensities)); if (!event.isCancelled()) { for (LivingEntity splashed : event.getAffectedEntities()) { for (PotionEffect effect : effects) { double intensity = event.getIntensity(splashed); EntityUtils.applyPotionEffectWithIntensity( effect, splashed, intensity, intensity);
/** * Gets the potion which caused this event * * @return The thrown potion entity */ public ThrownPotion getPotion() { return (ThrownPotion) getEntity(); }
for (PotionEffect effect : event.getPotion().getEffects()) { if (badPotionEffects.contains(effect.getType())) { badjuju = true; ProjectileSource thrower = event.getPotion().getShooter(); if (!(thrower instanceof Entity)) { return; FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); if (badjuju && fPlayer.getFaction().isPeaceful()) { event.setCancelled(true); return; for (LivingEntity target : event.getAffectedEntities()) { EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent((Entity) thrower, target, EntityDamageEvent.DamageCause.CUSTOM, 0); if (!this.canDamagerHurtDamagee(sub, true)) { event.setIntensity(target, 0.0); // affected entity list doesn't accept modification (so no iter.remove()), but this works
@EventHandler(ignoreCancelled = true) public void onPotionSplash(PotionSplashEvent event) { Entity entity = event.getEntity(); ThrownPotion potion = event.getPotion(); World world = entity.getWorld(); Cause cause = create(potion); // Fire item interaction event Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem())); // Fire entity interaction event if (!event.isCancelled()) { int blocked = 0; int affectedSize = event.getAffectedEntities().size(); boolean hasDamageEffect = Materials.hasDamageEffect(potion.getEffects()); for (LivingEntity affected : event.getAffectedEntities()) { DelegateEvent delegate = hasDamageEffect ? new DamageEntityEvent(event, cause, affected) : new UseEntityEvent(event, cause, affected); // Consider the potion splash flag delegate.getRelevantFlags().add(Flags.POTION_SPLASH); if (Events.fireAndTestCancel(delegate)) { event.setIntensity(affected, 0); blocked++; } } if (blocked == affectedSize) { // server does weird things with this if the event is modified, so use cached number event.setCancelled(true); } } }
/** * Change the duration using values defined in config * for splash potions */ @EventHandler(priority = EventPriority.HIGHEST) public void onPotionSplash(PotionSplashEvent event){ ThrownPotion thrownPotion = event.getPotion(); ItemStack potion = thrownPotion.getItem(); PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); PotionEffect potionEffect = (PotionEffect) thrownPotion.getEffects().toArray()[0]; PotionData potionData = potionMeta.getBasePotionData(); if(isExcludedPotion(potionData.getType())) return; event.setCancelled(true); int duration = getPotionDuration(potionData, true); PotionEffectType pet = potionEffect.getType(); PotionEffect pe = new PotionEffect(pet, duration, potionEffect.getAmplifier()); event.getAffectedEntities().forEach(livingEntity -> setNewPotionEffect(livingEntity, pet, pe)); }
/** * Handle PotionSplash events in order to fix broken Splash Potion of * Saturation. * * @param event * The event to process */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPotionSplash(PotionSplashEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) return; for (PotionEffect effect : ((PotionMeta) event.getPotion().getItem().getItemMeta()).getCustomEffects()) { if (!effect.getType().equals(PotionEffectType.SATURATION)) { return; } for (LivingEntity entity : event.getAffectedEntities()) { int duration = (int) (effect.getDuration() * event.getIntensity(entity)); entity.addPotionEffect(new PotionEffect(effect.getType(), duration, effect.getAmplifier(), effect.isAmbient())); } } }
public void onSplashPotionSplash(final PotionSplashEvent e) { Projectile projectile = e.getEntity(); if (projectile.getShooter() instanceof Player) { Player attacker = (Player)projectile.getShooter(); for (LivingEntity entity: e.getAffectedEntities()) { for (PotionEffect effect : e.getPotion().getEffects()) { entity.removePotionEffect(effect.getType()); for (PotionEffect effect : e.getPotion().getEffects()) { entity.removePotionEffect(effect.getType()); for (PotionEffect effect : e.getPotion().getEffects()) { entity.removePotionEffect(effect.getType());
/** * Checks for splash damage. Remove damage if it should not affect. * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onSplashPotionSplash(final PotionSplashEvent e) { if (e.getEntity().getShooter() instanceof Player && getPlugin().getIWM().inWorld(e.getEntity().getLocation())) { User user = User.getInstance((Player)e.getEntity().getShooter()); // Run through affected entities and cancel the splash if any are a protected player e.setCancelled(e.getAffectedEntities().stream().anyMatch(le -> blockPVP(user, le, e, getFlag(e.getEntity().getWorld())))); } }
public void onPotionSplash(PotionSplashEvent event) { ThrownPotion potion = event.getPotion(); if (!region.contains(potion.getLocation())) { return; PotionEffectType type = effect.getType(); if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) { for (LivingEntity le : event.getAffectedEntities()) { if (le instanceof Player) { event.setIntensity(le, 0.0); PotionEffectType type = effect.getType(); if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) { for (LivingEntity le : event.getAffectedEntities()) { if (!(le instanceof Player)) { event.setIntensity(le, 0.0);
/** * @param event */ @EventHandler(priority = EventPriority.HIGH) public void onPotionSplash(PotionSplashEvent event) { if (event.isCancelled()) { return; } ThrownPotion potion = event.getPotion(); ProjectileSource shooter = potion.getShooter(); if (shooter != null) { if (shooter instanceof Player) { Player player = (Player) shooter; Field field = plugin.getForceFieldManager().getEnabledSourceField(player.getLocation(), FieldFlag.PREVENT_POTION_SPLASH); if (field != null) { if (FieldFlag.PREVENT_POTION_SPLASH.applies(field, player)) { event.setCancelled(true); } } } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onThrowPotion(PotionSplashEvent event) { ProjectileSource source = event.getEntity().getShooter(); if (!(source instanceof Player)) { event.setCancelled(true); return; } Player thrower = (Player) source; if (plugin.al.isAdmin(thrower)) { return; } for (Player player : thrower.getWorld().getPlayers()) { if (thrower.getLocation().distanceSquared(player.getLocation()) < POTION_BLOCK_RADIUS_SQUARED) { thrower.sendMessage(ChatColor.RED + "You cannot use splash potions close to other players."); event.setCancelled(true); return; } } }
@Override public Set<MCLivingEntity> getAffectedEntities() { Set<MCLivingEntity> ret = new HashSet<>(); for(LivingEntity le : pse.getAffectedEntities()) { ret.add((MCLivingEntity) BukkitConvertor.BukkitGetCorrectEntity(le)); } return ret; }
@Override public void setIntensity(MCLivingEntity le, double intensity) { pse.setIntensity(((BukkitMCLivingEntity) le).asLivingEntity(), intensity); } }
@Override public double getIntensity(MCLivingEntity le) { return pse.getIntensity(((BukkitMCLivingEntity) le).asLivingEntity()); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPotionSplash (PotionSplashEvent event) ThrownPotion potion = event.getPotion(); for(LivingEntity effected : event.getAffectedEntities()) if(claim.allowContainers(thrower) != null) event.setCancelled(true); GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.NoDamageClaimedEntity, claim.getOwnerName()); return; for(LivingEntity effected : event.getAffectedEntities()) if(!pvpEvent.isCancelled()) event.setIntensity(effected, 0); GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.CantFightWhileImmune); continue; if(!pvpEvent.isCancelled()) event.setIntensity(effected, 0); GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.PlayerInPvPSafeZone); continue;
boolean hasHarm = false; ThrownPotion potion = event.getPotion(); Collection<PotionEffect> effects = potion.getEffects(); Collection<LivingEntity> entities = event.getAffectedEntities(); event.setCancelled(true);
/** * Gets the potion which caused this event * * @return The thrown potion entity */ public ThrownPotion getPotion() { return (ThrownPotion) getEntity(); }