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.
This commit is contained in:
tastybento 2021-03-17 15:18:55 -07:00
parent b8d9b73103
commit 87bdee0946
2 changed files with 14 additions and 5 deletions

View File

@ -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()}<p>
*
* @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);
}

View File

@ -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()));
}