Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Island> getUsersIsland(User user) {
// Get the active island for the user
Expand All @@ -201,8 +201,14 @@ private Optional<Island> 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<Island> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}.
*/
Expand Down
Loading