mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-10 02:19:30 +01:00
Added insufficient rank error and fixed tests.
The no permission error was being added, but thats wrong because it's not lack of permission but lack of rank that is the issue. This adds a new error and shows it in the various commands.
This commit is contained in:
parent
9a7ded8136
commit
0fec5aec51
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -51,8 +52,9 @@ public class IslandBanCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
@ -38,8 +39,9 @@ public class IslandBanlistCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island.getRank(user) < island.getRankCommand("ban")) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
@ -52,8 +53,9 @@ public class IslandExpelCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -48,8 +49,9 @@ public class IslandUnbanCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -52,8 +53,9 @@ public class IslandTeamCoopCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -44,8 +45,9 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -42,8 +43,9 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// If args are not right, show help
|
||||
@ -133,12 +135,12 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.build();
|
||||
IslandEvent.builder()
|
||||
.island(oldIsland)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(oldIsland.getRank(user), RanksManager.VISITOR_RANK)
|
||||
.build();
|
||||
.island(oldIsland)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(oldIsland.getRank(user), RanksManager.VISITOR_RANK)
|
||||
.build();
|
||||
|
||||
// Add cooldown for this player and target
|
||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
@ -37,8 +38,9 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -77,12 +79,12 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank));
|
||||
user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||
IslandEvent.builder()
|
||||
.island(island)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(currentRank, nextRank)
|
||||
.build();
|
||||
.island(island)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(currentRank, nextRank)
|
||||
.build();
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.promote.failure");
|
||||
@ -97,12 +99,12 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank));
|
||||
user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||
IslandEvent.builder()
|
||||
.island(island)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(currentRank, prevRank)
|
||||
.build();
|
||||
.island(island)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(currentRank, prevRank)
|
||||
.build();
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.demote.failure");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -52,8 +53,9 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
@ -72,7 +74,7 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
int rank = getIslands().getIsland(getWorld(), user).getRank(target);
|
||||
rank = getIslands().getIsland(getWorld(), user).getRank(target);
|
||||
if (rank >= RanksManager.TRUSTED_RANK) {
|
||||
user.sendMessage("commands.island.team.trust.player-already-trusted");
|
||||
return false;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -50,8 +51,9 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
@ -91,12 +93,12 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
|
||||
subCommand.setCooldown(island.getUniqueId(), targetUUID.toString(), getSettings().getCoopCooldown() * 60));
|
||||
}
|
||||
IslandEvent.builder()
|
||||
.island(island)
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(RanksManager.COOP_RANK, RanksManager.VISITOR_RANK)
|
||||
.build();
|
||||
.island(island)
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(RanksManager.COOP_RANK, RanksManager.VISITOR_RANK)
|
||||
.build();
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -50,8 +51,9 @@ public class IslandTeamUntrustCommand extends CompositeCommand {
|
||||
}
|
||||
// Check rank to use command
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island.getRank(user) < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
int rank = Objects.requireNonNull(island).getRank(user);
|
||||
if (rank < island.getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
@ -91,12 +93,12 @@ public class IslandTeamUntrustCommand extends CompositeCommand {
|
||||
subCommand.setCooldown(island.getUniqueId(), targetUUID.toString(), getSettings().getTrustCooldown() * 60));
|
||||
}
|
||||
IslandEvent.builder()
|
||||
.island(island)
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(RanksManager.TRUSTED_RANK, RanksManager.VISITOR_RANK)
|
||||
.build();
|
||||
.island(island)
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE)
|
||||
.rankChange(RanksManager.TRUSTED_RANK, RanksManager.VISITOR_RANK)
|
||||
.build();
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
|
@ -19,6 +19,7 @@ general:
|
||||
errors:
|
||||
command-cancelled: "&c Command cancelled."
|
||||
no-permission: "&c You don't have the permission to execute this command (&7 [permission]&c )."
|
||||
insufficient-rank: "&c Your rank is not high enough to do that! (&7 [rank]&c )"
|
||||
use-in-game: "&c This command is only available in game."
|
||||
no-team: "&c You do not have a team!"
|
||||
no-island: "&c You do not have an island!"
|
||||
|
@ -9,6 +9,7 @@ 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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -79,6 +80,8 @@ public class IslandBanCommandTest {
|
||||
@Mock
|
||||
private Player targetPlayer;
|
||||
|
||||
private RanksManager rm;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
@ -103,6 +106,7 @@ public class IslandBanCommandTest {
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(-1);
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Parent command has no aliases
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
@ -143,7 +147,7 @@ public class IslandBanCommandTest {
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||
when(lm.get(any(), any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
||||
when(phm.replacePlaceholders(any(), any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||
@ -152,14 +156,18 @@ public class IslandBanCommandTest {
|
||||
|
||||
// Target bill - default target. Non Op, online, no ban prevention permission
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
when(targetPlayer.getName()).thenReturn("bill");
|
||||
when(targetPlayer.getUniqueId()).thenReturn(uuid);
|
||||
when(targetPlayer.isOp()).thenReturn(false);
|
||||
when(targetPlayer.isOnline()).thenReturn(true);
|
||||
when(targetPlayer.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||
when(targetPlayer.hasPermission(anyString())).thenReturn(false);
|
||||
User.getInstance(targetPlayer);
|
||||
|
||||
// Ranks Manager
|
||||
rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
// Island Ban Command
|
||||
ibc = new IslandBanCommand(ic);
|
||||
|
||||
@ -208,7 +216,7 @@ public class IslandBanCommandTest {
|
||||
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user).sendMessage("general.errors.no-permission");
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -220,7 +228,7 @@ public class IslandBanCommandTest {
|
||||
|
||||
@Test
|
||||
public void testBanSelf() {
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||
when(pm.getUUID(anyString())).thenReturn(uuid);
|
||||
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user).sendMessage("commands.island.ban.cannot-ban-yourself");
|
||||
}
|
||||
@ -228,7 +236,7 @@ public class IslandBanCommandTest {
|
||||
@Test
|
||||
public void testBanTeamMate() {
|
||||
UUID teamMate = UUID.randomUUID();
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(teamMate);
|
||||
when(pm.getUUID(anyString())).thenReturn(teamMate);
|
||||
Set<UUID> members = new HashSet<>();
|
||||
members.add(uuid);
|
||||
members.add(teamMate);
|
||||
@ -240,7 +248,7 @@ public class IslandBanCommandTest {
|
||||
@Test
|
||||
public void testBanAlreadyBanned() {
|
||||
UUID bannedUser = UUID.randomUUID();
|
||||
when(pm.getUUID(Mockito.anyString())).thenReturn(bannedUser);
|
||||
when(pm.getUUID(anyString())).thenReturn(bannedUser);
|
||||
when(island.isBanned(eq(bannedUser))).thenReturn(true);
|
||||
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user).sendMessage("commands.island.ban.player-already-banned");
|
||||
@ -255,7 +263,7 @@ public class IslandBanCommandTest {
|
||||
|
||||
@Test
|
||||
public void testBanOnlineNoBanPermission() {
|
||||
when(targetPlayer.hasPermission(Mockito.anyString())).thenReturn(true);
|
||||
when(targetPlayer.hasPermission(anyString())).thenReturn(true);
|
||||
User.getInstance(targetPlayer);
|
||||
|
||||
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("billy")));
|
||||
@ -295,8 +303,8 @@ public class IslandBanCommandTest {
|
||||
when(island.ban(any(), any())).thenReturn(false);
|
||||
|
||||
assertFalse(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user, Mockito.never()).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, targetPlayer.getName());
|
||||
verify(targetPlayer, Mockito.never()).sendMessage("commands.island.ban.owner-banned-you");
|
||||
verify(user, never()).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, targetPlayer.getName());
|
||||
verify(targetPlayer, never()).sendMessage("commands.island.ban.owner-banned-you");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -91,6 +91,7 @@ public class IslandBanlistCommandTest {
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(-1); // Unlimited bans
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Parent command has no aliases
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
@ -120,6 +121,10 @@ public class IslandBanlistCommandTest {
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
@ -135,7 +140,7 @@ public class IslandBanlistCommandTest {
|
||||
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
|
||||
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.singletonList("bill")));
|
||||
// Verify show help
|
||||
verify(user).sendMessage("commands.help.header", "[label]", null);
|
||||
verify(user).sendMessage("commands.help.header", "[label]", "commands.help.console");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +164,7 @@ public class IslandBanlistCommandTest {
|
||||
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");
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,6 +108,7 @@ public class IslandExpelCommandTest {
|
||||
when(p.getServer()).thenReturn(server);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Parent command has no aliases
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
@ -153,6 +154,10 @@ public class IslandExpelCommandTest {
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
|
||||
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
// Class
|
||||
iec = new IslandExpelCommand(ic);
|
||||
}
|
||||
@ -192,7 +197,7 @@ public class IslandExpelCommandTest {
|
||||
@Test
|
||||
public void testCanExecuteNoArgs() {
|
||||
assertFalse(iec.canExecute(user, "", Collections.emptyList()));
|
||||
verify(user).sendMessage("commands.help.header", "[label]", null);
|
||||
verify(user).sendMessage("commands.help.header", "[label]", "commands.help.console");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,7 +206,7 @@ public class IslandExpelCommandTest {
|
||||
@Test
|
||||
public void testCanExecuteTooManyArgs() {
|
||||
assertFalse(iec.canExecute(user, "", Arrays.asList("Hello", "there")));
|
||||
verify(user).sendMessage("commands.help.header", "[label]", null);
|
||||
verify(user).sendMessage("commands.help.header", "[label]", "commands.help.console");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,7 +248,7 @@ public class IslandExpelCommandTest {
|
||||
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
|
||||
verify(user).sendMessage("general.errors.no-permission");
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.visitor"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,6 +94,7 @@ public class IslandUnbanCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Parent command has no aliases
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
@ -128,6 +129,11 @@ public class IslandUnbanCommandTest {
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
@ -177,7 +183,7 @@ public class IslandUnbanCommandTest {
|
||||
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user).sendMessage("general.errors.no-permission");
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,6 +96,7 @@ public class IslandTeamCoopCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
@ -139,6 +140,11 @@ public class IslandTeamCoopCommandTest {
|
||||
when(phm.replacePlaceholders(any(), any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||
// Placeholder manager
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
@ -167,7 +173,7 @@ public class IslandTeamCoopCommandTest {
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user).sendMessage(eq("general.errors.no-permission"));
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,6 +103,7 @@ public class IslandTeamInviteCommandTest {
|
||||
// Permission to invite 3 more players
|
||||
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3);
|
||||
when(User.getInstance(eq(uuid))).thenReturn(user);
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
User.setPlugin(plugin);
|
||||
// Target
|
||||
@ -145,7 +146,7 @@ public class IslandTeamInviteCommandTest {
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
when(lm.get(any(), any())).thenReturn(null);
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// IWM friendly name
|
||||
@ -156,6 +157,10 @@ public class IslandTeamInviteCommandTest {
|
||||
// Parent command
|
||||
when(ic.getTopLabel()).thenReturn("island");
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
// Command under test
|
||||
itl = new IslandTeamInviteCommand(ic);
|
||||
|
||||
@ -191,7 +196,7 @@ public class IslandTeamInviteCommandTest {
|
||||
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("target")));
|
||||
verify(user).sendMessage(eq("general.errors.no-permission"));
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,7 +218,7 @@ public class IslandTeamInviteCommandTest {
|
||||
public void testCanExecuteNoTarget() {
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
|
||||
// Show help
|
||||
verify(user).sendMessage(eq("commands.help.header"),eq(TextVariables.LABEL),eq(null));
|
||||
verify(user).sendMessage(eq("commands.help.header"),eq(TextVariables.LABEL),eq("commands.help.console"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,6 +114,7 @@ public class IslandTeamKickCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(player);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
@ -173,6 +174,10 @@ public class IslandTeamKickCommandTest {
|
||||
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.VISITOR_RANK);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
@ -256,7 +261,7 @@ public class IslandTeamKickCommandTest {
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(user).sendMessage(eq("general.errors.no-permission"));
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.visitor"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,6 +100,7 @@ public class IslandTeamTrustCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
User.setPlugin(plugin);
|
||||
// Target player
|
||||
when(targetPlayer.getUniqueId()).thenReturn(notUUID);
|
||||
@ -146,6 +147,11 @@ public class IslandTeamTrustCommandTest {
|
||||
when(phm.replacePlaceholders(any(), any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||
// Placeholder manager
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
@ -174,7 +180,7 @@ public class IslandTeamTrustCommandTest {
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user).sendMessage(eq("general.errors.no-permission"));
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,6 +38,7 @@ import com.google.common.collect.ImmutableSet.Builder;
|
||||
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;
|
||||
@ -94,6 +95,8 @@ public class IslandTeamUncoopCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
@ -134,6 +137,11 @@ public class IslandTeamUncoopCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,7 +165,7 @@ public class IslandTeamUncoopCommandTest {
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
verify(user).sendMessage(eq("general.errors.no-permission"));
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,9 @@ package world.bentobox.bentobox.api.commands.island.team;
|
||||
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;
|
||||
@ -24,7 +26,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -36,6 +37,7 @@ import com.google.common.collect.ImmutableSet.Builder;
|
||||
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;
|
||||
@ -92,6 +94,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
@ -111,7 +114,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
when(im.inTeam(any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
|
||||
// Player Manager
|
||||
pm = mock(PlayersManager.class);
|
||||
@ -132,6 +135,11 @@ public class IslandTeamUntrustCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Ranks Manager
|
||||
RanksManager rm = new RanksManager();
|
||||
when(plugin.getRanksManager()).thenReturn(rm);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,7 +151,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
verify(user).sendMessage(eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +163,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
when(island.getRankCommand(any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,7 +184,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +198,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.untrust.cannot-untrust-yourself"));
|
||||
verify(user).sendMessage(eq("commands.island.team.untrust.cannot-untrust-yourself"));
|
||||
}
|
||||
|
||||
|
||||
@ -207,7 +215,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
when(im.getMembers(any(), any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.untrust.cannot-untrust-member"));
|
||||
verify(user).sendMessage(eq("commands.island.team.untrust.cannot-untrust-member"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -724,6 +724,7 @@ public class IslandsManagerTest {
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.IslandsManager#homeTeleport(World, Player, int)}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testHomeTeleportPlayerInt() {
|
||||
when(iwm.getDefaultGameMode(world)).thenReturn(GameMode.SURVIVAL);
|
||||
|
Loading…
Reference in New Issue
Block a user