diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 239592c36..eac5e7bcc 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -99,8 +99,10 @@ import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Shulker; import org.bukkit.event.Listener; import org.bukkit.generator.ChunkGenerator; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; @@ -469,6 +471,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) { iterator.remove(); entity.remove(); + entity = null; } } } else { @@ -476,10 +479,34 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) { iterator.remove(); entity.remove(); + entity = null; } } } } + + if (entity != null && BukkitUtil.getLocation(entity.getLocation()).isPlotArea()) { + if (entity instanceof Shulker) { + LivingEntity livingEntity = (LivingEntity) entity; + if (entity.hasMetadata("ownerplot")) { + if(!livingEntity.isLeashed() || !entity.hasMetadata("keep")) { + PlotId originalPlotId = (PlotId) (!entity.getMetadata("ownerplot").isEmpty() ? entity.getMetadata("ownerplot").get(0).value() : null); + PlotId currentPlotId = BukkitUtil.getLocation(entity.getLocation()).getPlot().getId(); + if(!currentPlotId.equals(originalPlotId)) { + iterator.remove(); + entity.remove(); + } + + } + } + else { + if(!entity.hasMetadata("ownerplot")) { + //This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java) + entity.setMetadata("ownerplot", new FixedMetadataValue((Plugin) PS.get().IMP, BukkitUtil.getLocation(entity.getLocation()).getPlot().getId())); + } + } + } + } } } } catch (Throwable e) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java index 2dbfaf788..3b8c7b02d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java @@ -1,5 +1,6 @@ package com.plotsquared.bukkit.listeners; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; @@ -11,6 +12,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.plugin.Plugin; public class EntitySpawnListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -38,6 +41,10 @@ public class EntitySpawnListener implements Listener { if (PlayerEvents.checkEntity(entity, plot)) { event.setCancelled(true); } + case SHULKER: + if(!entity.hasMetadata("ownerplot")) { + entity.setMetadata("ownerplot", new FixedMetadataValue((Plugin) PS.get().IMP, plot.getId())); + } } } } 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 f0de471df..88a35e6d0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1263,7 +1263,8 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockDispense(BlockDispenseEvent event) { Material type = event.getItem().getType(); - if (type != Material.WATER_BUCKET && type != Material.LAVA_BUCKET) { + Material dispenserType = event.getBlock().getType(); + if (dispenserType == Material.DROPPER || (type != Material.WATER_BUCKET && type != Material.LAVA_BUCKET)) { return; } Location location = BukkitUtil.getLocation(event.getVelocity().toLocation(event.getBlock().getWorld()));