diff --git a/locales/en-US.yml b/locales/en-US.yml index ce7ce82bb..b07731ff3 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -43,7 +43,7 @@ general: commands: help: - header: "&7=========== &c%bsb_plugin_name% &7===========" + header: "&7=========== &c[label] help &7===========" syntax: "&b[usage] &a[parameters]&7: &e[description]" end: "&7=================================" parameters: "[command]" @@ -122,12 +122,13 @@ commands: rank-set: "&aRank set from [from] to [to]." island: about: - description: "display info about %bsb_plugin_name%" + description: "display copyright and license info" go: parameters: "" 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]." + tip: "&bType /[label] help &afor help." help: description: "The main island command" pick-world: "&cSpecify world from [worlds]" diff --git a/src/main/java/us/tastybento/bskyblock/Constants.java b/src/main/java/us/tastybento/bskyblock/Constants.java index 9ab76eb8e..1223358c8 100644 --- a/src/main/java/us/tastybento/bskyblock/Constants.java +++ b/src/main/java/us/tastybento/bskyblock/Constants.java @@ -12,13 +12,6 @@ public class Constants { } 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) public static final String SPAWNCOMMAND = "spawn"; - // Admin command - public static final String ADMINCOMMAND = "bsadmin"; - } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java index bb90d37b6..b88823ae8 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java @@ -19,6 +19,7 @@ import org.bukkit.entity.Player; import us.tastybento.bskyblock.BSkyBlock; 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.user.User; 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 */ private World world; + + /** + * The addon creating this command, if any + */ + private Addon addon; + + /** + * The top level label + */ + private String topLabel = ""; /** * 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. * @param label - string for this command @@ -105,6 +143,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi */ public CompositeCommand(String label, String... aliases) { super(label); + this.topLabel = label; this.plugin = BSkyBlock.getInstance(); setAliases(new ArrayList<>(Arrays.asList(aliases))); parent = null; @@ -130,6 +169,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi */ public CompositeCommand(CompositeCommand parent, String label, String... aliases) { super(label); + this.topLabel = parent.getTopLabel(); this.plugin = BSkyBlock.getInstance(); this.parent = parent; subCommandLevel = parent.getLevel() + 1; @@ -143,17 +183,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi parent.getSubCommandAliases().put(alias, this); } setUsage(""); + // Inherit permission prefix + this.permissionPrefix = parent.getPermissionPrefix(); + // Inherit world + this.world = parent.getWorld(); setup(); // If this command does not define its own help class, then use the default help command if (!getSubCommand("help").isPresent() && !label.equals("help")) { 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 * 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) { this.world = world; } + + /** + * @return the addon + */ + public Addon getAddon() { + return addon; + } + /** + * @return top level label, e.g., island + */ + public String getTopLabel() { + return topLabel; + } } diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java index 44adea267..e2ee92777 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java @@ -51,7 +51,7 @@ public class DefaultHelpCommand extends CompositeCommand { } } if (depth == 0) { - user.sendMessage("commands.help.header"); + user.sendMessage("commands.help.header", "[label]", getIWM().getFriendlyName(getWorld())); } if (depth < MAX_DEPTH) { if (!parent.getLabel().equals(HELP)) { diff --git a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java index f0acc6bf4..3a1a78940 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java @@ -2,7 +2,6 @@ package us.tastybento.bskyblock.commands; import java.util.List; -import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.user.User; 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 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()); new AdminVersionCommand(this); new AdminReloadCommand(this); @@ -39,19 +47,10 @@ public class AdminCommand extends CompositeCommand { new AdminSchemCommand(this); } - @Override - public void setup() { - setPermissionPrefix("bskyblock"); - setPermission("admin.*"); - setOnlyPlayer(false); - setParameters("commands.admin.help.parameters"); - setDescription("commands.admin.help.description"); - } - @Override public boolean execute(User user, List args) { if (!args.isEmpty()) { - user.sendMessage("general.errors.unknown-command", "[label]", Constants.ADMINCOMMAND); + user.sendMessage("general.errors.unknown-command", "[label]", getTopLabel()); return false; } // By default run the attached help command, if it exists (it should) diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index 2c6a327fa..8af8fba75 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.island.IslandAboutCommand; @@ -26,7 +25,19 @@ import us.tastybento.bskyblock.util.Util; public class IslandCommand extends CompositeCommand { 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()); // Set up subcommands new IslandAboutCommand(this); @@ -45,18 +56,6 @@ public class IslandCommand extends CompositeCommand { 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) * @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 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; } diff --git a/src/main/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommand.java b/src/main/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommand.java index 55ccc49b8..dd0ffbd07 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommand.java @@ -5,7 +5,6 @@ import java.util.UUID; import org.bukkit.World; -import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.user.User; @@ -64,7 +63,7 @@ public class AdminTeamAddCommand extends CompositeCommand { User target = User.getInstance(targetUUID); User leader = User.getInstance(leaderUUID); 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); user.sendMessage("general.success"); return true; diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java index c496f6550..3f0d200ad 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java @@ -19,7 +19,6 @@ public class IslandGoCommand extends CompositeCommand { public IslandGoCommand(CompositeCommand islandCommand) { super(islandCommand, "go", "home", "h"); - new CustomIslandMultiHomeHelp(this); } /* (non-Javadoc) @@ -29,7 +28,8 @@ public class IslandGoCommand extends CompositeCommand { public void setup() { setPermission("island.home"); setOnlyPlayer(true); - setDescription("commands.island.go.description"); + setDescription("commands.island.go.description"); + new CustomIslandMultiHomeHelp(this); } /* (non-Javadoc) @@ -47,6 +47,7 @@ public class IslandGoCommand extends CompositeCommand { int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getSettings().getMaxHomes()); if (homeValue > 1 && homeValue <= maxHomes) { getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue); + user.sendMessage("commands.island.go.tip", "[label]", getTopLabel()); return true; } } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java index a0dcbbf0c..58fd53d4b 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java @@ -10,7 +10,6 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; -import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.user.User; @@ -81,13 +80,13 @@ public class IslandResetCommand extends CompositeCommand { } else { // Show how many seconds left to confirm 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; } 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 confirm.put(user.getUniqueId(), System.currentTimeMillis() + getSettings().getConfirmationTime() * 1000L); Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java index ba3c96d61..125e6b73f 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java @@ -11,7 +11,6 @@ public class IslandSethomeCommand extends CompositeCommand { public IslandSethomeCommand(CompositeCommand islandCommand) { super(islandCommand, "sethome"); - new CustomIslandMultiHomeHelp(this); } @Override @@ -19,6 +18,7 @@ public class IslandSethomeCommand extends CompositeCommand { setPermission("island.sethome"); setOnlyPlayer(true); setDescription("commands.island.sethome.description"); + new CustomIslandMultiHomeHelp(this); } @Override diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java index aa9eb0608..f5a333c78 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java @@ -15,14 +15,6 @@ public class IslandTeamCommand extends CompositeCommand { public IslandTeamCommand(CompositeCommand parent) { 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 @@ -30,6 +22,13 @@ public class IslandTeamCommand extends CompositeCommand { setPermission("island.team"); setOnlyPlayer(true); 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 diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java index 1d1b5fe31..763693cb8 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java @@ -6,7 +6,6 @@ import java.util.UUID; import org.bukkit.GameMode; import org.bukkit.Location; -import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent; @@ -91,7 +90,7 @@ public class IslandTeamInviteAcceptCommand extends CompositeCommand { // Put player back into normal mode 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)); if (inviter != null) { inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName()); diff --git a/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java b/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java index 91b71860a..eca3e0e64 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java @@ -141,10 +141,7 @@ public class AddonsManager { addons.add(addon); // Inform the console - plugin.log("Loading BSkyBlock addon " + addon.getDescription().getName() + "..."); - - // Run the onLoad() method - addon.onLoad(); + plugin.log("Loading BSkyBlock addon " + addon.getDescription().getName() + "..."); } } catch (Exception e) { diff --git a/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java b/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java index e01c6f3d7..20452f315 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java @@ -30,4 +30,8 @@ public class CommandsManager { return commands.get(command); } + public String listCommands() { + return commands.keySet().toString(); + } + } diff --git a/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java b/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java index 746ffc828..da64f25c2 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java @@ -421,7 +421,7 @@ public class IslandWorldManager { /** * Get max team size for this world - * @param world + * @param world - world * @return max team size */ public int getMaxTeamSize(World world) { @@ -430,11 +430,19 @@ public class IslandWorldManager { /** * Get max homes for world - * @param world + * @param world - world * @return max homes */ public int getMaxHomes(World world) { 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(); + } } diff --git a/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java b/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java index b19b21230..5aa383153 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java @@ -522,7 +522,7 @@ public class IslandsManager { } player.teleport(home); if (number == 1) { - user.sendMessage("commands.island.go.teleport", "[label]", Constants.ISLANDCOMMAND); + user.sendMessage("commands.island.go.teleport"); } else { user.sendMessage("commands.island.go.teleported", "[number]", String.valueOf(number)); } diff --git a/src/test/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommandTest.java b/src/test/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommandTest.java index 0b8aa78a6..bc066e924 100644 --- a/src/test/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommandTest.java @@ -27,6 +27,7 @@ import us.tastybento.bskyblock.api.events.command.CommandEvent; import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.managers.CommandsManager; +import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.PlayersManager; @@ -94,6 +95,11 @@ public class DefaultHelpCommandTest { BukkitScheduler sch = mock(BukkitScheduler.class); PowerMockito.mockStatic(Bukkit.class); 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"); DefaultHelpCommand dhc = new DefaultHelpCommand(parent); 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("parameters"); Mockito.verify(user).getTranslation("description"); diff --git a/src/test/java/us/tastybento/bskyblock/commands/admin/AdminInfoCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/admin/AdminInfoCommandTest.java index a0239e0b9..454624ea4 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/admin/AdminInfoCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/admin/AdminInfoCommandTest.java @@ -96,6 +96,7 @@ public class AdminInfoCommandTest { IslandWorldManager iwm = mock(IslandWorldManager.class); World world = mock(World.class); when(iwm.getIslandWorld()).thenReturn(world); + when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); when(plugin.getIWM()).thenReturn(iwm); diff --git a/src/test/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommandTest.java index 53392f66d..fbfe4d62a 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/admin/teams/AdminTeamAddCommandTest.java @@ -89,6 +89,7 @@ public class AdminTeamAddCommandTest { // Parent command has no aliases ac = mock(AdminCommand.class); when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); + when(ac.getTopLabel()).thenReturn("bsb"); // Player has island to begin with im = mock(IslandsManager.class); @@ -118,6 +119,7 @@ public class AdminTeamAddCommandTest { IslandWorldManager iwm = mock(IslandWorldManager.class); World world = mock(World.class); when(iwm.getIslandWorld()).thenReturn(world); + when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); when(plugin.getIWM()).thenReturn(iwm); } diff --git a/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanCommandTest.java index fc96b6672..0bb8fdc38 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanCommandTest.java @@ -40,6 +40,7 @@ import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.managers.CommandsManager; +import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.PlayersManager; @@ -114,6 +115,11 @@ public class IslandBanCommandTest { when(island.getBanned()).thenReturn(new HashSet<>()); when(island.isBanned(Mockito.any())).thenReturn(false); 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); } diff --git a/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanlistCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanlistCommandTest.java index 05f3d9b03..3ddd7d829 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanlistCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/island/IslandBanlistCommandTest.java @@ -36,6 +36,7 @@ import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.managers.CommandsManager; +import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.PlayersManager; @@ -88,6 +89,7 @@ public class IslandBanlistCommandTest { // Parent command has no aliases ic = mock(IslandCommand.class); when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); + when(ic.getTopLabel()).thenReturn("island"); // No island for player to begin with (set it later in the tests) im = mock(IslandsManager.class); @@ -111,6 +113,11 @@ public class IslandBanlistCommandTest { when(island.isBanned(Mockito.any())).thenReturn(false); 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); + } /** diff --git a/src/test/java/us/tastybento/bskyblock/commands/island/IslandResetCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/island/IslandResetCommandTest.java index 79d6c6776..7ef02aa96 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/island/IslandResetCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/island/IslandResetCommandTest.java @@ -27,12 +27,12 @@ import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.managers.CommandsManager; +import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.PlayersManager; import us.tastybento.bskyblock.managers.island.NewIsland; @@ -74,6 +74,7 @@ public class IslandResetCommandTest { // Player Player p = mock(Player.class); + // User, sometime use Mockito.withSettings().verboseLogging() user = mock(User.class); when(user.isOp()).thenReturn(false); uuid = UUID.randomUUID(); @@ -83,12 +84,14 @@ public class IslandResetCommandTest { // Parent command has no aliases ic = mock(IslandCommand.class); when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); + when(ic.getTopLabel()).thenReturn("island"); // No island for player to begin with (set it later in the tests) im = mock(IslandsManager.class); when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); when(plugin.getIslands()).thenReturn(im); + // Has team pm = mock(PlayersManager.class); @@ -99,6 +102,12 @@ public class IslandResetCommandTest { BukkitScheduler sch = mock(BukkitScheduler.class); PowerMockito.mockStatic(Bukkit.class); 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 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 assertTrue(irc.execute(user, Arrays.asList("confirm"))); diff --git a/src/test/java/us/tastybento/bskyblock/commands/island/IslandUnbanCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/island/IslandUnbanCommandTest.java index 720820c9c..34ebed744 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/island/IslandUnbanCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/island/IslandUnbanCommandTest.java @@ -36,6 +36,7 @@ import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.managers.CommandsManager; +import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.PlayersManager; @@ -111,6 +112,10 @@ public class IslandUnbanCommandTest { when(island.isBanned(Mockito.any())).thenReturn(false); 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); } /** diff --git a/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommandTest.java index e027233c4..81fbfe0b5 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommandTest.java @@ -29,6 +29,7 @@ import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.managers.CommandsManager; +import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.LocalesManager; import us.tastybento.bskyblock.managers.PlayersManager; @@ -112,6 +113,11 @@ public class IslandTeamInviteCommandTest { 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); } /** diff --git a/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommandTest.java b/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommandTest.java index e44acf4c1..cb9f56258 100644 --- a/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommandTest.java +++ b/src/test/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommandTest.java @@ -32,6 +32,7 @@ import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.managers.CommandsManager; +import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.LocalesManager; import us.tastybento.bskyblock.managers.PlayersManager; @@ -113,6 +114,11 @@ public class IslandTeamKickCommandTest { 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); } /**