mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-28 03:57:39 +01:00
commit
a29a2ccd8c
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@
|
||||
/.idea
|
||||
/database/
|
||||
/.gitignore
|
||||
/dependency-reduced-pom.xml
|
||||
|
@ -74,10 +74,6 @@ public class BentoBox extends JavaPlugin {
|
||||
// get a commodore instance
|
||||
commodore = CommodoreProvider.getCommodore(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Not loaded
|
||||
isLoaded = false;
|
||||
// Store the current millis time so we can tell how many ms it took for BSB to fully load.
|
||||
|
@ -10,6 +10,7 @@ import world.bentobox.bentobox.api.configuration.ConfigEntry;
|
||||
import world.bentobox.bentobox.api.configuration.StoreAt;
|
||||
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
||||
import world.bentobox.bentobox.database.objects.DataObject;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* All the plugin settings are here
|
||||
@ -109,6 +110,10 @@ public class Settings implements DataObject {
|
||||
@ConfigComment("Time in seconds that players have to confirm sensitive commands, e.g. island reset")
|
||||
@ConfigEntry(path = "general.confirmation-time")
|
||||
private int confirmationTime = 20;
|
||||
|
||||
@ConfigComment("Rank required to use a command. e.g., use the invite command. Default is owner rank is required.")
|
||||
@ConfigEntry(path = "general.rank-command")
|
||||
private Map<String, Integer> rankCommand = new HashMap<>();
|
||||
|
||||
@ConfigEntry(path = "panel.close-on-click-outside")
|
||||
private boolean closePanelOnClickOutside = true;
|
||||
@ -586,4 +591,28 @@ public class Settings implements DataObject {
|
||||
this.banWait = banWait;
|
||||
}
|
||||
|
||||
public int getRankCommand(String command) {
|
||||
return rankCommand.getOrDefault(command, RanksManager.OWNER_RANK);
|
||||
|
||||
}
|
||||
|
||||
public void setRankCommand(String command, int rank) {
|
||||
rankCommand.put(command, rank);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rankCommand
|
||||
*/
|
||||
public Map<String, Integer> getRankCommand() {
|
||||
return rankCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rankCommand the rankCommand to set
|
||||
*/
|
||||
public void setRankCommand(Map<String, Integer> rankCommand) {
|
||||
this.rankCommand = rankCommand;
|
||||
}
|
||||
|
||||
}
|
@ -17,16 +17,10 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
import me.lucko.commodore.Commodore;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
@ -51,6 +45,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
* True if the command is for the player only (not for the console)
|
||||
*/
|
||||
private boolean onlyPlayer = false;
|
||||
|
||||
/**
|
||||
* True if the command is only for the console to use
|
||||
*/
|
||||
private boolean onlyConsole = false;
|
||||
|
||||
/**
|
||||
* True if command is a configurable rank
|
||||
*/
|
||||
private boolean configurableRankCommand = false;
|
||||
|
||||
/**
|
||||
* The parameters string for this command. It is the commands followed by a locale reference.
|
||||
*/
|
||||
@ -201,8 +206,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
this.permissionPrefix = parent.getPermissionPrefix();
|
||||
// Inherit world
|
||||
this.world = parent.getWorld();
|
||||
|
||||
// Default references to description and parameters
|
||||
|
||||
StringBuilder reference = new StringBuilder();
|
||||
reference.append(label);
|
||||
CompositeCommand p = this;
|
||||
@ -620,7 +625,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
// Get command object based on args entered so far
|
||||
CompositeCommand cmd = getCommandFromArgs(args);
|
||||
// Check for console and permissions
|
||||
if (cmd.onlyPlayer && !(sender instanceof Player)) {
|
||||
if ((cmd.onlyPlayer && !(sender instanceof Player)) || (cmd.onlyConsole && sender instanceof Player)) {
|
||||
return options;
|
||||
}
|
||||
if (!cmd.getPermission().isEmpty() && !sender.hasPermission(cmd.getPermission()) && !sender.isOp()) {
|
||||
@ -821,4 +826,33 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
user.sendMessage("general.errors.you-must-wait", TextVariables.NUMBER, String.valueOf(timeToGo));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onlyConsole
|
||||
*/
|
||||
public boolean isOnlyConsole() {
|
||||
return onlyConsole;
|
||||
}
|
||||
|
||||
/**
|
||||
* This command is only for console use
|
||||
*/
|
||||
public void setOnlyConsole() {
|
||||
this.onlyConsole = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configurableRankCommand
|
||||
*/
|
||||
public boolean isConfigurableRankCommand() {
|
||||
return configurableRankCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* This command can be configured for use by different ranks
|
||||
*/
|
||||
public void setConfigurableRankCommand() {
|
||||
this.configurableRankCommand = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ public class AdminClearResetsAllCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// If args are not right, show help
|
||||
if (!args.isEmpty()) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
|
@ -1,31 +0,0 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AdminReloadCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* @param parent - parent command
|
||||
*/
|
||||
public AdminReloadCommand(CompositeCommand parent) {
|
||||
super(parent, "reload", "rl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.reload.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -27,6 +27,7 @@ public class IslandBanCommand extends CompositeCommand {
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.island.ban.parameters");
|
||||
setDescription("commands.island.ban.description");
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,13 +38,14 @@ public class IslandBanCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID)) {
|
||||
// Player issuing the command must have an island or be in a team
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
|
@ -23,6 +23,7 @@ public class IslandUnbanCommand extends CompositeCommand {
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.island.unban.parameters");
|
||||
setDescription("commands.island.unban.description");
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,13 +34,14 @@ public class IslandUnbanCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID)) {
|
||||
// Player issuing the command must have an island or be in a team
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
|
@ -30,6 +30,13 @@ public class IslandTeamCommand extends CompositeCommand {
|
||||
new IslandTeamKickCommand(this);
|
||||
new IslandTeamInviteAcceptCommand(this);
|
||||
new IslandTeamInviteRejectCommand(this);
|
||||
new IslandTeamCoopCommand(this);
|
||||
new IslandTeamUncoopCommand(this);
|
||||
new IslandTeamTrustCommand(this);
|
||||
new IslandTeamUntrustCommand(this);
|
||||
new IslandTeamPromoteCommand(this, "promote");
|
||||
new IslandTeamPromoteCommand(this, "demote");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,96 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
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.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Command to coop another player
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class IslandTeamCoopCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamCoopCommand(CompositeCommand parentCommand) {
|
||||
super(parentCommand, "coop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team.coop");
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.island.team.coop.parameters");
|
||||
setDescription("commands.island.team.coop.description");
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Player issuing the command must have an island or be in a team
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (getSettings().getInviteWait() > 0 && checkCooldown(user, targetUUID)) {
|
||||
return false;
|
||||
}
|
||||
return coopCmd(user, targetUUID);
|
||||
}
|
||||
|
||||
private boolean coopCmd(User user, UUID targetUUID) {
|
||||
// Player cannot coop themselves
|
||||
if (user.getUniqueId().equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.coop.cannot-coop-yourself");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.coop.already-has-rank");
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.setRank(target, RanksManager.COOP_RANK);
|
||||
user.sendMessage("general.success");
|
||||
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
user.sendMessage("general.errors.general");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(Util.getOnlinePlayerList(user), lastArg));
|
||||
}
|
||||
}
|
@ -32,19 +32,20 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.invite.description");
|
||||
inviteList = HashBiMap.create();
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
// Player issuing the command must have an island or be in a team
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
UUID teamLeaderUUID = getTeamLeader(getWorld(), user);
|
||||
if (!(teamLeaderUUID.equals(playerUUID))) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
if (args.isEmpty() || args.size() > 1) {
|
||||
|
@ -18,6 +18,7 @@ public class IslandTeamKickCommand extends CompositeCommand {
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.island.team.kick.parameters");
|
||||
setDescription("commands.island.team.kick.description");
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
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.managers.RanksManager;
|
||||
|
||||
public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
|
||||
@ -31,10 +32,12 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return true;
|
||||
}
|
||||
if (!getTeamLeader(getWorld(), user).equals(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return true;
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
@ -58,7 +61,8 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
int currentRank = getIslands().getIsland(getWorld(), user.getUniqueId()).getRank(target);
|
||||
if (this.getLabel().equals("promote")) {
|
||||
int nextRank = getPlugin().getRanksManager().getRankUpValue(currentRank);
|
||||
if (nextRank > currentRank) {
|
||||
// Stop short of owner
|
||||
if (nextRank != RanksManager.OWNER_RANK && nextRank > currentRank) {
|
||||
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, nextRank);
|
||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank));
|
||||
user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||
@ -70,7 +74,8 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||
} else {
|
||||
// Demote
|
||||
int prevRank = getPlugin().getRanksManager().getRankDownValue(currentRank);
|
||||
if (prevRank < currentRank) {
|
||||
// Lowest is Member
|
||||
if (prevRank >= RanksManager.MEMBER_RANK && prevRank < currentRank) {
|
||||
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, prevRank);
|
||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank));
|
||||
user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||
|
@ -0,0 +1,111 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Command to trust another player
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamTrustCommand(CompositeCommand parentCommand) {
|
||||
super(parentCommand, "trust");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team.trust");
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.island.team.trust.parameters");
|
||||
setDescription("commands.island.team.trust.description");
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Player issuing the command must have an island or be in a team
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (getSettings().getInviteWait() > 0 && checkCooldown(user, targetUUID)) {
|
||||
return false;
|
||||
}
|
||||
return trustCmd(user, targetUUID);
|
||||
}
|
||||
|
||||
private boolean trustCmd(User user, UUID targetUUID) {
|
||||
// Player cannot trust themselves
|
||||
if (user.getUniqueId().equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.trust.trust-in-yourself");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.trust.members-trusted");
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
int rank = getIslands().getIsland(getWorld(), user).getRank(target);
|
||||
if (rank >= RanksManager.TRUSTED_RANK) {
|
||||
user.sendMessage("commands.island.team.trust.player-already-trusted");
|
||||
return false;
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.setRank(target, RanksManager.TRUSTED_RANK);
|
||||
user.sendMessage("general.success");
|
||||
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName());
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
user.sendMessage("general.errors.general");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
List<String> options = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> !p.getUniqueId().equals(user.getUniqueId()))
|
||||
.filter(p -> !island.getMemberSet().contains(p.getUniqueId()))
|
||||
.filter(p -> user.getPlayer().canSee(p))
|
||||
.map(Player::getName).collect(Collectors.toList());
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
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.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Command to uncoop a player
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class IslandTeamUncoopCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamUncoopCommand(CompositeCommand parentCommand) {
|
||||
super(parentCommand, "uncoop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team.coop");
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.island.team.uncoop.parameters");
|
||||
setDescription("commands.island.team.uncoop.description");
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Player issuing the command must have an island or be in a team
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
// Uncoop
|
||||
return unCoopCmd(user, targetUUID);
|
||||
}
|
||||
|
||||
private boolean unCoopCmd(User user, UUID targetUUID) {
|
||||
// Player cannot uncoop themselves
|
||||
if (user.getUniqueId().equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-yourself");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-member");
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
int rank = getIslands().getIsland(getWorld(), user).getRank(target);
|
||||
if (rank != RanksManager.COOP_RANK) {
|
||||
user.sendMessage("commands.island.team.uncoop.player-not-coop");
|
||||
return false;
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.removeMember(targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
target.sendMessage("commands.island.team.uncoop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName());
|
||||
// Set cooldown
|
||||
if (getSettings().getInviteWait() > 0 && getParent() != null) {
|
||||
getParent().getSubCommand("coop").ifPresent(subCommand ->
|
||||
subCommand.setCooldown(user.getUniqueId(), targetUUID, getSettings().getInviteWait() * 60));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
user.sendMessage("general.errors.general");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
List<String> options = island.getMemberSet().stream()
|
||||
.filter(uuid -> island.getRank(User.getInstance(uuid)) == RanksManager.COOP_RANK)
|
||||
.map(Bukkit::getOfflinePlayer)
|
||||
.map(OfflinePlayer::getName).collect(Collectors.toList());
|
||||
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
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.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Command to untrust a player
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class IslandTeamUntrustCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamUntrustCommand(CompositeCommand parentCommand) {
|
||||
super(parentCommand, "untrust");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("island.team.coop");
|
||||
setOnlyPlayer(true);
|
||||
setParametersHelp("commands.island.team.untrust.parameters");
|
||||
setDescription("commands.island.team.untrust.description");
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// Player issuing the command must have an island or be in a team
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
// Check rank to use command
|
||||
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
// untrust
|
||||
return unTrustCmd(user, targetUUID);
|
||||
}
|
||||
|
||||
private boolean unTrustCmd(User user, UUID targetUUID) {
|
||||
// Player cannot untrust themselves
|
||||
if (user.getUniqueId().equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.untrust.cannot-untrust-yourself");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.untrust.cannot-untrust-member");
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
int rank = getIslands().getIsland(getWorld(), user).getRank(target);
|
||||
if (rank != RanksManager.TRUSTED_RANK) {
|
||||
user.sendMessage("commands.island.team.untrust.player-not-trusted");
|
||||
return false;
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.removeMember(targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
target.sendMessage("commands.island.team.untrust.you-are-no-longer-trusted", TextVariables.NAME, user.getName());
|
||||
// Set cooldown
|
||||
if (getSettings().getInviteWait() > 0 && getParent() != null) {
|
||||
getParent().getSubCommand("trust").ifPresent(subCommand ->
|
||||
subCommand.setCooldown(user.getUniqueId(), targetUUID, getSettings().getInviteWait() * 60));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
user.sendMessage("general.errors.general");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
List<String> options = island.getMemberSet().stream()
|
||||
.filter(uuid -> island.getRank(User.getInstance(uuid)) == RanksManager.TRUSTED_RANK)
|
||||
.map(Bukkit::getOfflinePlayer)
|
||||
.map(OfflinePlayer::getName).collect(Collectors.toList());
|
||||
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
@ -16,8 +16,10 @@ public class BentoBoxCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("bentobox.admin");
|
||||
new BentoBoxVersionCommand(this);
|
||||
new BentoBoxAboutCommand(this);
|
||||
new BentoBoxReloadCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,44 @@
|
||||
package world.bentobox.bentobox.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* Displays information about Gamemodes, Addons and versioning.
|
||||
*
|
||||
* @author tastybento
|
||||
*/
|
||||
public class BentoBoxReloadCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* Reloads locales command
|
||||
* @param parent - command parent
|
||||
*/
|
||||
public BentoBoxReloadCommand(CompositeCommand parent) {
|
||||
super(parent, "reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.reload");
|
||||
setDescription("commands.bentobox.reload.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
this.askConfirmation(user, () -> reloadLocales(user));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the languages
|
||||
* @param user
|
||||
*/
|
||||
public void reloadLocales(User user) {
|
||||
getPlugin().getLocalesManager().reloadLanguages();
|
||||
user.sendMessage("commands.bentobox.reload.locales-reloaded");
|
||||
}
|
||||
|
||||
}
|
@ -23,7 +23,7 @@ public class BentoBoxVersionCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
// Useless : this command uses the default values.
|
||||
setPermission("bentobox.admin");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -403,8 +403,8 @@ public class Island implements DataObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from the team member map. Do not call this directly.
|
||||
* Use {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(World, UUID)}
|
||||
* Removes a player from the team member map. Generally, you should
|
||||
* use {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(World, UUID)}
|
||||
* @param playerUUID - uuid of player
|
||||
*/
|
||||
public void removeMember(UUID playerUUID) {
|
||||
@ -636,20 +636,16 @@ public class Island implements DataObject {
|
||||
* @param world - world to check
|
||||
*/
|
||||
public void showMembers(BentoBox plugin, User user, World world) {
|
||||
if (plugin.getIslands().inTeam(world, user.getUniqueId())) {
|
||||
user.sendMessage("commands.admin.info.team-members-title");
|
||||
members.forEach((u, i) -> {
|
||||
if (owner.equals(u)) {
|
||||
user.sendMessage("commands.admin.info.team-owner-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
} else if (i > RanksManager.VISITOR_RANK){
|
||||
user.sendMessage("commands.admin.info.team-member-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
user.sendMessage("commands.admin.info.team-members-title");
|
||||
members.forEach((u, i) -> {
|
||||
if (owner.equals(u)) {
|
||||
user.sendMessage("commands.admin.info.team-owner-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
} else if (i > RanksManager.VISITOR_RANK){
|
||||
user.sendMessage("commands.admin.info.team-member-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,66 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.clicklisteners;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class CommandCycleClick implements ClickHandler {
|
||||
|
||||
private BentoBox plugin = BentoBox.getInstance();
|
||||
private String command;
|
||||
private CommandRankClickListener commandRankClickListener;
|
||||
|
||||
public CommandCycleClick(CommandRankClickListener commandRankClickListener, String c) {
|
||||
this.commandRankClickListener = commandRankClickListener;
|
||||
this.command = c;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see world.bentobox.bentobox.api.panels.PanelItem.ClickHandler#onClick(world.bentobox.bentobox.api.panels.Panel, world.bentobox.bentobox.api.user.User, org.bukkit.event.inventory.ClickType, int)
|
||||
*/
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType click, int slot) {
|
||||
// Left clicking increases the rank required
|
||||
// Right clicking decreases the rank required
|
||||
// Get the user's island
|
||||
Island island = plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId());
|
||||
if (island != null && island.getOwner().equals(user.getUniqueId())) {
|
||||
RanksManager rm = plugin.getRanksManager();
|
||||
int currentRank = plugin.getSettings().getRankCommand(command);
|
||||
if (click.equals(ClickType.LEFT)) {
|
||||
if (currentRank == RanksManager.OWNER_RANK) {
|
||||
plugin.getSettings().setRankCommand(command, RanksManager.MEMBER_RANK);
|
||||
} else {
|
||||
plugin.getSettings().setRankCommand(command, rm.getRankUpValue(currentRank));
|
||||
}
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
} else if (click.equals(ClickType.RIGHT)) {
|
||||
if (currentRank == RanksManager.MEMBER_RANK) {
|
||||
plugin.getSettings().setRankCommand(command, RanksManager.OWNER_RANK);
|
||||
} else {
|
||||
plugin.getSettings().setRankCommand(command, rm.getRankDownValue(currentRank));
|
||||
}
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
}
|
||||
// Apply change to panel
|
||||
panel.getInventory().setItem(slot, commandRankClickListener.getPanelItem(command, user).getItem());
|
||||
} else {
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags.clicklisteners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class CommandRankClickListener implements ClickHandler {
|
||||
|
||||
private BentoBox plugin = BentoBox.getInstance();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see world.bentobox.bentobox.api.panels.PanelItem.ClickHandler#onClick(world.bentobox.bentobox.api.panels.Panel, world.bentobox.bentobox.api.user.User, org.bukkit.event.inventory.ClickType, int)
|
||||
*/
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
// Get the world
|
||||
if (!user.inWorld()) {
|
||||
user.sendMessage("general.errors.wrong-world");
|
||||
return true;
|
||||
}
|
||||
IslandWorldManager iwm = plugin.getIWM();
|
||||
String reqPerm = iwm.getPermissionPrefix(Util.getWorld(user.getWorld())) + ".admin.settings.COMMAND_RANKS";
|
||||
if (!user.hasPermission(reqPerm)) {
|
||||
user.sendMessage("general.errors.no-permission", "[permission]", reqPerm);
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||
return true;
|
||||
}
|
||||
|
||||
String panelName = user.getTranslation("protection.flags.COMMAND_RANKS.name");
|
||||
if (panel.getName().equals(panelName)) {
|
||||
// This is a click on the panel
|
||||
// Slot relates to the command
|
||||
String c = getCommands(user.getWorld()).get(slot);
|
||||
// Apply change to panel
|
||||
panel.getInventory().setItem(slot, getPanelItem(c, user).getItem());
|
||||
} else {
|
||||
// Open the Sub Settings panel
|
||||
openPanel(user, panelName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void openPanel(User user, String panelName) {
|
||||
// Close the current panel
|
||||
user.closeInventory();
|
||||
// Open a new panel
|
||||
PanelBuilder pb = new PanelBuilder();
|
||||
pb.user(user).name(panelName);
|
||||
// Make panel items
|
||||
getCommands(user.getWorld()).forEach(c -> pb.item(getPanelItem(c, user)));
|
||||
pb.build();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rank command panel item
|
||||
* @param c - rank string
|
||||
* @param user - user
|
||||
* @return panel item for this command
|
||||
*/
|
||||
public PanelItem getPanelItem(String c, User user) {
|
||||
PanelItemBuilder pib = new PanelItemBuilder();
|
||||
pib.name(c);
|
||||
pib.clickHandler(new CommandCycleClick(this, c));
|
||||
pib.icon(Material.MAP);
|
||||
// TODO: use specific layout
|
||||
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
|
||||
pib.description(d);
|
||||
plugin.getRanksManager().getRanks().forEach((reference, score) -> {
|
||||
if (score >= RanksManager.MEMBER_RANK && score < plugin.getSettings().getRankCommand(c)) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.blocked-rank") + user.getTranslation(reference));
|
||||
} else if (score <= RanksManager.OWNER_RANK && score > plugin.getSettings().getRankCommand(c)) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.allowed-rank") + user.getTranslation(reference));
|
||||
} else if (score == plugin.getSettings().getRankCommand(c)) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.minimal-rank") + user.getTranslation(reference));
|
||||
}
|
||||
});
|
||||
return pib.build();
|
||||
}
|
||||
|
||||
private List<String> getCommands(World world) {
|
||||
List<String> result = new ArrayList<>();
|
||||
plugin.getCommandsManager().getCommands().values().stream()
|
||||
.filter(c -> c.getWorld() != null && c.getWorld().equals(world))
|
||||
.forEach(c -> result.addAll(getCmdRecursively("/", c)));
|
||||
if (result.size() > 49) {
|
||||
Bukkit.getLogger().severe("Number of rank setting commands is too big for GUI");
|
||||
result.subList(49, result.size()).clear();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively traverses the command tree looking for any configurable rank command and returns a string list of commands
|
||||
* @param labels - preceding command's label list
|
||||
* @param cc - composite command
|
||||
* @return string list of commands
|
||||
*/
|
||||
private List<String> getCmdRecursively(String labels, CompositeCommand cc) {
|
||||
List<String> result = new ArrayList<>();
|
||||
String newLabel = labels + cc.getName();
|
||||
if (cc.isConfigurableRankCommand()) {
|
||||
result.add(newLabel);
|
||||
}
|
||||
cc.getSubCommands().values().forEach(s -> result.addAll(getCmdRecursively(newLabel + " ", s)));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.listeners.flags;
|
||||
package world.bentobox.bentobox.listeners.flags.clicklisteners;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
@ -49,8 +49,7 @@ public class GeoLimitClickListener implements ClickHandler {
|
||||
IslandWorldManager iwm = BentoBox.getInstance().getIWM();
|
||||
String reqPerm = iwm.getPermissionPrefix(Util.getWorld(user.getWorld())) + ".admin.settings.GEO_LIMIT_MOBS";
|
||||
if (!user.hasPermission(reqPerm)) {
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
user.sendMessage("general.errors.you-need", "[permission]", reqPerm);
|
||||
user.sendMessage("general.errors.no-permission", "[permission]", reqPerm);
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||
return true;
|
||||
}
|
@ -23,7 +23,6 @@ import world.bentobox.bentobox.listeners.flags.EndermanListener;
|
||||
import world.bentobox.bentobox.listeners.flags.EnterExitListener;
|
||||
import world.bentobox.bentobox.listeners.flags.EntityInteractListener;
|
||||
import world.bentobox.bentobox.listeners.flags.FireListener;
|
||||
import world.bentobox.bentobox.listeners.flags.GeoLimitClickListener;
|
||||
import world.bentobox.bentobox.listeners.flags.GeoLimitMobsListener;
|
||||
import world.bentobox.bentobox.listeners.flags.HurtingListener;
|
||||
import world.bentobox.bentobox.listeners.flags.InventoryListener;
|
||||
@ -44,6 +43,8 @@ import world.bentobox.bentobox.listeners.flags.RemoveMobsListener;
|
||||
import world.bentobox.bentobox.listeners.flags.ShearingListener;
|
||||
import world.bentobox.bentobox.listeners.flags.TNTListener;
|
||||
import world.bentobox.bentobox.listeners.flags.TeleportationListener;
|
||||
import world.bentobox.bentobox.listeners.flags.clicklisteners.CommandRankClickListener;
|
||||
import world.bentobox.bentobox.listeners.flags.clicklisteners.GeoLimitClickListener;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
public class Flags {
|
||||
@ -222,6 +223,9 @@ public class Flags {
|
||||
*/
|
||||
public static final Flag CREEPER_GRIEFING = new FlagBuilder().id("CREEPER_GRIEFING").icon(Material.CREEPER_HEAD).type(Type.WORLD_SETTING)
|
||||
.allowedByDefault(false).build();
|
||||
|
||||
public static final Flag COMMAND_RANKS = new FlagBuilder().id("COMMAND_RANKS").icon(Material.PLAYER_HEAD).type(Type.WORLD_SETTING)
|
||||
.onClick(new CommandRankClickListener()).subPanel(true).build();
|
||||
|
||||
/**
|
||||
* @return List of all the flags in this class
|
||||
|
@ -115,7 +115,7 @@ public class AddonsManager {
|
||||
for (String localeFile : listJarYamlFiles(jar, LOCALE_FOLDER)) {
|
||||
addon.saveResource(localeFile, localeDir, false, true);
|
||||
}
|
||||
plugin.getLocalesManager().loadLocales(addon.getDescription().getName());
|
||||
plugin.getLocalesManager().loadLocalesFromFile(addon.getDescription().getName());
|
||||
// Fire the load event
|
||||
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
||||
// Add it to the list of addons
|
||||
@ -192,7 +192,6 @@ public class AddonsManager {
|
||||
* @param jar - the jar file
|
||||
* @param folderPath - the path within the jar
|
||||
* @return a list of files
|
||||
- if the file cannot be read
|
||||
*/
|
||||
public List<String> listJarYamlFiles(JarFile jar, String folderPath) {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
@ -44,4 +44,11 @@ public class CommandsManager {
|
||||
return commands.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the commands
|
||||
*/
|
||||
public HashMap<String, CompositeCommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ public class LocalesManager {
|
||||
|
||||
public LocalesManager(BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
loadLocales("BentoBox"); // Default
|
||||
copyLocalesFromJar("BentoBox");
|
||||
loadLocalesFromFile("BentoBox"); // Default
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,16 +57,13 @@ public class LocalesManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all the locales available. If the locale folder does not exist, one will be created and
|
||||
* filled with locale files from the jar.
|
||||
* Copies all the locale files from the plugin jar to the filesystem.
|
||||
* Only done if the locale folder does not already exist.
|
||||
* @param folderName - the name of the destination folder
|
||||
*/
|
||||
public void loadLocales(String parent) {
|
||||
// Describe the filter - we only want files that are correctly named
|
||||
// Files must be 9 chars long
|
||||
FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase(java.util.Locale.ENGLISH).endsWith(".yml") && name.length() == 9;
|
||||
|
||||
private void copyLocalesFromJar(String folderName) {
|
||||
// Run through the files and store the locales
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + folderName);
|
||||
// If the folder does not exist, then make it and fill with the locale files from the jar
|
||||
// If it does exist, then new files will NOT be written!
|
||||
if (!localeDir.exists()) {
|
||||
@ -83,8 +81,24 @@ public class LocalesManager {
|
||||
plugin.logError("Could not copy locale files from jar " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all the locales available in the locale folder given. Used for loading all locales from plugin and addons
|
||||
*
|
||||
* @param localeFolder - locale folder location relative to the plugin's data folder
|
||||
*/
|
||||
public void loadLocalesFromFile(String localeFolder) {
|
||||
// Filter for files of length 9 and ending with .yml
|
||||
FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase(java.util.Locale.ENGLISH).endsWith(".yml") && name.length() == 9;
|
||||
|
||||
// Store all the locales available
|
||||
// Get the folder
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + localeFolder);
|
||||
if (!localeDir.exists()) {
|
||||
// If there is no locale folder, then return
|
||||
return;
|
||||
}
|
||||
// Run through the files and store the locales
|
||||
for (File language : Objects.requireNonNull(localeDir.listFiles(ymlFilter))) {
|
||||
Locale localeObject = Locale.forLanguageTag(language.getName().substring(0, language.getName().length() - 4));
|
||||
|
||||
@ -137,4 +151,13 @@ public class LocalesManager {
|
||||
public Map<Locale, BentoBoxLocale> getLanguages() {
|
||||
return this.languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all the language files from the filesystem
|
||||
*/
|
||||
public void reloadLanguages() {
|
||||
languages.clear();
|
||||
loadLocalesFromFile("BentoBox");
|
||||
plugin.getAddonsManager().getAddons().forEach(addon -> loadLocalesFromFile(addon.getDescription().getName()));
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,19 @@ public class RanksManager {
|
||||
public static final String ADMIN_RANK_REF = "ranks.admin";
|
||||
public static final String MOD_RANK_REF = "ranks.mod";
|
||||
public static final String OWNER_RANK_REF = "ranks.owner";
|
||||
public static final String SUB_OWNER_RANK_REF = "ranks.sub-owner";
|
||||
public static final String MEMBER_RANK_REF = "ranks.member";
|
||||
public static final String TRUSTED_RANK_REF = "ranks.trusted";
|
||||
public static final String COOP_RANK_REF = "ranks.coop";
|
||||
public static final String VISITOR_RANK_REF = "ranks.visitor";
|
||||
public static final String BANNED_RANK_REF = "ranks.banned";
|
||||
public static final int ADMIN_RANK = 10000;
|
||||
public static final int MOD_RANK = 5000;
|
||||
public static final int OWNER_RANK = 1000;
|
||||
public static final int MEMBER_RANK = 900;
|
||||
public static final int SUB_OWNER_RANK = 900;
|
||||
public static final int MEMBER_RANK = 500;
|
||||
public static final int TRUSTED_RANK = 400;
|
||||
public static final int COOP_RANK = 200;
|
||||
public static final int VISITOR_RANK = 0;
|
||||
public static final int BANNED_RANK = -1;
|
||||
|
||||
@ -38,7 +44,10 @@ public class RanksManager {
|
||||
ranksPut(ADMIN_RANK_REF, ADMIN_RANK);
|
||||
ranksPut(MOD_RANK_REF, MOD_RANK);
|
||||
ranksPut(OWNER_RANK_REF, OWNER_RANK);
|
||||
ranksPut(SUB_OWNER_RANK_REF, SUB_OWNER_RANK);
|
||||
ranksPut(MEMBER_RANK_REF, MEMBER_RANK);
|
||||
ranksPut(TRUSTED_RANK_REF, TRUSTED_RANK);
|
||||
ranksPut(COOP_RANK_REF, COOP_RANK);
|
||||
ranksPut(VISITOR_RANK_REF, VISITOR_RANK);
|
||||
ranksPut(BANNED_RANK_REF, BANNED_RANK);
|
||||
loadCustomRanks();
|
||||
|
@ -26,7 +26,9 @@ public class SettingsPanel {
|
||||
/**
|
||||
* Dynamically creates the panel.
|
||||
* @param plugin - plugin
|
||||
* @param user the User to show the panel to
|
||||
* @param user - user to show panel to
|
||||
* @param flagType - initial view
|
||||
* @param world - world
|
||||
*/
|
||||
public static void openPanel(BentoBox plugin, User user, Flag.Type flagType, World world) {
|
||||
String friendlyWorldName = plugin.getIWM().getFriendlyName(world);
|
||||
|
@ -175,6 +175,8 @@ commands:
|
||||
description: "BentoBox admin command"
|
||||
about:
|
||||
description: "display copyright and license info"
|
||||
reload:
|
||||
description: "reloads all locale files"
|
||||
version:
|
||||
description: "display info"
|
||||
loaded-addons: "Loaded Add-Ons"
|
||||
@ -226,12 +228,39 @@ commands:
|
||||
description: "manage your team"
|
||||
info:
|
||||
description: "display detailed info about your team"
|
||||
coop:
|
||||
description: "make a player coop rank on your island"
|
||||
paramters: "<player>"
|
||||
cannot-coop-yourself: "&cYou cannot coop yourself!"
|
||||
already-has-rank: "&cPlayer already has a rank!"
|
||||
you-are-a-coop-member: "&2You were cooped by [name]"
|
||||
uncoop:
|
||||
description: "remove a coop rank from player"
|
||||
paramters: "<player>"
|
||||
cannot-uncoop-yourself: "&cYou cannot uncoop yourself!"
|
||||
cannot-uncoop-member: "&cYou cannot uncoop a team member!"
|
||||
player-not-cooped: "&cPlayer is not cooped!"
|
||||
you-are-no-longer-a-coop-member: "&cYou are no longer a coop member of [name]'s island"
|
||||
trust:
|
||||
description: "give a player trusted rank on your island"
|
||||
paramters: "<player>"
|
||||
trust-in-yourself: "&cTrust in yourself!"
|
||||
members-trusted: "&cMembers are already trusted"
|
||||
player-already-trusted: "&cPlayer is already trusted!"
|
||||
you-are-trusted: "&2You are trusted by [name]!"
|
||||
untrust:
|
||||
description: "remove trusted player rank from player"
|
||||
paramters: "<player>"
|
||||
cannot-untrust-yourself: "&cYou cannot untrust yourself!"
|
||||
cannot-untrust-member: "&cYou cannot untrust a team member!"
|
||||
player-not-trusted: "&cPlayer is not trusted!"
|
||||
you-are-no-longer-trusted: "&cYou are no longer trusted by [name]!"
|
||||
invite:
|
||||
description: "invite a player to join your island"
|
||||
invitation-sent: "Invitation sent to [name]"
|
||||
removing-invite: "Removing invite"
|
||||
name-has-invited-you: "[name] has invited you to join their island."
|
||||
to-accept-or-reject: "Do /island team accept to accept, or /island team reject to reject"
|
||||
to-accept-or-reject: "Do /[label] team accept to accept, or /[label] team reject to reject"
|
||||
you-will-lose-your-island: "&cWARNING! You will lose your island if you accept!"
|
||||
errors:
|
||||
cannot-invite-self: "&cYou cannot invite yourself!"
|
||||
@ -307,7 +336,9 @@ commands:
|
||||
|
||||
ranks:
|
||||
owner: "Owner"
|
||||
sub-owner: "Sub-Owner"
|
||||
member: "Member"
|
||||
trusted: "Trusted"
|
||||
coop: "Coop"
|
||||
visitor: "Visitor"
|
||||
banned: "Banned"
|
||||
@ -385,6 +416,9 @@ protection:
|
||||
&a(override Buckets)
|
||||
name: "Collect water"
|
||||
hint: "No water collection"
|
||||
COMMAND_RANKS:
|
||||
name: "Command Ranks"
|
||||
description: "&aConfigure command ranks"
|
||||
CRAFTING:
|
||||
description: "Toggle use"
|
||||
name: "Workbenches"
|
||||
|
@ -8,3 +8,8 @@ authors: [tastybento, Poslovitch]
|
||||
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI]
|
||||
|
||||
loadbefore: [Multiverse-Core]
|
||||
|
||||
permissions:
|
||||
bentobox.admin:
|
||||
description: Allow bentobox command usage
|
||||
default: op
|
||||
|
@ -113,7 +113,7 @@ public class AdminClearResetsAllCommandTest {
|
||||
AdminClearResetsAllCommand itl = new AdminClearResetsAllCommand(ac);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>(Arrays.asList("tastybento", "bobby"))));
|
||||
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.any());
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.confirmation.confirm"), Mockito.eq("[seconds]"), Mockito.any());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public class AdminDeleteCommandTest {
|
||||
AdminDeleteCommand itl = new AdminDeleteCommand(ac);
|
||||
// First requires confirmation
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.confirm", "[seconds]", "0");
|
||||
Mockito.verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0");
|
||||
// Confirm
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ import world.bentobox.bentobox.managers.CommandsManager;
|
||||
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
|
||||
@ -76,6 +77,7 @@ public class IslandBanCommandTest {
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
@ -112,6 +114,8 @@ public class IslandBanCommandTest {
|
||||
island = mock(Island.class);
|
||||
when(island.getBanned()).thenReturn(new HashSet<>());
|
||||
when(island.isBanned(Mockito.any())).thenReturn(false);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
|
||||
// IWM friendly name
|
||||
@ -147,17 +151,19 @@ public class IslandBanCommandTest {
|
||||
|
||||
@Test
|
||||
public void testNoIsland() {
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
IslandBanCommand ibc = new IslandBanCommand(ic);
|
||||
assertFalse(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage("general.errors.no-island");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotOwner() {
|
||||
public void testTooLowRank() {
|
||||
IslandBanCommand ibc = new IslandBanCommand(ic);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
assertFalse(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage("general.errors.not-leader");
|
||||
Mockito.verify(user).sendMessage("general.errors.no-permission");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -276,7 +276,7 @@ public class IslandResetCommandTest {
|
||||
// Reset
|
||||
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||
// Check for message
|
||||
Mockito.verify(user).sendMessage("general.confirm", "[seconds]", String.valueOf(s.getConfirmationTime()));
|
||||
Mockito.verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", String.valueOf(s.getConfirmationTime()));
|
||||
|
||||
// Send command again to confirm
|
||||
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||
|
@ -41,6 +41,7 @@ import world.bentobox.bentobox.managers.CommandsManager;
|
||||
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
|
||||
@ -73,6 +74,7 @@ public class IslandUnbanCommandTest {
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
@ -110,6 +112,8 @@ public class IslandUnbanCommandTest {
|
||||
island = mock(Island.class);
|
||||
when(island.getBanned()).thenReturn(new HashSet<>());
|
||||
when(island.isBanned(Mockito.any())).thenReturn(false);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
|
||||
// IWM friendly name
|
||||
@ -141,17 +145,19 @@ public class IslandUnbanCommandTest {
|
||||
|
||||
@Test
|
||||
public void testNoIsland() {
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
IslandUnbanCommand iubc = new IslandUnbanCommand(ic);
|
||||
assertFalse(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage("general.errors.no-island");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotOwner() {
|
||||
public void testTooLowRank() {
|
||||
IslandUnbanCommand iubc = new IslandUnbanCommand(ic);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
assertFalse(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage("general.errors.not-leader");
|
||||
Mockito.verify(user).sendMessage("general.errors.no-permission");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
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.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamCoopCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
private Island island;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(CompositeCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
// Player Manager
|
||||
pm = mock(PlayersManager.class);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// IWM friendly name
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSamePlayer() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.coop.cannot-coop-yourself"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.coop.already-has-rank"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -28,11 +28,13 @@ import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -49,6 +51,7 @@ public class IslandTeamInviteCommandTest {
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
private Island island;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -66,6 +69,7 @@ public class IslandTeamInviteCommandTest {
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
@ -91,8 +95,12 @@ public class IslandTeamInviteCommandTest {
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
@ -125,6 +133,7 @@ public class IslandTeamInviteCommandTest {
|
||||
@Test
|
||||
public void testExecuteNoIsland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
@ -134,11 +143,11 @@ public class IslandTeamInviteCommandTest {
|
||||
* Test method for .
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNotTeamLeader() {
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(notUUID);
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-leader"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,7 +236,7 @@ public class IslandTeamKickCommandTest {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
// Confirmation required
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.confirmation.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,7 +159,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Confirmation required
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.confirmation.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
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.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamTrustCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
private Island island;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(CompositeCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
// Player Manager
|
||||
pm = mock(PlayersManager.class);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// IWM friendly name
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSamePlayer() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.trust.trust-in-yourself"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.trust.members-trusted"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
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.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamUncoopCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
private Island island;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(CompositeCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
// Player Manager
|
||||
pm = mock(PlayersManager.class);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// IWM friendly name
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSamePlayer() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.uncoop.cannot-uncoop-yourself"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.uncoop.cannot-uncoop-member"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
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.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamUntrustCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
private Island island;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(CompositeCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
// Player Manager
|
||||
pm = mock(PlayersManager.class);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// IWM friendly name
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.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"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_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"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSamePlayer() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.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"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.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"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -207,8 +207,7 @@ public class CycleClickTest {
|
||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||
CycleClick udc = new CycleClick("LOCK");
|
||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.you-need"), Mockito.eq("[permission]"), Mockito.eq("bskyblock.settings.LOCK"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"), Mockito.eq("[permission]"), Mockito.eq("bskyblock.settings.LOCK"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -102,8 +102,7 @@ public class IslandToggleClickTest {
|
||||
public void testOnClickNoPermission() {
|
||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
Mockito.verify(user).sendMessage("general.errors.no-permission");
|
||||
Mockito.verify(user).sendMessage("general.errors.you-need", "[permission]", "bskyblock.settings.test");
|
||||
Mockito.verify(user).sendMessage("general.errors.no-permission", "[permission]", "bskyblock.settings.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -86,8 +86,7 @@ public class WorldToggleClickTest {
|
||||
public void testOnClickNoPermission() {
|
||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
Mockito.verify(user).sendMessage("general.errors.no-permission");
|
||||
Mockito.verify(user).sendMessage("general.errors.you-need", "[permission]", "bskyblock.admin.world.settings.test");
|
||||
Mockito.verify(user).sendMessage("general.errors.no-permission", "[permission]", "bskyblock.admin.world.settings.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,8 +89,8 @@ public class RanksManagerTest {
|
||||
public void testGetNextRankValue() {
|
||||
assertEquals(RanksManager.BANNED_RANK, ranksManager.getRankUpValue(-20));
|
||||
assertEquals(RanksManager.VISITOR_RANK, ranksManager.getRankUpValue(RanksManager.BANNED_RANK));
|
||||
assertEquals(RanksManager.MEMBER_RANK, ranksManager.getRankUpValue(RanksManager.VISITOR_RANK));
|
||||
assertEquals(RanksManager.OWNER_RANK, ranksManager.getRankUpValue(RanksManager.MEMBER_RANK));
|
||||
assertEquals(RanksManager.COOP_RANK, ranksManager.getRankUpValue(RanksManager.VISITOR_RANK));
|
||||
assertEquals(RanksManager.SUB_OWNER_RANK, ranksManager.getRankUpValue(RanksManager.MEMBER_RANK));
|
||||
assertEquals(RanksManager.OWNER_RANK, ranksManager.getRankUpValue(RanksManager.OWNER_RANK));
|
||||
assertEquals(RanksManager.OWNER_RANK, ranksManager.getRankUpValue(2000));
|
||||
}
|
||||
@ -103,8 +103,8 @@ public class RanksManagerTest {
|
||||
// Lowest rank is Visitor
|
||||
assertEquals(RanksManager.VISITOR_RANK, ranksManager.getRankDownValue(-20));
|
||||
assertEquals(RanksManager.VISITOR_RANK, ranksManager.getRankDownValue(RanksManager.VISITOR_RANK));
|
||||
assertEquals(RanksManager.VISITOR_RANK, ranksManager.getRankDownValue(RanksManager.MEMBER_RANK));
|
||||
assertEquals(RanksManager.MEMBER_RANK, ranksManager.getRankDownValue(RanksManager.OWNER_RANK));
|
||||
assertEquals(RanksManager.TRUSTED_RANK, ranksManager.getRankDownValue(RanksManager.MEMBER_RANK));
|
||||
assertEquals(RanksManager.SUB_OWNER_RANK, ranksManager.getRankDownValue(RanksManager.OWNER_RANK));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user