Skip to content

Commit

Permalink
Merge pull request #2561 from BentoBoxWorld/2546_Max_homes_limit_for_…
Browse files Browse the repository at this point in the history
…players_is_the_set_limit_minus_1

Fix for #2546. Default unnamed home was being counted in the number
  • Loading branch information
tastybento authored Nov 23, 2024
2 parents 02d69b8 + 58dfca6 commit 8e3a6ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public boolean canExecute(User user, String label, List<String> 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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ public boolean renameHomeLocation(@NonNull Island island, @NonNull String oldNam
*/
@NonNull
public Map<String, Location> getHomeLocations(@NonNull Island island) {
island.getHomes().forEach((n, l) -> BentoBox.getInstance().logDebug(n));
return island.getHomes();
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 8e3a6ab

Please sign in to comment.