Merge pull request #2561 from BentoBoxWorld/2546_Max_homes_limit_for_players_is_the_set_limit_minus_1

Fix for #2546. Default unnamed home was being counted in the number
This commit is contained in:
tastybento 2024-11-23 11:30:54 -08:00 committed by GitHub
commit 8e3a6ab6e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View File

@ -54,7 +54,8 @@ public class IslandSethomeCommand extends ConfirmableCommand {
// 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 ->

View File

@ -940,6 +940,7 @@ public class IslandsManager {
*/
@NonNull
public Map<String, Location> getHomeLocations(@NonNull Island island) {
island.getHomes().forEach((n, l) -> BentoBox.getInstance().logDebug(n));
return island.getHomes();
}
@ -956,6 +957,7 @@ public class IslandsManager {
/**
* 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

View File

@ -201,11 +201,11 @@ public class IslandSethomeCommandTest {
*/
@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 class IslandSethomeCommandTest {
@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"));