Handle null users when getting island. Added test case.

A recent change to placeholders meant that it is possible for users to
be null. See https://github.com/BentoBoxWorld/BentoBox/issues/1654
This commit is contained in:
tastybento 2021-02-16 17:15:07 -08:00
parent 69b40ee141
commit 97ac70cea3
2 changed files with 15 additions and 4 deletions

View File

@ -377,11 +377,11 @@ public class IslandsManager {
* If they are in a team, the team island is returned. * If they are in a team, the team island is returned.
* @param world world to check * @param world world to check
* @param user user * @param user user
* @return Island or null * @return Island or null if not found or null user
*/ */
@Nullable @Nullable
public Island getIsland(@NonNull World world, @NonNull User user){ public Island getIsland(@NonNull World world, @Nullable User user){
return islandCache.get(world, user.getUniqueId()); return user == null || user.getUniqueId() == null ? null : getIsland(world, user.getUniqueId());
} }
/** /**

View File

@ -592,6 +592,17 @@ public class IslandsManagerTest {
assertEquals(1, im.getIslandCount()); assertEquals(1, im.getIslandCount());
} }
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIsland(World, User)}
*/
@Test
public void testGetIslandWorldUser() {
IslandsManager im = new IslandsManager(plugin);
Island island = im.createIsland(location, user.getUniqueId());
assertEquals(island, im.getIsland(world, user));
assertNull(im.getIsland(world, (User)null));
}
/** /**
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIsland(World, UUID)}. * Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIsland(World, UUID)}.
*/ */