Removed constants that reference the island and admin commands.

Fixed bug where addon onLoad was being called twice.
This commit is contained in:
tastybento 2018-05-26 18:20:02 -07:00
parent a5a75c6854
commit 66d9ef857d
25 changed files with 170 additions and 71 deletions

View File

@ -43,7 +43,7 @@ general:
commands: commands:
help: help:
header: "&7=========== &c%bsb_plugin_name% &7===========" header: "&7=========== &c[label] help &7==========="
syntax: "&b[usage] &a[parameters]&7: &e[description]" syntax: "&b[usage] &a[parameters]&7: &e[description]"
end: "&7=================================" end: "&7================================="
parameters: "[command]" parameters: "[command]"
@ -122,12 +122,13 @@ commands:
rank-set: "&aRank set from [from] to [to]." rank-set: "&aRank set from [from] to [to]."
island: island:
about: about:
description: "display info about %bsb_plugin_name%" description: "display copyright and license info"
go: go:
parameters: "<home number>" parameters: "<home number>"
description: "teleport you to your island" description: "teleport you to your island"
teleport: "&aTeleporting you to your island. &b/[label] help &afor help." teleport: "&aTeleporting you to your island."
teleported: "&aTeleported you to home &e#[number]." teleported: "&aTeleported you to home &e#[number]."
tip: "&bType /[label] help &afor help."
help: help:
description: "The main island command" description: "The main island command"
pick-world: "&cSpecify world from [worlds]" pick-world: "&cSpecify world from [worlds]"

View File

@ -12,13 +12,6 @@ public class Constants {
} }
public static final GameType GAMETYPE = GameType.BSKYBLOCK; public static final GameType GAMETYPE = GameType.BSKYBLOCK;
// Permission prefix
public static final String PERMPREFIX = "bskyblock.";
// The island command
public static final String ISLANDCOMMAND = "island";
// The spawn command (Essentials spawn for example) // The spawn command (Essentials spawn for example)
public static final String SPAWNCOMMAND = "spawn"; public static final String SPAWNCOMMAND = "spawn";
// Admin command
public static final String ADMINCOMMAND = "bsadmin";
} }

View File

