From 2f5e6665f7eefb705cc57af90c452f54c62a8fcf Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Wed, 9 Feb 2022 19:23:40 +0100 Subject: [PATCH] fix: Don't teleport shulkers on the road --- .../bukkit/listener/EntitySpawnListener.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java index d7e06d63e..f47155124 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java @@ -36,6 +36,7 @@ import com.plotsquared.core.plot.flag.implementations.DoneFlag; import io.papermc.lib.PaperLib; import org.bukkit.Chunk; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -191,8 +192,32 @@ public class EntitySpawnListener implements Listener { @EventHandler public void onTeleport(EntityTeleportEvent event) { - Entity ent = event.getEntity(); - if (ent instanceof Vehicle || ent instanceof ArmorStand) { + Entity entity = event.getEntity(); + Entity fromLocation = event.getEntity(); + Block toLocation = event.getTo().getBlock(); + final Location fromLocLocation = BukkitUtil.adapt(fromLocation.getLocation()); + final PlotArea fromArea = fromLocLocation.getPlotArea(); + Location toLocLocation = BukkitUtil.adapt(toLocation.getLocation()); + PlotArea area = toLocLocation.getPlotArea(); + + if (area == null) { + if (fromLocation.getType() == EntityType.SHULKER && fromArea != null) { + event.setCancelled(true); + } + return; + } + Plot plot = area.getOwnedPlot(toLocLocation); + if (fromLocation.getType() == EntityType.SHULKER && fromArea != null) { + final Plot fromPlot = fromArea.getOwnedPlot(fromLocLocation); + + if (fromPlot != null || plot != null) { + if ((fromPlot == null || !fromPlot.equals(plot)) && (plot == null || !plot.equals(fromPlot))) { + event.setCancelled(true); + return; + } + } + } + if (entity instanceof Vehicle || entity instanceof ArmorStand) { testNether(event.getEntity()); } }