From 4a972a86aeafba9783faf67581f73adba0a96cd9 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 28 Sep 2024 16:02:11 -0700 Subject: [PATCH] Add placeholders. Put in defensive code against nulls. --- .../commands/admin/AdminMaxHomesCommand.java | 1 + .../bentobox/lists/GameModePlaceholder.java | 19 +++++++ .../bentobox/bentobox/util/IslandInfo.java | 4 +- .../admin/DefaultAdminCommandTest.java | 55 +++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/test/java/world/bentobox/bentobox/api/commands/admin/DefaultAdminCommandTest.java diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminMaxHomesCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminMaxHomesCommand.java index eda3f8f09..8f38bf4d4 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminMaxHomesCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminMaxHomesCommand.java @@ -27,6 +27,7 @@ import world.bentobox.bentobox.util.Util; * * * @author tastybento + * @since 2.6.0 */ public class AdminMaxHomesCommand extends ConfirmableCommand { diff --git a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java index 032617d26..03b67d59b 100644 --- a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java +++ b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java @@ -157,6 +157,15 @@ public enum GameModePlaceholder { * @since 1.5.0 */ ISLAND_VISITORS_COUNT("island_visitors_count", (addon, user, island) -> island == null ? "" : String.valueOf(island.getVisitors().size())), + /** + * Returns the amount of players that are at least MEMBER on the island the player is standing on. + * @since 2.6.0 + */ + ISLAND_MAX_HOMES("island_max_homes", + (addon, user, island) -> island == null ? "" + : String.valueOf( + island.getMaxHomes() == null ? addon.getPlugin().getIWM().getMaxHomes(island.getWorld()) + : island.getMaxHomes())), /** * Returns the amount of players banned from the island. * @since 1.5.0 @@ -281,6 +290,16 @@ public enum GameModePlaceholder { */ VISITED_ISLAND_MEMBERS_COUNT("visited_island_members_count", (addon, user, island) -> getVisitedIsland(addon, user).map(value -> String.valueOf(value.getMemberSet().size())).orElse("")), + /** + * Returns the amount of players that are at least MEMBER on the island the player is standing on. + * @since 2.6.0 + */ + VISITED_ISLAND_MAX_HOMES("visited_island_max_homes", + (addon, user, + island) -> getVisitedIsland(addon, user).map(value -> String.valueOf( + island.getMaxHomes() == null ? addon.getPlugin().getIWM().getMaxHomes(island.getWorld()) + : island.getMaxHomes())) + .orElse("")), /** * Returns the amount of players that are TRUSTED on the island the player is standing on. * @since 1.5.2 diff --git a/src/main/java/world/bentobox/bentobox/util/IslandInfo.java b/src/main/java/world/bentobox/bentobox/util/IslandInfo.java index f7a0eecc7..909262f44 100644 --- a/src/main/java/world/bentobox/bentobox/util/IslandInfo.java +++ b/src/main/java/world/bentobox/bentobox/util/IslandInfo.java @@ -143,7 +143,9 @@ public class IslandInfo { // Show team members showMembers(user); } - user.sendMessage("commands.admin.info.max-homes", TextVariables.NUMBER, String.valueOf(island.getMaxHomes())); + int maxHomes = island.getMaxHomes() == null ? plugin.getIWM().getMaxHomes(island.getWorld()) + : island.getMaxHomes(); + user.sendMessage("commands.admin.info.max-homes", TextVariables.NUMBER, String.valueOf(maxHomes)); Vector location = island.getProtectionCenter().toVector(); user.sendMessage("commands.admin.info.island-center", TextVariables.XYZ, Util.xyz(location)); user.sendMessage("commands.admin.info.protection-range", RANGE, String.valueOf(island.getProtectionRange())); diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/DefaultAdminCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/DefaultAdminCommandTest.java new file mode 100644 index 000000000..26909309b --- /dev/null +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/DefaultAdminCommandTest.java @@ -0,0 +1,55 @@ +/** + * + */ +package world.bentobox.bentobox.api.commands.admin; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * + */ +public class DefaultAdminCommandTest { + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand#DefaultAdminCommand(world.bentobox.bentobox.api.addons.GameModeAddon)}. + */ + @Test + public void testDefaultAdminCommand() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand#setup()}. + */ + @Test + public void testSetup() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. + */ + @Test + public void testExecuteUserStringListOfString() { + fail("Not yet implemented"); + } + +}