Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #2546. Default unnamed home was being counted in the number #2561

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading