Fix for #2279 on-island placeholder for nether and end (#2280)

This commit is contained in:
tastybento 2024-01-21 10:58:53 -08:00 committed by GitHub
parent 90a53e9fd8
commit 5d3821094c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View File

@ -312,7 +312,11 @@ public enum GameModePlaceholder {
* Returns whether this player is on his island and has a rank greater than VISITOR_RANK
* @since 1.13.0
*/
ON_ISLAND("on_island", (addon, user, island) -> String.valueOf(addon.getIslands().userIsOnIsland(addon.getOverWorld(), user))),
ON_ISLAND("on_island",
(addon, user,
island) -> String.valueOf(addon.getIslands().userIsOnIsland(addon.getOverWorld(), user)
|| addon.getIslands().userIsOnIsland(addon.getNetherWorld(), user)
|| addon.getIslands().userIsOnIsland(addon.getEndWorld(), user))),
/**
* Returns whether this player is an owner of their island
* @since 1.14.0

View File

@ -6,6 +6,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Optional;
@ -168,6 +169,40 @@ public class GameModePlaceholderTest {
assertEquals("0", GameModePlaceholder.RESETS_LEFT.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerPlayerOnIsland() {
@Nullable
World netherWorld = mock(World.class);
when(addon.getNetherWorld()).thenReturn(netherWorld);
@Nullable
World endWorld = mock(World.class);
when(addon.getEndWorld()).thenReturn(endWorld);
// Not on island
when(im.userIsOnIsland(world, user)).thenReturn(false);
when(im.userIsOnIsland(netherWorld, user)).thenReturn(false);
when(im.userIsOnIsland(endWorld, user)).thenReturn(false);
assertEquals("false", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island));
// Put player on island
when(im.userIsOnIsland(world, user)).thenReturn(true);
when(im.userIsOnIsland(netherWorld, user)).thenReturn(false);
when(im.userIsOnIsland(endWorld, user)).thenReturn(false);
assertEquals("true", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island));
// Nether
when(im.userIsOnIsland(world, user)).thenReturn(false);
when(im.userIsOnIsland(netherWorld, user)).thenReturn(true);
when(im.userIsOnIsland(endWorld, user)).thenReturn(false);
assertEquals("true", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island));
// End
when(im.userIsOnIsland(world, user)).thenReturn(false);
when(im.userIsOnIsland(netherWorld, user)).thenReturn(false);
when(im.userIsOnIsland(endWorld, user)).thenReturn(true);
assertEquals("true", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/