Cancel potion throw

This commit is contained in:
Jesse Boyd 2016-03-30 13:41:13 +11:00
parent dca2696782
commit 95d03e878c

View File

@ -90,6 +90,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent; 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 @EventHandler
public boolean onProjectileHit(ProjectileHitEvent event) { public boolean onProjectileHit(ProjectileHitEvent event) {
Projectile entity = event.getEntity(); Projectile entity = event.getEntity();