diff --git a/src/main/java/world/bentobox/aoneblock/AOneBlockPlaceholders.java b/src/main/java/world/bentobox/aoneblock/AOneBlockPlaceholders.java index 431e6b4..e70439a 100644 --- a/src/main/java/world/bentobox/aoneblock/AOneBlockPlaceholders.java +++ b/src/main/java/world/bentobox/aoneblock/AOneBlockPlaceholders.java @@ -64,11 +64,11 @@ public AOneBlockPlaceholders(AOneBlock addon, } /** - * Get the user's owned island. Returns the island owned by the user, not a team - * island they may be visiting as a member. If the user owns more than one island, - * one is picked. + * Get the user's island. Prefers an island the user owns; if they own none, + * falls back to the team island they are a member of. If the user owns more + * than one island, one is picked. * @param user user - * @return island owned by the user, or empty if they own none + * @return island owned by the user, or their team island, or empty if neither exists */ private Optional getUsersIsland(User user) { // Get the active island for the user @@ -78,8 +78,14 @@ private Optional getUsersIsland(User user) { return Optional.of(i); } - // Find an island the user actually owns (not just a team island they are visiting) - return addon.getIslands().getOwnedIslands(addon.getOverWorld(), user).stream().findFirst(); + // Prefer an island the user actually owns (not just a team island they are a member of) + Optional owned = addon.getIslands().getOwnedIslands(addon.getOverWorld(), user).stream().findFirst(); + if (owned.isPresent()) { + return owned; + } + + // Fall back to the team island the user is a member of, if any + return Optional.ofNullable(i); } public String getPhaseBlocksNames(User user) { diff --git a/src/test/java/world/bentobox/aoneblock/PlaceholdersManagerTest.java b/src/test/java/world/bentobox/aoneblock/PlaceholdersManagerTest.java index 93c67bd..042dbed 100644 --- a/src/test/java/world/bentobox/aoneblock/PlaceholdersManagerTest.java +++ b/src/test/java/world/bentobox/aoneblock/PlaceholdersManagerTest.java @@ -271,6 +271,27 @@ void testGetLifetimeTeamMember() { assertEquals("1000", pm.getLifetime(user)); } + /** + * Test that my_island_* placeholders fall back to the team island for a team + * member who owns no island of their own. See issue #559. + */ + @Test + void testTeamMemberWithoutOwnedIsland() { + when(user.getUniqueId()).thenReturn(uuid); + // The team island is owned by someone else + Island teamIsland = mock(Island.class); + when(teamIsland.getOwner()).thenReturn(UUID.randomUUID()); + when(im.getIsland(world, user)).thenReturn(teamIsland); + // The user owns no island of their own + when(im.getOwnedIslands(world, user)).thenReturn(Set.of()); + // Placeholders should show the team island's data, not the defaults + assertEquals("first", pm.getPhase(user)); + assertEquals("1000", pm.getCount(user)); + assertEquals("70%", pm.getPercentDone(user)); + assertEquals("next_phase", pm.getNextPhase(user)); + assertEquals("1000", pm.getLifetime(user)); + } + /** * Test method for {@link world.bentobox.aoneblock.AOneBlockPlaceholders#getLifetimeByLocation(world.bentobox.bentobox.api.user.User)}. */