From fcfd6616bee14c328262c5d0d12f1ceed5029c0d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 15 Aug 2015 13:37:11 +1000 Subject: [PATCH] Splash potion protection --- pom.xml | 2 +- .../plot/commands/Clear.java | 2 +- .../bukkit/listeners/PlayerEvents.java | 78 ++++++++++++------- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 1ec715a8b..ddff8b266 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.0.16 + 3.0.17 PlotSquared jar diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 7834414e3..fdaf2ec9a 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -88,7 +88,7 @@ public class Clear extends SubCommand { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); return false; } - if (Settings.DONE_COUNTS_TOWARDS_LIMIT && FlagManager.isPlotFlagTrue(plot, "done" ) && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)) { + if (FlagManager.isPlotFlagTrue(plot, "done" ) && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))) { MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE); return false; } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 50687a08d..18b8e7a81 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -57,10 +57,12 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Hanging; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.Tameable; +import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.Vehicle; import org.bukkit.entity.minecart.RideableMinecart; import org.bukkit.event.EventHandler; @@ -85,6 +87,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; @@ -1881,14 +1884,33 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityDamageByEntityEvent(final EntityDamageByEntityEvent e) { - final Location l = BukkitUtil.getLocation(e.getEntity()); + public void onPotionSplash(final PotionSplashEvent event) { + ThrownPotion damager = event.getPotion(); + final Location l = BukkitUtil.getLocation(damager); if (!PS.get().isPlotWorld(l.getWorld())) { return; } + for (LivingEntity victim : event.getAffectedEntities()) { + if (!entityDamage(l, damager, victim)) { + event.setIntensity(victim, 0); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityDamageByEntityEvent(final EntityDamageByEntityEvent e) { final Entity damager = e.getDamager(); + final Location l = BukkitUtil.getLocation(damager); + if (!PS.get().isPlotWorld(l.getWorld())) { + return; + } final Entity victim = e.getEntity(); - + if (!entityDamage(l, damager, victim)) { + e.setCancelled(true); + } + } + + public boolean entityDamage(Location l, Entity damager, Entity victim) { Location dloc = BukkitUtil.getLocation(damager); Location vloc = BukkitUtil.getLocation(victim); @@ -1899,7 +1921,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen String stub; if (dplot == null && vplot == null) { if (!MainUtil.isPlotAreaAbs(dloc)) { - return; + return true; } plot = null; stub = "road"; @@ -1931,90 +1953,88 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen PlotPlayer pp = BukkitUtil.getPlayer(player); if (victim instanceof Hanging) { // hanging if (plot != null && ((FlagManager.isPlotFlagTrue(plot, "hanging-break") || plot.isAdded(pp.getUUID())))) { - return; + return true; } if (!Permissions.hasPermission(pp, "plots.admin.break." + stub)) { - e.setCancelled(true); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.break." + stub); - return; + return false; } } else if (victim.getEntityId() == 30) { if (plot != null && ((FlagManager.isPlotFlagTrue(plot, "misc-break") || plot.isAdded(pp.getUUID())))) { - return; + return true; } if (!Permissions.hasPermission(pp, "plots.admin.break." + stub)) { - e.setCancelled(true); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.break." + stub); - return; + return false; } } else if (victim instanceof Monster || victim instanceof EnderDragon) { // victim is monster if (plot != null && ((FlagManager.isPlotFlagTrue(plot, "hostile-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID())))) { - return; + return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { - e.setCancelled(true); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); - return; + return false; } } else if (victim instanceof Tameable) { // victim is tameable if (plot != null && ((FlagManager.isPlotFlagTrue(plot, "tamed-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID())))) { - return; + return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { - e.setCancelled(true); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); - return; + return false; } } else if (victim instanceof Player) { if (plot != null) { Flag pvp = FlagManager.getPlotFlag(plot, FLAG_PVP); if (pvp == null) { - return; + return true; } else { if ((Boolean) pvp.getValue()) { - return; + return true; + } + else if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); + return false; } } } if (!Permissions.hasPermission(pp, "plots.admin.pvp." + stub)) { - e.setCancelled(true); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pvp." + stub); - return; + return false; } } else if (victim instanceof Creature) { // victim is animal if (plot != null && ((FlagManager.isPlotFlagTrue(plot, "animal-attack") || FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID())))) { - return; + return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { - e.setCancelled(true); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); - return; + return false; } } else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event - return; + return true; } else { // victim is something else if (plot != null && ((FlagManager.isPlotFlagTrue(plot, "pve") || plot.isAdded(pp.getUUID())))) { - return; + return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { - e.setCancelled(true); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); - return; + return false; } } - return; + return true; } // player is null if ((damager instanceof Arrow) && (!(victim instanceof Creature))) { - e.setCancelled(true); + return false; } + return true; } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)