From 5d3821094cf0c164194c455ff384b58d397e40df Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 21 Jan 2024 10:58:53 -0800 Subject: [PATCH] Fix for #2279 on-island placeholder for nether and end (#2280) --- .../bentobox/lists/GameModePlaceholder.java | 6 +++- .../lists/GameModePlaceholderTest.java | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java index 06662819f..2e74d6440 100644 --- a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java +++ b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java @@ -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 diff --git a/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java b/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java index 57e3da44b..7d00eccdd 100644 --- a/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java +++ b/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java @@ -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()}. */