From 95d03e878c83436982aed04d7bdfed8f0c024e08 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 30 Mar 2016 13:41:13 +1100 Subject: [PATCH] Cancel potion throw --- .../bukkit/listeners/PlayerEvents.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 5db37b92d..5aa5baa56 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -90,6 +90,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; @@ -269,6 +270,29 @@ public class PlayerEvents extends PlotListener implements Listener { } } + @EventHandler + public void onProjectileLaunch(ProjectileLaunchEvent event) { + Projectile entity = event.getEntity(); + if (!(entity instanceof ThrownPotion)) { + return; + } + ProjectileSource shooter = entity.getShooter(); + if (!(shooter instanceof Player)) { + return; + } + ThrownPotion potion = (ThrownPotion) entity; + Location l = BukkitUtil.getLocation(potion); + if (!PS.get().hasPlotArea(l.getWorld())) { + return; + } + PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); + Plot plot = l.getOwnedPlot(); + if (plot != null && !plot.isAdded(pp.getUUID())) { + entity.remove(); + event.setCancelled(true); + } + } + @EventHandler public boolean onProjectileHit(ProjectileHitEvent event) { Projectile entity = event.getEntity();