Handle LingeringPotions as their own event.

potion-splash flag should now filter them when denied.
Fixes WORLDGUARD-3765.
This commit is contained in:
wizjany 2016-11-15 21:20:49 -05:00
parent 4746e95249
commit 26e59955ed
3 changed files with 32 additions and 3 deletions

View File

@ -70,8 +70,10 @@
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.*;
import org.bukkit.material.Dispenser;
import org.bukkit.material.MaterialData;
import org.bukkit.material.PistonExtensionMaterial;
import org.bukkit.material.SpawnEgg;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
@ -832,6 +834,7 @@ public void onPotionSplash(PotionSplashEvent event) {
// 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()) {
@ -848,12 +851,29 @@ public void onPotionSplash(PotionSplashEvent event) {
}
}
if (blocked == event.getAffectedEntities().size()) {
if (blocked == affectedSize) { // server does weird things with this if the event is modified, so use cached number
event.setCancelled(true);
}
}
}
@EventHandler(ignoreCancelled = true)
public void onLingeringSplash(LingeringPotionSplashEvent event) {
AreaEffectCloud aec = event.getAreaEffectCloud();
LingeringPotion potion = event.getEntity();
World world = potion.getWorld();
Cause cause = create(event.getEntity());
// Fire item interaction event
Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));
// Fire entity spawn event
if (!event.isCancelled()) {
// radius unfortunately doesn't go through with this, so only a single location is tested
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, aec.getLocation().add(0.5, 0, 0.5), EntityType.AREA_EFFECT_CLOUD));
}
}
@EventHandler(ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent event) {
Cause cause = create(event.getBlock());

View File

@ -340,10 +340,14 @@ public void onSpawnEntity(SpawnEntityEvent event) {
what = "drop items";
/* XP drops */
} else if (event.getEffectiveType() == EntityType.EXPERIENCE_ORB) {
} else if (type == EntityType.EXPERIENCE_ORB) {
canSpawn = query.testBuild(target, associable, combine(event, DefaultFlag.EXP_DROPS));
what = "drop XP";
} else if (Entities.isAoECloud(type)) {
canSpawn = query.testBuild(target, associable, combine(event, DefaultFlag.POTION_SPLASH));
what = "use lingering potions";
/* Everything else */
} else {
canSpawn = query.testBuild(target, associable, combine(event));

View File

@ -204,4 +204,9 @@ public static boolean isPotionArrow(Entity entity) {
return (entity != null &&
(entity.getType() == tippedArrow || entity.getType() == spectralArrow));
}
private static final EntityType aoeCloud = Enums.findByValue(EntityType.class, "AREA_EFFECT_CLOUD");
public static boolean isAoECloud(EntityType type) {
return type == aoeCloud;
}
}