From 58dfca6a8ddaae395ccb0da1b41f24eba3266e26 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 23 Nov 2024 11:30:36 -0800 Subject: [PATCH] Fix for #2546. Default unnamed home was being counted in the number --- .../bentobox/api/commands/island/IslandSethomeCommand.java | 3 ++- .../world/bentobox/bentobox/managers/IslandsManager.java | 2 ++ .../api/commands/island/IslandSethomeCommandTest.java | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) 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 0db39b132..4b1d1c4ec 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 @@ -54,7 +54,8 @@ public boolean canExecute(User user, String label, List args) { // Check number of homes int maxHomes = getIslands().getMaxHomes(island); - if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes) { + // The + 1 is for the default home + if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes + 1) { user.sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, String.valueOf(maxHomes)); user.sendMessage("commands.island.sethome.homes-are"); getIslands().getIslands(getWorld(), user).forEach(is -> diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index 0452c970c..681fd69e7 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -940,6 +940,7 @@ public boolean renameHomeLocation(@NonNull Island island, @NonNull String oldNam */ @NonNull public Map getHomeLocations(@NonNull Island island) { + island.getHomes().forEach((n, l) -> BentoBox.getInstance().logDebug(n)); return island.getHomes(); } @@ -956,6 +957,7 @@ public boolean isHomeLocation(@NonNull Island island, @NonNull String name) { /** * Get the number of homes on this island if this home were added + * This includes the default home, which has no name * * @param island - island * @param name - name 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 9dd2e46ab..5e2e21460 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 @@ -201,11 +201,11 @@ public void testCanExecuteNotOnIsland() { */ @Test public void testCanExecuteTooManyHomes() { - when(im.getMaxHomes(island)).thenReturn(10); + when(im.getMaxHomes(island)).thenReturn(9); 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.too-many-homes", TextVariables.NUMBER, "9"); verify(user).sendMessage("commands.island.sethome.homes-are"); } @@ -251,7 +251,7 @@ public void testExecuteUserStringListOfStringHomeSuccess() { @Test public void testExecuteUserStringListOfStringMultiHomeTooMany() { when(im.getMaxHomes(island)).thenReturn(3); - when(im.getNumberOfHomesIfAdded(eq(island), anyString())).thenReturn(4); + when(im.getNumberOfHomesIfAdded(eq(island), anyString())).thenReturn(5); IslandSethomeCommand isc = new IslandSethomeCommand(ic); assertFalse(isc.canExecute(user, "island", Collections.singletonList("13"))); verify(user).sendMessage(eq("commands.island.sethome.too-many-homes"), eq("[number]"), eq("3"));