From c0ece6c7ecbf964f0d0dd703fb557a0e4e84165b Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 28 Aug 2026 17:40:41 -0700 Subject: [PATCH] fix: my_island placeholders fall back to team island for members The my_island_* placeholder lookup only resolved islands the player owns, so plain team members (who own no island) got the empty defaults (0, 0%, Unknown). Prefer an owned island as before, but fall back to the team island the player is a member of when they own none. Same fix as BentoBoxWorld/AOneBlock#560 (this code was forked from AOneBlock). See BentoBoxWorld/AOneBlock#559. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01PtmXKNJ5fSZ9sEumeFDEBc --- .../chunkblock/ChunkBlockPlaceholders.java | 18 ++++++++++------ .../chunkblock/PlaceholdersManagerTest.java | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/chunkblock/ChunkBlockPlaceholders.java b/src/main/java/world/bentobox/chunkblock/ChunkBlockPlaceholders.java index 14ea94d..eae9367 100644 --- a/src/main/java/world/bentobox/chunkblock/ChunkBlockPlaceholders.java +++ b/src/main/java/world/bentobox/chunkblock/ChunkBlockPlaceholders.java @@ -187,11 +187,11 @@ public String getNextRingRemaining(User user) { } /** - * 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 @@ -201,8 +201,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/chunkblock/PlaceholdersManagerTest.java b/src/test/java/world/bentobox/chunkblock/PlaceholdersManagerTest.java index 783f884..670be6a 100644 --- a/src/test/java/world/bentobox/chunkblock/PlaceholdersManagerTest.java +++ b/src/test/java/world/bentobox/chunkblock/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 AOneBlock 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.chunkblock.ChunkBlockPlaceholders#getLifetimeByLocation(world.bentobox.bentobox.api.user.User)}. */