public void onPotionSplash(PotionSplashEvent event) { ThrownPotion potion = event.getPotion(); if (!region.contains(potion.getLocation())) { return; if (potion.getShooter() instanceof Player) { for (PotionEffect effect : potion.getEffects()) { PotionEffectType type = effect.getType(); if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) { for (PotionEffect effect : potion.getEffects()) { PotionEffectType type = effect.getType(); if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) {
/** * 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)); }
/** * 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())))); } }
if (potion == null) { potion = (ThrownPotion) location.getWorld().spawnEntity(location, EntityType.SPLASH_POTION); potion.remove(); potionReference = new WeakReference<>(potion); potion.teleport(location); potion.setShooter((LivingEntity)source); Object potionHandle = getHandle(potion); Object damageSource = class_DamageSource_getMagicSourceMethod.invoke(null, potionHandle, sourceHandle);
for (PotionEffect effect : event.getPotion().getEffects()) { if (badPotionEffects.contains(effect.getType())) { badjuju = true; ProjectileSource thrower = event.getPotion().getShooter(); if (!(thrower instanceof Entity)) { return;
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());
/** * @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); } } } } }
/** * 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())); } } }
@Override public MCItemStack getItem() { return new BukkitMCItemStack(getHandle().getItem()); }
/** * Fires a potion from the NPC at a target. */ public void firePotion(ItemStack potion, Location target, Vector lead) { sentinel.stats_potionsThrown++; HashMap.SimpleEntry<Location, Vector> start = sentinel.getLaunchDetail(target, lead); Entity entpotion; if (SentinelTarget.v1_9) { entpotion = start.getKey().getWorld().spawnEntity(start.getKey(), potion.getType() == Material.SPLASH_POTION ? EntityType.SPLASH_POTION : EntityType.LINGERING_POTION); } else { entpotion = start.getKey().getWorld().spawnEntity(start.getKey(), EntityType.SPLASH_POTION); } ((ThrownPotion) entpotion).setShooter(getLivingEntity()); ((ThrownPotion) entpotion).setItem(potion); entpotion.setVelocity(sentinel.fixForAcc(start.getValue())); sentinel.swingWeapon(); }
@Override public void setItem(MCItemStack item) { getHandle().setItem((ItemStack) item.getHandle()); } }
ProjectileSource projectileSource = potion.getShooter(); if(projectileSource == null || !(projectileSource instanceof Player)) return; Player thrower = (Player)projectileSource; Collection<PotionEffect> effects = potion.getEffects(); for(PotionEffect effect : effects)
Collection<PotionEffect> effects = potion.getEffects();
@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; } } }
@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); } } }