@Override public MCItemStack getItem() { return new BukkitMCItemStack(getHandle().getItem()); }
/** * 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)); }
@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); } } }
/** * 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())); } } }