mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-06 00:18:36 +01:00
Fixes banlist command number in unlimited case
Added test methods to confirm operation. https://github.com/BentoBoxWorld/BentoBox/issues/1060
This commit is contained in:
parent
55d0920a9c
commit
e511d1b9e9
@ -79,7 +79,7 @@ public class IslandBanlistCommand extends CompositeCommand {
|
||||
lines.forEach(l -> user.sendMessage("commands.island.banlist.names", "[line]", l));
|
||||
|
||||
int banLimit = user.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));
|
||||
if (banLimit <= -1 || island.getBanned().size() < banLimit) {
|
||||
if (banLimit > -1 && island.getBanned().size() < banLimit) {
|
||||
user.sendMessage("commands.island.banlist.you-can-ban", TextVariables.NUMBER, String.valueOf(banLimit - island.getBanned().size()));
|
||||
}
|
||||
return true;
|
||||
|
@ -4,10 +4,12 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -32,6 +34,7 @@ import org.powermock.reflect.Whitebox;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
@ -85,6 +88,7 @@ public class IslandBanlistCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(-1); // Unlimited bans
|
||||
|
||||
// Parent command has no aliases
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
@ -187,4 +191,22 @@ public class IslandBanlistCommandTest {
|
||||
verify(user).sendMessage("commands.island.banlist.the-following");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testBanlistMaxBanNoLimit() {
|
||||
testBanlistBanned();
|
||||
verify(user, never()).sendMessage(eq("commands.island.banlist.you-can-ban"), anyString(), anyString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testBanlistMaxBanLimit() {
|
||||
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(15);
|
||||
testBanlistBanned();
|
||||
verify(user).sendMessage(eq("commands.island.banlist.you-can-ban"), eq(TextVariables.NUMBER), eq("4"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user