@ -19,6 +19,7 @@ import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.addons.Addon;
import us.tastybento.bskyblock.api.events.command.CommandEvent; import us.tastybento.bskyblock.api.events.command.CommandEvent;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandWorldManager;
@ -79,6 +80,16 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* If the world value does not exist, then the command is general across worlds * If the world value does not exist, then the command is general across worlds
*/ */
private World world; private World world;
/**
* The addon creating this command, if any
*/
private Addon addon;
/**
* The top level label
*/
private String topLabel = "";
/** /**
* Used only for testing.... * Used only for testing....
@ -98,6 +109,33 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
} }
} }
/**
* Top level command
* @param addon - addon creating the command
* @param label - string for this command
* @param aliases - aliases
*/
public CompositeCommand(Addon addon, String label, String... aliases) {
super(label);
this.topLabel = label;
this.addon = addon;
this.plugin = BSkyBlock.getInstance();
setAliases(new ArrayList<>(Arrays.asList(aliases)));
parent = null;
setUsage("");
subCommandLevel = 0; // Top level
subCommands = new LinkedHashMap<>();
subCommandAliases = new LinkedHashMap<>();
// Register command if it is not already registered
if (plugin.getCommand(label) == null) {
plugin.getCommandsManager().registerCommand(this);
}
setup();
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
new DefaultHelpCommand(this);
}
}
/** /**
* This is the top-level command constructor for commands that have no parent. * This is the top-level command constructor for commands that have no parent.
* @param label - string for this command * @param label - string for this command
@ -105,6 +143,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/ */
public CompositeCommand(String label, String... aliases) { public CompositeCommand(String label, String... aliases) {
super(label); super(label);
this.topLabel = label;
this.plugin = BSkyBlock.getInstance(); this.plugin = BSkyBlock.getInstance();
setAliases(new ArrayList<>(Arrays.asList(aliases))); setAliases(new ArrayList<>(Arrays.asList(aliases)));
parent = null; parent = null;
@ -130,6 +169,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/ */
public CompositeCommand(CompositeCommand parent, String label, String... aliases) { public CompositeCommand(CompositeCommand parent, String label, String... aliases) {
super(label); super(label);
this.topLabel = parent.getTopLabel();
this.plugin = BSkyBlock.getInstance(); this.plugin = BSkyBlock.getInstance();
this.parent = parent; this.parent = parent;
subCommandLevel = parent.getLevel() + 1; subCommandLevel = parent.getLevel() + 1;
@ -143,17 +183,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
parent.getSubCommandAliases().put(alias, this); parent.getSubCommandAliases().put(alias, this);
} }
setUsage(""); setUsage("");
// Inherit permission prefix
this.permissionPrefix = parent.getPermissionPrefix();
// Inherit world
this.world = parent.getWorld();
setup(); setup();
// If this command does not define its own help class, then use the default help command // If this command does not define its own help class, then use the default help command
if (!getSubCommand("help").isPresent() && !label.equals("help")) { if (!getSubCommand("help").isPresent() && !label.equals("help")) {
new DefaultHelpCommand(this); new DefaultHelpCommand(this);
} }
// Inherit permission prefix
this.permissionPrefix = parent.getPermissionPrefix();
// Inherit world
this.world = parent.getWorld();
}
}
/* /*
* This method deals with the command execution. It traverses the tree of * This method deals with the command execution. It traverses the tree of
* subcommands until it finds the right object and then runs execute on it. * subcommands until it finds the right object and then runs execute on it.
@ -504,5 +544,18 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
public void setWorld(World world) { public void setWorld(World world) {
this.world = world; this.world = world;
} }
/**
* @return the addon
*/
public Addon getAddon() {
return addon;
}
/**
* @return top level label, e.g., island
*/
public String getTopLabel() {
return topLabel;
}
} }

View File

