From eef3dcbc468491ffe2b4dfaa520f02efbb22963a Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 13 Mar 2024 17:58:28 -0700 Subject: [PATCH] Allow the maxhomes to apply per island. --- .../api/commands/island/IslandSethomeCommand.java | 2 +- .../commands/island/IslandSethomeCommandTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java index 9ccde2194..0db39b132 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommand.java @@ -53,7 +53,7 @@ public class IslandSethomeCommand extends ConfirmableCommand { // Check number of homes - int maxHomes = getIslands().getIslands(getWorld(), user).stream().mapToInt(getIslands()::getMaxHomes).sum(); + int maxHomes = getIslands().getMaxHomes(island); if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes) { user.sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, String.valueOf(maxHomes)); user.sendMessage("commands.island.sethome.homes-are"); diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java index fccdd060b..c80f05563 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java @@ -37,6 +37,7 @@ import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.configuration.WorldSettings; +import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.managers.CommandsManager; @@ -195,6 +196,20 @@ public class IslandSethomeCommandTest { verify(user).sendMessage("commands.island.sethome.must-be-on-your-island"); } + /** + * Test method for + * {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. + */ + @Test + public void testCanExecuteTooManyHomes() { + when(im.getMaxHomes(island)).thenReturn(10); + when(im.getNumberOfHomesIfAdded(eq(island), anyString())).thenReturn(11); + IslandSethomeCommand isc = new IslandSethomeCommand(ic); + assertFalse(isc.canExecute(user, "island", Collections.emptyList())); + verify(user).sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, "10"); + verify(user).sendMessage("commands.island.sethome.homes-are"); + } + /** * Test method for * {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.