This commit is contained in:
Jesse Boyd 2018-06-07 08:15:28 +10:00
parent 40635255e3
commit 442513b592
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 34 additions and 17 deletions

View File

@ -87,12 +87,7 @@ import com.sk89q.worldedit.WorldEdit;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -527,27 +522,43 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
} }
} }
continue;
} }
case SHULKER: { case SHULKER: {
if (Settings.Enabled_Components.KILL_ROAD_MOBS) { if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
LivingEntity livingEntity = (LivingEntity) entity; LivingEntity livingEntity = (LivingEntity) entity;
if (entity.hasMetadata("plot")) { List<MetadataValue> meta = entity.getMetadata("plot");
if (!livingEntity.isLeashed() || !entity.hasMetadata("keep")) { if (meta != null && !meta.isEmpty()) {
PlotId originalPlotId = (PlotId) (!entity.getMetadata("plot").isEmpty() ? entity.getMetadata("plot").get(0).value() : null); if (livingEntity.isLeashed()) continue;
PlotId currentPlotId = BukkitUtil.getLocation(entity.getLocation()).getPlot().getId();
if (!currentPlotId.equals(originalPlotId)) {
iterator.remove();
entity.remove();
}
List<MetadataValue> 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 { } else {
if (!entity.hasMetadata("plot")) { //This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java) com.intellectualcrafters.plot.object.Location pLoc = BukkitUtil.getLocation(entity.getLocation());
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, BukkitUtil.getLocation(entity.getLocation()).getPlot().getId())); 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;
} }
} }
} }

View File

@ -1,5 +1,7 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import javax.annotation.Nullable;
public class PlotId { public class PlotId {
/** /**
* x value * 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<br> * Get the PlotId from the HashCode<br>
* Note: Only accurate for small x,z values (short) * Note: Only accurate for small x,z values (short)