From 989778d114d5e1052047511f307c3d1cab4ea777 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 22 Sep 2019 00:18:19 -0600 Subject: [PATCH] Fixed entities targetting other entities outside the border --- .../songoda/skyblock/listeners/Entity.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/com/songoda/skyblock/listeners/Entity.java b/src/main/java/com/songoda/skyblock/listeners/Entity.java index 3be2370f..54963724 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Entity.java +++ b/src/main/java/com/songoda/skyblock/listeners/Entity.java @@ -248,6 +248,37 @@ public class Entity implements Listener { } } + /** + * Checks that an entity is not targeting another entity on different islands. + * @author LimeGlass + */ + @EventHandler + public void onEntityTarget(EntityTargetEvent event) { + org.bukkit.entity.Entity entity = event.getEntity(); + WorldManager worldManager = skyblock.getWorldManager(); + if (!worldManager.isIslandWorld(entity.getWorld())) + return; + + org.bukkit.entity.Entity target = event.getTarget(); + + IslandManager islandManager = skyblock.getIslandManager(); + Island entityIsland = islandManager.getIslandAtLocation(entity.getLocation()); + Island targetIsland = islandManager.getIslandAtLocation(target.getLocation()); + // Event not related to Skyblock islands. + if (entityIsland == null && targetIsland == null) + return; + // One entity is on an island, and the other isn't. + if (entityIsland == null || targetIsland == null) { + event.setCancelled(true); + return; + } + // Both entities are on different islands. + if (!entityIsland.getIslandUUID().equals(targetIsland.getIslandUUID())) { + event.setCancelled(true); + return; + } + } + @EventHandler public void onStackableInteract(PlayerArmorStandManipulateEvent event) { Player player = event.getPlayer();