diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java index e7e8e1805..6a4f70c7e 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java @@ -112,7 +112,13 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan Player p = (Player) e.getEntity(); // Handle the void - teleport player back to island in a safe spot if(e.getCause().equals(DamageCause.VOID)) { - if (getIslands().getIslandAt(p.getLocation()).isPresent()) { getIslands().getIslandAt(p.getLocation()).ifPresent(i -> new SafeSpotTeleport.Builder(getPlugin()).entity(p).island(i).build()); + if (getIslands().getIslandAt(p.getLocation()).isPresent()) { + getIslands().getIslandAt(p.getLocation()).ifPresent(island -> + // Teleport + new SafeSpotTeleport.Builder(getPlugin()) + .entity(p) + .location(island.getCenter().toVector().toLocation(p.getWorld())) + .build()); } else if (getIslands().hasIsland(p.getWorld(), p.getUniqueId())) { // No island in this location - if the player has an island try to teleport them back getIslands().homeTeleport(p.getWorld(), p); @@ -122,5 +128,7 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan } } } + + } diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java index 2e16b599b..35c2eecc0 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java @@ -27,6 +27,8 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.util.Vector; +import org.eclipse.jdt.annotation.Nullable; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -114,6 +116,11 @@ public class InvincibleVisitorsListenerTest { // Island Manager Island island = mock(Island.class); when(island.getOwner()).thenReturn(uuid); + @Nullable + Location location = mock(Location.class); + Vector vector = mock(Vector.class); + when(location.toVector()).thenReturn(vector); + when(island.getCenter()).thenReturn(location); when(im.getIsland(Mockito.any(World.class), Mockito.any(User.class))).thenReturn(island); optionalIsland = Optional.of(island); // Visitor