@ -51,7 +51,7 @@ public class DefaultHelpCommand extends CompositeCommand {
} }
} }
if (depth == 0) { if (depth == 0) {
user.sendMessage("commands.help.header"); user.sendMessage("commands.help.header", "[label]", getIWM().getFriendlyName(getWorld()));
} }
if (depth < MAX_DEPTH) { if (depth < MAX_DEPTH) {
if (!parent.getLabel().equals(HELP)) { if (!parent.getLabel().equals(HELP)) {

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.commands;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.admin.AdminGetRankCommand; import us.tastybento.bskyblock.commands.admin.AdminGetRankCommand;
@ -20,7 +19,16 @@ import us.tastybento.bskyblock.commands.admin.teams.AdminTeamMakeLeaderCommand;
public class AdminCommand extends CompositeCommand { public class AdminCommand extends CompositeCommand {
public AdminCommand() { public AdminCommand() {
super(Constants.ADMINCOMMAND, "bsb"); super("bsbadmin", "bsb");
}
@Override
public void setup() {
setPermissionPrefix("bskyblock");
setPermission("admin.*");
setOnlyPlayer(false);
setParameters("commands.admin.help.parameters");
setDescription("commands.admin.help.description");
setWorld(getPlugin().getIWM().getIslandWorld()); setWorld(getPlugin().getIWM().getIslandWorld());
new AdminVersionCommand(this); new AdminVersionCommand(this);
new AdminReloadCommand(this); new AdminReloadCommand(this);
@ -39,19 +47,10 @@ public class AdminCommand extends CompositeCommand {
new AdminSchemCommand(this); new AdminSchemCommand(this);
} }
@Override
public void setup() {
setPermissionPrefix("bskyblock");
setPermission("admin.*");
setOnlyPlayer(false);
setParameters("commands.admin.help.parameters");
setDescription("commands.admin.help.description");
}
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
if (!args.isEmpty()) { if (!args.isEmpty()) {
user.sendMessage("general.errors.unknown-command", "[label]", Constants.ADMINCOMMAND); user.sendMessage("general.errors.unknown-command", "[label]", getTopLabel());
return false; return false;
} }
// By default run the attached help command, if it exists (it should) // By default run the attached help command, if it exists (it should)

View File

@ -5,7 +5,6 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.island.IslandAboutCommand; import us.tastybento.bskyblock.commands.island.IslandAboutCommand;
@ -26,7 +25,19 @@ import us.tastybento.bskyblock.util.Util;
public class IslandCommand extends CompositeCommand { public class IslandCommand extends CompositeCommand {
public IslandCommand() { public IslandCommand() {
super(Constants.ISLANDCOMMAND, "is"); super("island", "is");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CompositeCommand#setup()
*/
@Override
public void setup() {
setDescription("commands.island.help.description");
setOnlyPlayer(true);
// Permission
setPermissionPrefix("bskyblock");
setPermission("island");
setWorld(getPlugin().getIWM().getIslandWorld()); setWorld(getPlugin().getIWM().getIslandWorld());
// Set up subcommands // Set up subcommands
new IslandAboutCommand(this); new IslandAboutCommand(this);
@ -45,18 +56,6 @@ public class IslandCommand extends CompositeCommand {
new IslandTeamCommand(this); new IslandTeamCommand(this);
} }
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CompositeCommand#setup()
*/
@Override
public void setup() {
setDescription("commands.island.help.description");
setOnlyPlayer(true);
// Permission
setPermissionPrefix("bskyblock");
setPermission("island");
}
/* (non-Javadoc) /* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@ -74,7 +73,7 @@ public class IslandCommand extends CompositeCommand {
// No islands currently // No islands currently
return getSubCommand("create").map(createCmd -> createCmd.execute(user, new ArrayList<>())).orElse(false); return getSubCommand("create").map(createCmd -> createCmd.execute(user, new ArrayList<>())).orElse(false);
} }
user.sendMessage("general.errors.unknown-command", "[label]", Constants.ISLANDCOMMAND); user.sendMessage("general.errors.unknown-command", "[label]", getTopLabel());
return false; return false;
} }

View File

@ -5,7 +5,6 @@ import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -64,7 +63,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
User target = User.getInstance(targetUUID); User target = User.getInstance(targetUUID);
User leader = User.getInstance(leaderUUID); User leader = User.getInstance(leaderUUID);
leader.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", getPlugin().getPlayers().getName(targetUUID)); leader.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", getPlugin().getPlayers().getName(targetUUID));
target.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Constants.ISLANDCOMMAND); target.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", getTopLabel());
getIslands().getIsland(world, leaderUUID).addMember(targetUUID); getIslands().getIsland(world, leaderUUID).addMember(targetUUID);
user.sendMessage("general.success"); user.sendMessage("general.success");
return true; return true;

View File

@ -19,7 +19,6 @@ public class IslandGoCommand extends CompositeCommand {
public IslandGoCommand(CompositeCommand islandCommand) { public IslandGoCommand(CompositeCommand islandCommand) {
super(islandCommand, "go", "home", "h"); super(islandCommand, "go", "home", "h");
new CustomIslandMultiHomeHelp(this);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -29,7 +28,8 @@ public class IslandGoCommand extends CompositeCommand {
public void setup() { public void setup() {
setPermission("island.home"); setPermission("island.home");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.go.description"); setDescription("commands.island.go.description");
new CustomIslandMultiHomeHelp(this);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -47,6 +47,7 @@ public class IslandGoCommand extends CompositeCommand {
int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getSettings().getMaxHomes()); int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getSettings().getMaxHomes());
if (homeValue > 1 && homeValue <= maxHomes) { if (homeValue > 1 && homeValue <= maxHomes) {
getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue); getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue);
user.sendMessage("commands.island.go.tip", "[label]", getTopLabel());
return true; return true;
} }
} }

View File

@ -10,7 +10,6 @@ import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -81,13 +80,13 @@ public class IslandResetCommand extends CompositeCommand {
} else { } else {
// Show how many seconds left to confirm // Show how many seconds left to confirm
int time = (int)((confirm.get(user.getUniqueId()) - System.currentTimeMillis()) / 1000D); int time = (int)((confirm.get(user.getUniqueId()) - System.currentTimeMillis()) / 1000D);
user.sendMessage("commands.island.reset.confirm", "[label]", Constants.ISLANDCOMMAND, SECONDS_PLACEHOLDER, String.valueOf(time)); user.sendMessage("commands.island.reset.confirm", "[label]", getTopLabel(), SECONDS_PLACEHOLDER, String.valueOf(time));
} }
return true; return true;
} }
private void requestConfirmation(User user) { private void requestConfirmation(User user) {
user.sendMessage("commands.island.reset.confirm", "[label]", Constants.ISLANDCOMMAND, SECONDS_PLACEHOLDER, String.valueOf(getSettings().getConfirmationTime())); user.sendMessage("commands.island.reset.confirm", "[label]", getTopLabel(), SECONDS_PLACEHOLDER, String.valueOf(getSettings().getConfirmationTime()));
// Require confirmation // Require confirmation
confirm.put(user.getUniqueId(), System.currentTimeMillis() + getSettings().getConfirmationTime() * 1000L); confirm.put(user.getUniqueId(), System.currentTimeMillis() + getSettings().getConfirmationTime() * 1000L);
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { Bukkit.getScheduler().runTaskLater(getPlugin(), () -> {

View File

@ -11,7 +11,6 @@ public class IslandSethomeCommand extends CompositeCommand {
public IslandSethomeCommand(CompositeCommand islandCommand) { public IslandSethomeCommand(CompositeCommand islandCommand) {
super(islandCommand, "sethome"); super(islandCommand, "sethome");
new CustomIslandMultiHomeHelp(this);
} }
@Override @Override
@ -19,6 +18,7 @@ public class IslandSethomeCommand extends CompositeCommand {
setPermission("island.sethome"); setPermission("island.sethome");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.sethome.description"); setDescription("commands.island.sethome.description");
new CustomIslandMultiHomeHelp(this);
} }
@Override @Override

View File

@ -15,14 +15,6 @@ public class IslandTeamCommand extends CompositeCommand {
public IslandTeamCommand(CompositeCommand parent) { public IslandTeamCommand(CompositeCommand parent) {
super(parent, "team"); super(parent, "team");
// Register commands
inviteCommand = new IslandTeamInviteCommand(this);
new IslandTeamLeaveCommand(this);
new IslandTeamSetownerCommand(this);
new IslandTeamKickCommand(this);
new IslandTeamInviteAcceptCommand(this);
new IslandTeamInviteRejectCommand(this);
} }
@Override @Override
@ -30,6 +22,13 @@ public class IslandTeamCommand extends CompositeCommand {
setPermission("island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.description"); setDescription("commands.island.team.description");
// Register commands
inviteCommand = new IslandTeamInviteCommand(this);
new IslandTeamLeaveCommand(this);
new IslandTeamSetownerCommand(this);
new IslandTeamKickCommand(this);
new IslandTeamInviteAcceptCommand(this);
new IslandTeamInviteRejectCommand(this);
} }
@Override @Override

View File

@ -6,7 +6,6 @@ import java.util.UUID;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
@ -91,7 +90,7 @@ public class IslandTeamInviteAcceptCommand extends CompositeCommand {
// Put player back into normal mode // Put player back into normal mode
user.setGameMode(GameMode.SURVIVAL); user.setGameMode(GameMode.SURVIVAL);
user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Constants.ISLANDCOMMAND); user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", getTopLabel());
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID)); User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
if (inviter != null) { if (inviter != null) {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName()); inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName());

View File

@ -141,10 +141,7 @@ public class AddonsManager {
addons.add(addon); addons.add(addon);
// Inform the console // Inform the console
plugin.log("Loading BSkyBlock addon " + addon.getDescription().getName() + "..."); plugin.log("Loading BSkyBlock addon " + addon.getDescription().getName() + "...");
// Run the onLoad() method
addon.onLoad();
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -30,4 +30,8 @@ public class CommandsManager {
return commands.get(command); return commands.get(command);
} }
public String listCommands() {
return commands.keySet().toString();
}
} }

View File

@ -421,7 +421,7 @@ public class IslandWorldManager {
/** /**
* Get max team size for this world * Get max team size for this world
* @param world * @param world - world
* @return max team size * @return max team size
*/ */
public int getMaxTeamSize(World world) { public int getMaxTeamSize(World world) {
@ -430,11 +430,19 @@ public class IslandWorldManager {
/** /**
* Get max homes for world * Get max homes for world
* @param world * @param world - world
* @return max homes * @return max homes
*/ */
public int getMaxHomes(World world) { public int getMaxHomes(World world) {
return worldSettings.get(Util.getWorld(world)).getMaxHomes(); return worldSettings.get(Util.getWorld(world)).getMaxHomes();
} }
/**
* Get the friendly name for world or related nether or end
* @param world - world
* @return Friendly name
*/
public String getFriendlyName(World world) {
return worldSettings.get(Util.getWorld(world)).getFriendlyName();
}
} }

View File

@ -522,7 +522,7 @@ public class IslandsManager {
} }
player.teleport(home); player.teleport(home);
if (number == 1) { if (number == 1) {
user.sendMessage("commands.island.go.teleport", "[label]", Constants.ISLANDCOMMAND); user.sendMessage("commands.island.go.teleport");
} else { } else {
user.sendMessage("commands.island.go.teleported", "[number]", String.valueOf(number)); user.sendMessage("commands.island.go.teleported", "[number]", String.valueOf(number));
} }

View File

@ -27,6 +27,7 @@ import us.tastybento.bskyblock.api.events.command.CommandEvent;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
@ -94,6 +95,11 @@ public class DefaultHelpCommandTest {
BukkitScheduler sch = mock(BukkitScheduler.class); BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch); when(Bukkit.getScheduler()).thenReturn(sch);
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
} }
@ -146,7 +152,7 @@ public class DefaultHelpCommandTest {
when(user.getTranslation("description")).thenReturn("the main island command"); when(user.getTranslation("description")).thenReturn("the main island command");
DefaultHelpCommand dhc = new DefaultHelpCommand(parent); DefaultHelpCommand dhc = new DefaultHelpCommand(parent);
dhc.execute(user, new ArrayList<>()); dhc.execute(user, new ArrayList<>());
Mockito.verify(user).sendMessage("commands.help.header"); Mockito.verify(user).sendMessage("commands.help.header", "[label]", "BSkyBlock");
Mockito.verify(user).getTranslation("island"); Mockito.verify(user).getTranslation("island");
Mockito.verify(user).getTranslation("parameters"); Mockito.verify(user).getTranslation("parameters");
Mockito.verify(user).getTranslation("description"); Mockito.verify(user).getTranslation("description");

View File

@ -96,6 +96,7 @@ public class AdminInfoCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);

View File

@ -89,6 +89,7 @@ public class AdminTeamAddCommandTest {
// Parent command has no aliases // Parent command has no aliases
ac = mock(AdminCommand.class); ac = mock(AdminCommand.class);
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ac.getTopLabel()).thenReturn("bsb");
// Player has island to begin with // Player has island to begin with
im = mock(IslandsManager.class); im = mock(IslandsManager.class);
@ -118,6 +119,7 @@ public class AdminTeamAddCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
} }

View File

@ -40,6 +40,7 @@ import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
@ -114,6 +115,11 @@ public class IslandBanCommandTest {
when(island.getBanned()).thenReturn(new HashSet<>()); when(island.getBanned()).thenReturn(new HashSet<>());
when(island.isBanned(Mockito.any())).thenReturn(false); when(island.isBanned(Mockito.any())).thenReturn(false);
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
} }

View File

@ -36,6 +36,7 @@ import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
@ -88,6 +89,7 @@ public class IslandBanlistCommandTest {
// Parent command has no aliases // Parent command has no aliases
ic = mock(IslandCommand.class); ic = mock(IslandCommand.class);
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ic.getTopLabel()).thenReturn("island");
// No island for player to begin with (set it later in the tests) // No island for player to begin with (set it later in the tests)
im = mock(IslandsManager.class); im = mock(IslandsManager.class);
@ -111,6 +113,11 @@ public class IslandBanlistCommandTest {
when(island.isBanned(Mockito.any())).thenReturn(false); when(island.isBanned(Mockito.any())).thenReturn(false);
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
} }
/** /**

View File

@ -27,12 +27,12 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
import us.tastybento.bskyblock.managers.island.NewIsland; import us.tastybento.bskyblock.managers.island.NewIsland;
@ -74,6 +74,7 @@ public class IslandResetCommandTest {
// Player // Player
Player p = mock(Player.class); Player p = mock(Player.class);
// User, sometime use Mockito.withSettings().verboseLogging()
user = mock(User.class); user = mock(User.class);
when(user.isOp()).thenReturn(false); when(user.isOp()).thenReturn(false);
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
@ -83,12 +84,14 @@ public class IslandResetCommandTest {
// Parent command has no aliases // Parent command has no aliases
ic = mock(IslandCommand.class); ic = mock(IslandCommand.class);
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ic.getTopLabel()).thenReturn("island");
// No island for player to begin with (set it later in the tests) // No island for player to begin with (set it later in the tests)
im = mock(IslandsManager.class); im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
when(plugin.getIslands()).thenReturn(im); when(plugin.getIslands()).thenReturn(im);
// Has team // Has team
pm = mock(PlayersManager.class); pm = mock(PlayersManager.class);
@ -99,6 +102,12 @@ public class IslandResetCommandTest {
BukkitScheduler sch = mock(BukkitScheduler.class); BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch); when(Bukkit.getScheduler()).thenReturn(sch);
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
} }
@ -272,7 +281,7 @@ public class IslandResetCommandTest {
// Reset // Reset
assertTrue(irc.execute(user, new ArrayList<>())); assertTrue(irc.execute(user, new ArrayList<>()));
Mockito.verify(user).sendMessage("commands.island.reset.confirm", "[label]", Constants.ISLANDCOMMAND, "[seconds]", String.valueOf(s.getConfirmationTime())); Mockito.verify(user).sendMessage("commands.island.reset.confirm", "[label]", "island", "[seconds]", String.valueOf(s.getConfirmationTime()));
// Reset confirm // Reset confirm
assertTrue(irc.execute(user, Arrays.asList("confirm"))); assertTrue(irc.execute(user, Arrays.asList("confirm")));

View File

@ -36,6 +36,7 @@ import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
@ -111,6 +112,10 @@ public class IslandUnbanCommandTest {
when(island.isBanned(Mockito.any())).thenReturn(false); when(island.isBanned(Mockito.any())).thenReturn(false);
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
} }
/** /**

View File

@ -29,6 +29,7 @@ import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.LocalesManager; import us.tastybento.bskyblock.managers.LocalesManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
@ -112,6 +113,11 @@ public class IslandTeamInviteCommandTest {
LocalesManager lm = mock(LocalesManager.class); LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm); 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);
} }
/** /**

View File

@ -32,6 +32,7 @@ import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.LocalesManager; import us.tastybento.bskyblock.managers.LocalesManager;
import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.PlayersManager;
@ -113,6 +114,11 @@ public class IslandTeamKickCommandTest {
LocalesManager lm = mock(LocalesManager.class); LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm); 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);
} }
/** /**