From 442513b5920c76b60fce79a5e6ce2d7190c39e7e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 7 Jun 2018 08:15:28 +1000 Subject: [PATCH] Fixes #1970 --- .../com/plotsquared/bukkit/BukkitMain.java | 45 ++++++++++++------- .../plot/object/PlotId.java | 6 +++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index bb004a234..9ee0332f5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -87,12 +87,7 @@ import com.sk89q.worldedit.WorldEdit; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -527,27 +522,43 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } } } + continue; } case SHULKER: { if (Settings.Enabled_Components.KILL_ROAD_MOBS) { LivingEntity livingEntity = (LivingEntity) entity; - if (entity.hasMetadata("plot")) { - if (!livingEntity.isLeashed() || !entity.hasMetadata("keep")) { - PlotId originalPlotId = (PlotId) (!entity.getMetadata("plot").isEmpty() ? entity.getMetadata("plot").get(0).value() : null); - PlotId currentPlotId = BukkitUtil.getLocation(entity.getLocation()).getPlot().getId(); - if (!currentPlotId.equals(originalPlotId)) { - iterator.remove(); - entity.remove(); - } + List meta = entity.getMetadata("plot"); + if (meta != null && !meta.isEmpty()) { + if (livingEntity.isLeashed()) continue; + List keep = entity.getMetadata("keep"); + if (keep != null && !keep.isEmpty()) continue; + + PlotId originalPlotId = (PlotId) meta.get(0).value(); + if (originalPlotId != null) { + com.intellectualcrafters.plot.object.Location pLoc = BukkitUtil.getLocation(entity.getLocation()); + PlotArea area = pLoc.getPlotArea(); + if (area != null) { + PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc)); + if (!originalPlotId.equals(currentPlotId) && (currentPlotId == null || !area.getPlot(originalPlotId).equals(area.getPlot(currentPlotId)))) { + iterator.remove(); + entity.remove(); + } + } } } else { - if (!entity.hasMetadata("plot")) { - //This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java) - entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, BukkitUtil.getLocation(entity.getLocation()).getPlot().getId())); + //This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java) + com.intellectualcrafters.plot.object.Location pLoc = BukkitUtil.getLocation(entity.getLocation()); + PlotArea area = pLoc.getPlotArea(); + if (area != null) { + PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc)); + if (currentPlotId != null) { + entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, currentPlotId)); + } } } } + continue; } } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index ec17c18eb..679e7df8c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -1,5 +1,7 @@ package com.intellectualcrafters.plot.object; +import javax.annotation.Nullable; + public class PlotId { /** * x value @@ -77,6 +79,10 @@ public class PlotId { } } + public static PlotId of(@Nullable Plot plot) { + return plot != null ? plot.getId() : null; + } + /** * Get the PlotId from the HashCode
* Note: Only accurate for small x,z values (short)