Skip to content

Commit

Permalink
Pegs banlist command to same rank level as ban command
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 13, 2019
1 parent e86fb09 commit fb16930
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

public class IslandBanlistCommand extends CompositeCommand {

private Island island;

public IslandBanlistCommand(CompositeCommand islandCommand) {
super(islandCommand, "banlist", "banned", "bans");
}
Expand All @@ -23,7 +25,7 @@ public void setup() {
}

@Override
public boolean execute(User user, String label, List<String> args) {
public boolean canExecute(User user, String label, List<String> args) {
if (!args.isEmpty()) {
// Show help
showHelp(this, user);
Expand All @@ -34,7 +36,17 @@ public boolean execute(User user, String label, List<String> args) {
user.sendMessage("general.errors.no-island");
return false;
}
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
// Check rank to use command
island = getIslands().getIsland(getWorld(), user.getUniqueId());
if (island.getRank(user) < island.getRankCommand("ban")) {
user.sendMessage("general.errors.no-permission");
return false;
}
return true;
}

@Override
public boolean execute(User user, String label, List<String> args) {
// Show all the players banned on the island
if (island.getBanned().isEmpty()) {
user.sendMessage("commands.island.banlist.noone");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,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.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -38,6 +38,7 @@
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;

/**
* @author tastybento
Expand Down Expand Up @@ -116,35 +117,49 @@ public void setUp() throws Exception {
}

/**
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
* Test method for {@link IslandBanlistCommand#canExecute(User, String, java.util.List)}.
*/
@Test
public void testWithArgs() {
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
assertFalse(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill")));
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.singletonList("bill")));
// Verify show help
verify(user).sendMessage("commands.help.header", "[label]", null);
}

/**
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
* Test method for {@link IslandBanlistCommand#canExecute(User, String, java.util.List)}.
*/
@Test
public void testNoIsland() {
// not in team
when(im.inTeam(any(), eq(uuid))).thenReturn(false);
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
assertFalse(iubc.execute(user, iubc.getLabel(), new ArrayList<>()));
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.emptyList()));
verify(user).sendMessage("general.errors.no-island");
}

/**
* Test method for {@link IslandBanlistCommand#canExecute(User, String, java.util.List)}.
*/
@Test
public void testTooLowRank() {
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.emptyList()));
verify(user).sendMessage("general.errors.no-permission");
}

/**
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
*/
@Test
public void testBanlistNooneBanned() {
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
assertTrue(iubc.execute(user, iubc.getLabel(), new ArrayList<>()));
iubc.canExecute(user, iubc.getLabel(), Collections.emptyList());
assertTrue(iubc.execute(user, iubc.getLabel(), Collections.emptyList()));
verify(user).sendMessage("commands.island.banlist.noone");
}

Expand All @@ -167,7 +182,8 @@ public void testBanlistBanned() {
when(island.getBanned()).thenReturn(banned);
// Respond to name queries
when(pm.getName(any(UUID.class))).then((Answer<String>) invocation -> uuidToName.getOrDefault(invocation.getArgument(0, UUID.class), "tastybento"));
assertTrue(iubc.execute(user, iubc.getLabel(), new ArrayList<>()));
iubc.canExecute(user, iubc.getLabel(), Collections.emptyList());
assertTrue(iubc.execute(user, iubc.getLabel(), Collections.emptyList()));
verify(user).sendMessage("commands.island.banlist.the-following");
}

Expand Down

0 comments on commit fb16930

Please sign in to comment.