Merge pull request #2321 from BentoBoxWorld/max_islands_per_island

Allow the maxhomes to apply per island.
This commit is contained in:
tastybento 2024-03-13 18:01:18 -07:00 committed by GitHub
commit 6fccf80477
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -53,7 +53,7 @@ public class IslandSethomeCommand extends ConfirmableCommand {
// Check number of homes // 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) { 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.too-many-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
user.sendMessage("commands.island.sethome.homes-are"); user.sendMessage("commands.island.sethome.homes-are");

View File

@ -37,6 +37,7 @@ import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.configuration.WorldSettings; 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.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.CommandsManager;
@ -195,6 +196,20 @@ public class IslandSethomeCommandTest {
verify(user).sendMessage("commands.island.sethome.must-be-on-your-island"); 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 * Test method for
* {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.