From f8e97f14d689a06af3affe342858a9fdc6d784d5 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 28 Jun 2016 02:03:16 +1000 Subject: [PATCH] Fix end crystal spawn cap --- Bukkit/build.gradle | 2 +- .../com/plotsquared/bukkit/BukkitMain.java | 4 +++ .../bukkit/listeners/EntitySpawnListener.java | 36 +++++++++++++++++++ .../bukkit/listeners/PlayerEvents.java | 23 ++++++------ 4 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 2d34329da..e9aadce6a 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -1,6 +1,6 @@ dependencies { compile project(':Core') - compile 'org.bukkit:bukkit:1.10-R0.1-SNAPSHOT' + compile 'org.spigotmc:spigot-api:1.10.2-R0.1-SNAPSHOT' compile 'org.mcstats.bukkit:metrics:R7' compile 'net.milkbowl.vault:VaultAPI:1.6' } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 2c2455791..7536d23d1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -38,6 +38,7 @@ import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter; import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.listeners.ChunkListener; +import com.plotsquared.bukkit.listeners.EntitySpawnListener; import com.plotsquared.bukkit.listeners.ForceFieldListener; import com.plotsquared.bukkit.listeners.PlayerEvents; import com.plotsquared.bukkit.listeners.PlayerEvents183; @@ -361,6 +362,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain public void registerPlayerEvents() { PlayerEvents main = new PlayerEvents(); getServer().getPluginManager().registerEvents(main, this); + try { + getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this); + } catch (Throwable ignore) {} if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { try { getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java new file mode 100644 index 000000000..5c871eaf5 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java @@ -0,0 +1,36 @@ +package com.plotsquared.bukkit.listeners; + +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.plotsquared.bukkit.util.BukkitUtil; +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntitySpawnEvent; + +public class EntitySpawnListener implements Listener { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void creatureSpawnEvent(EntitySpawnEvent event) { + Entity entity = event.getEntity(); + switch (entity.getType()) { + case ENDER_CRYSTAL: + Location location = BukkitUtil.getLocation(entity.getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = area.getOwnedPlotAbs(location); + if (plot == null) { + if (!area.MOB_SPAWNING) { + event.setCancelled(true); + } + return; + } + if (PlayerEvents.checkEntity(entity, plot)) { + event.setCancelled(true); + } + } + } +} 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 1451bb314..ab00d14a6 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; @@ -111,17 +121,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. * @@ -1415,7 +1414,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } - public boolean checkEntity(Entity entity, Plot plot) { + public static boolean checkEntity(Entity entity, Plot plot) { if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS.isEmpty()) { return false; }