PotionSplashEvent event = EventFactory.getInstance().callEvent( new PotionSplashEvent(this, affectedIntensities)); if (!event.isCancelled()) { for (LivingEntity splashed : event.getAffectedEntities()) { for (PotionEffect effect : effects) {
/** * @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(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); } } }