From 87bdee0946a4aa311ac5f6f6cfcca1ede4090c0d Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 17 Mar 2021 15:18:55 -0700 Subject: [PATCH] Return island protection center instead of island logical center IslandsManager.getIslandLocation(world, uuid) is used to find the starting point for the island home if a safe home for players cannot be found. It returns the island center location but should return the center of the island protection because that can now be in a different location. --- .../bentobox/bentobox/managers/IslandsManager.java | 14 ++++++++++---- .../bentobox/managers/IslandsManagerTest.java | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index 32b8bfd7c..bc0bfb1d8 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -448,19 +448,25 @@ public class IslandsManager { } /** - * Returns the player's island location in World - * Returns an island location OR a team island location + * Returns the player's island location in World based on the island protection center. + * If you need the actual island center location for some reason use {@link Island#getCenter()}

* * @param world - world to check * @param uuid - the player's UUID - * @return Location of player's island or null if one does not exist + * @return Location of the center of the player's protection area or null if an island does not exist. + * Returns an island location OR a team island location */ @Nullable public Location getIslandLocation(@NonNull World world, @NonNull UUID uuid) { Island island = getIsland(world, uuid); - return island != null ? island.getCenter() : null; + return island != null ? island.getProtectionCenter() : null; } + /** + * Get the last location where an island was created + * @param world - world + * @return location + */ public Location getLast(@NonNull World world) { return last.get(world); } diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java index 63e6e9639..b52339032 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java @@ -238,6 +238,8 @@ public class IslandsManagerTest { when(island.getWorld()).thenReturn(world); when(island.getMaxMembers()).thenReturn(null); // default when(island.getMaxMembers(Mockito.anyInt())).thenReturn(null); // default + when(island.getCenter()).thenReturn(location); + when(island.getProtectionCenter()).thenReturn(location); // Mock island cache when(islandCache.getIslandAt(any(Location.class))).thenReturn(island); @@ -630,8 +632,9 @@ public class IslandsManagerTest { */ @Test public void testGetIslandLocation() { - im.createIsland(location, uuid); + Island i = im.createIsland(location, uuid); assertEquals(world, im.getIslandLocation(world, uuid).getWorld()); + assertEquals(i.getProtectionCenter(), im.getIslandLocation(world, uuid)); assertNull(im.getIslandLocation(world, UUID.randomUUID())); }