diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index de98b99d5..9e3a19c3b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -42,6 +42,7 @@ import com.plotsquared.bukkit.listeners.ForceFieldListener; import com.plotsquared.bukkit.listeners.PlayerEvents; import com.plotsquared.bukkit.listeners.PlayerEvents183; import com.plotsquared.bukkit.listeners.PlayerEvents_1_8; +import com.plotsquared.bukkit.listeners.PlayerEvents_1_9; import com.plotsquared.bukkit.listeners.PlotPlusListener; import com.plotsquared.bukkit.listeners.WorldEvents; import com.plotsquared.bukkit.listeners.worldedit.WEListener; @@ -72,6 +73,12 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.SQLUUIDHandler; import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -86,13 +93,6 @@ import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; - public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public static BukkitMain THIS; @@ -349,13 +349,17 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public void registerPlayerEvents() { - getServer().getPluginManager().registerEvents(new PlayerEvents(), this); + PlayerEvents main = new PlayerEvents(); + getServer().getPluginManager().registerEvents(main, this); if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this); } if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) { getServer().getPluginManager().registerEvents(new PlayerEvents183(), this); } + if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) { + getServer().getPluginManager().registerEvents(new PlayerEvents_1_9(main), this); + } } @Override 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 bf7f88fc6..5db37b92d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -28,6 +28,16 @@ import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.listener.PlayerBlockEventType; import com.plotsquared.listener.PlotListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -108,17 +118,6 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; - /** * Player Events involving plots. * @@ -271,15 +270,15 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler - public void onProjectileHit(ProjectileHitEvent event) { + public boolean onProjectileHit(ProjectileHitEvent event) { Projectile entity = event.getEntity(); Location loc = BukkitUtil.getLocation(entity); if (!PS.get().hasPlotArea(loc.getWorld())) { - return; + return true; } PlotArea area = loc.getPlotArea(); if (area == null) { - return; + return true; } Plot plot = area.getPlotAbs(loc); // @@ -289,28 +288,32 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { if (!Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_UNOWNED)) { entity.remove(); + return false; } - return; + return true; } if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) { - return; + return true; } entity.remove(); + return false; } else if (!(shooter instanceof Entity) && shooter != null) { if (plot == null) { entity.remove(); - return; + return false; } Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); if (!area.contains(sLoc.getX(), sLoc.getZ())) { entity.remove(); - return; + return false; } Plot sPlot = area.getOwnedPlotAbs(sLoc); if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) { entity.remove(); + return false; } } + return true; } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @@ -2035,11 +2038,16 @@ public class PlayerEvents extends PlotListener implements Listener { if (!PS.get().hasPlotArea(l.getWorld())) { return; } + int count = 0; for (LivingEntity victim : event.getAffectedEntities()) { if (!entityDamage(damager, victim)) { event.setIntensity(victim, 0); + count++; } } + if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) { + event.setCancelled(true); + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_9.java new file mode 100644 index 000000000..73e2f1965 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_9.java @@ -0,0 +1,34 @@ +package com.plotsquared.bukkit.listeners; + +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.Location; +import com.plotsquared.bukkit.util.BukkitUtil; +import org.bukkit.entity.LingeringPotion; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.LingeringPotionSplashEvent; + +/** + * Created by Jesse on 3/30/2016. + */ +public class PlayerEvents_1_9 implements Listener { + + private final PlayerEvents parent; + + public PlayerEvents_1_9(PlayerEvents parent) { + this.parent = parent; + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPotionSplash(LingeringPotionSplashEvent event) { + LingeringPotion entity = event.getEntity(); + Location l = BukkitUtil.getLocation(entity); + if (!PS.get().hasPlotArea(l.getWorld())) { + return; + } + if (!parent.onProjectileHit(event)) { + event.setCancelled(true); + } + } +}