/** * Gets the potion which caused this event * * @return The thrown potion entity */ public ThrownPotion getPotion() { return (ThrownPotion) getEntity(); }
/** * Gets the potion which caused this event * * @return The thrown potion entity */ public ThrownPotion getPotion() { return (ThrownPotion) getEntity(); }
/** * 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())))); } }
@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); } } }
@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; } } }
/** * 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();