mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-25 01:21:21 +01:00
Allows island team members as well as the owner to see the ban list
https://github.com/BentoBoxWorld/BentoBox/issues/891
This commit is contained in:
parent
21b7ce4b75
commit
e86fb09cf9
@ -28,11 +28,11 @@ public class IslandBanlistCommand extends CompositeCommand {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
}
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId()) && !getIslands().inTeam(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
// Show all the players banned on the island
|
||||
|
@ -1,11 +1,11 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
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;
|
||||
@ -22,7 +22,7 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
@ -47,11 +47,16 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandBanlistCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
@Mock
|
||||
private Island island;
|
||||
|
||||
/**
|
||||
@ -74,7 +79,6 @@ public class IslandBanlistCommandTest {
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
@ -82,19 +86,16 @@ public class IslandBanlistCommandTest {
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(CompositeCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ic.getTopLabel()).thenReturn("island");
|
||||
|
||||
// No island for player to begin with (set it later in the tests)
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.hasIsland(any(), eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(any(), eq(uuid))).thenReturn(false);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
@ -103,20 +104,19 @@ public class IslandBanlistCommandTest {
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
// Island Banned list initialization
|
||||
island = mock(Island.class);
|
||||
when(island.getBanned()).thenReturn(new HashSet<>());
|
||||
when(island.isBanned(Mockito.any())).thenReturn(false);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
when(island.isBanned(any())).thenReturn(false);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||
|
||||
// IWM friendly name
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for .
|
||||
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testWithArgs() {
|
||||
@ -125,25 +125,36 @@ public class IslandBanlistCommandTest {
|
||||
// Verify show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandBanlistCommand#execute(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<>()));
|
||||
Mockito.verify(user).sendMessage("general.errors.no-island");
|
||||
verify(user).sendMessage("general.errors.no-island");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testBanlistNooneBanned() {
|
||||
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
|
||||
assertTrue(iubc.execute(user, iubc.getLabel(), new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage("commands.island.banlist.noone");
|
||||
verify(user).sendMessage("commands.island.banlist.noone");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandBanlistCommand#execute(User, String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testBanlistBanned() {
|
||||
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
|
||||
// Make a ban list
|
||||
String[] names = {"adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry", "ian", "joe"};
|
||||
Set<UUID> banned = new HashSet<>();
|
||||
@ -155,9 +166,9 @@ public class IslandBanlistCommandTest {
|
||||
}
|
||||
when(island.getBanned()).thenReturn(banned);
|
||||
// Respond to name queries
|
||||
when(pm.getName(Mockito.any(UUID.class))).then((Answer<String>) invocation -> uuidToName.getOrDefault(invocation.getArgument(0, UUID.class), "tastybento"));
|
||||
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<>()));
|
||||
Mockito.verify(user).sendMessage("commands.island.banlist.the-following");
|
||||
verify(user).sendMessage("commands.island.banlist.the-following");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user