Adds island expel command.

Requires GameModeAddons to use it.

https://github.com/BentoBoxWorld/BentoBox/issues/524
This commit is contained in:
tastybento 2019-03-21 20:41:30 -07:00
parent 99e9ad6ac8
commit 7990378355
5 changed files with 594 additions and 1 deletions

View File

@ -0,0 +1,138 @@
package world.bentobox.bentobox.api.commands.island;
import java.util.List;
import java.util.UUID;
import org.bukkit.Sound;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
/**
* @author tastybento
* @since 1.4.0
*
*/
public class IslandExpelCommand extends CompositeCommand {
private @Nullable User target;
public IslandExpelCommand(CompositeCommand islandCommand) {
super(islandCommand, "expel");
}
@Override
public void setup() {
setOnlyPlayer(true);
setPermission("island.expel");
setParametersHelp("commands.island.expel.parameters");
setDescription("commands.island.expel.description");
setConfigurableRankCommand();
}
@Override
public boolean canExecute(User user, String label, List<String> args) {
if (args.size() != 1) {
// Show help
showHelp(this, user);
return false;
}
UUID playerUUID = 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)) {
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", TextVariables.NAME, args.get(0));
return false;
}
// Player cannot expel themselves
if (playerUUID.equals(targetUUID)) {
user.sendMessage("commands.island.expel.cannot-expel-yourself");
return false;
}
// Or team member
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
user.sendMessage("commands.island.expel.cannot-expel-member");
return false;
}
// Cannot expel offline players
target = User.getInstance(targetUUID);
if (!target.isOnline()) {
user.sendMessage("general.errors.offline-player");
return false;
}
// Not on island
if (!getIslands().locationIsOnIsland(user.getPlayer(), target.getLocation())) {
user.sendMessage("commands.island.expel.not-on-island");
return false;
}
// Cannot ban ops
if (target.isOp() || target.hasPermission("admin.noexpel")) {
user.sendMessage("commands.island.expel.cannot-expel");
return false;
}
return true;
}
@Override
public boolean execute(User user, String label, List<String> args) {
// Finished error checking - expel player
Island island = getIslands().getIsland(getWorld(), user);
// Fire event
IslandBaseEvent expelEvent = IslandEvent.builder()
.island(island)
.involvedPlayer(target.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.EXPEL)
.build();
if (expelEvent.isCancelled()) {
user.sendMessage("commands.island.expel.cannot-expel");
return false;
}
target.sendMessage("commands.island.expel.player-expelled-you", TextVariables.NAME, user.getName());
island.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
if (getIslands().hasIsland(getWorld(), target)) {
// Success
user.sendMessage("general.success");
// Teleport home
getIslands().homeTeleport(getWorld(), target.getPlayer());
return true;
} else if (getIslands().getSpawn(getWorld()).isPresent()){
// Success
user.sendMessage("general.success");
getIslands().spawnTeleport(getWorld(), user.getPlayer());
return true;
} else if (getIWM().getAddon(getWorld())
.map(gm -> gm.getPlayerCommand()
.map(pc -> pc.getSubCommand("create").isPresent())
.orElse(false))
.orElse(false)) {
if (target.performCommand(this.getTopLabel() + " create")) {
getAddon().logWarning("Expel: " + target.getName() + " had no island, so one was created");
user.sendMessage("general.success");
return true;
}
}
getAddon().logError("Expel: " + target.getName() + " had no island, and one could not be created");
user.sendMessage("commands.island.expel.cannot-expel");
return false;
}
}

View File

@ -117,13 +117,32 @@ public class IslandEvent extends IslandBaseEvent {
* Player was registered to the island by admin
* @since 1.3.0
*/
REGISTERED
REGISTERED,
/**
* Please was expelled
* @since 1.4.0
*/
EXPEL
}
public static IslandEventBuilder builder() {
return new IslandEventBuilder();
}
/**
* Fired when a player will be expelled from an island.
* May be cancelled.
* Cancellation will result in the expel being aborted.
*
* @since 1.4.0
*/
public static class IslandExpelEvent extends IslandBaseEvent {
private IslandExpelEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when a player will be banned from an island.
* May be cancelled.
@ -368,6 +387,10 @@ public class IslandEvent extends IslandBaseEvent {
Bukkit.getServer().getPluginManager().callEvent(new IslandEvent(island, player, admin, location, reason));
// Generate explicit events
switch (reason) {
case EXPEL:
IslandExpelEvent expel = new IslandExpelEvent(island, player, admin, location);
Bukkit.getServer().getPluginManager().callEvent(expel);
return expel;
case BAN:
IslandBanEvent ban = new IslandBanEvent(island, player, admin, location);
Bukkit.getServer().getPluginManager().callEvent(ban);

View File

@ -119,6 +119,10 @@ public class NewIsland {
return this;
}
/**
* @return Island
* @throws IOException - if there are insufficient parameters defined
*/
public Island build() throws IOException {
if (user2 != null) {
NewIsland newIsland = new NewIsland(oldIsland2, user2, reason2, world2, name2, noPaste2);

View File

@ -433,6 +433,14 @@ commands:
description: "display island settings"
language:
description: "select language"
expel:
description: "expel a player from your island"
parameters: "<player>"
cannot-expel-yourself: "&cYou cannot expel yourself!"
cannot-expel: "&cThat player cannot be expelled."
cannot-ban-member: "&cYou cannot expel a team member!"
not-on-island: "&cThat player is not on your island!"
player-expelled-you: "&b[name]&c expelled you from the island!"
ranks:
owner: "Owner"

View File

@ -0,0 +1,420 @@
/**
*
*/
package world.bentobox.bentobox.api.commands.island;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
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.addons.Addon;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager;
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 IslandExpelCommandTest {
@Mock
private CompositeCommand ic;
private UUID uuid;
@Mock
private User user;
@Mock
private IslandsManager im;
@Mock
private PlayersManager pm;
@Mock
private Island island;
@Mock
private LocalesManager lm;
@Mock
private IslandWorldManager iwm;
@Mock
private Addon addon;
private IslandExpelCommand iec;
@Before
public void setUp() throws Exception {
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
User.setPlugin(plugin);
// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
// Settings
Settings s = mock(Settings.class);
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
when(user.isOp()).thenReturn(false);
uuid = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(p);
when(user.getName()).thenReturn("tastybento");
// Parent command has no aliases
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
// Addon
when(ic.getAddon()).thenReturn(addon);
// No island for player to begin with (set it later in the tests)
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
when(plugin.getIslands()).thenReturn(im);
// No team to start
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
when(plugin.getPlayers()).thenReturn(pm);
// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
// Island Banned list initialization
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
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
// Server and Plugin Manager for events
Server server = mock(Server.class);
when(Bukkit.getServer()).thenReturn(server);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(island.getWorld()).thenReturn(mock(World.class));
// Locales
when(lm.get(Mockito.any(User.class), Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgumentAt(1, String.class));
when(plugin.getLocalesManager()).thenReturn(lm);
// Class
iec = new IslandExpelCommand(ic);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
User.clearUsers();
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#IslandExpelCommand(world.bentobox.bentobox.api.commands.CompositeCommand)}.
*/
@Test
public void testIslandExpelCommand() {
assertEquals("expel", iec.getLabel());
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#setup()}.
*/
@Test
public void testSetup() {
assertTrue(iec.isOnlyPlayer());
assertEquals("bskyblock.island.expel", iec.getPermission());
assertEquals("commands.island.expel.parameters", iec.getParameters());
assertEquals("commands.island.expel.description", iec.getDescription());
assertTrue(iec.isConfigurableRankCommand());
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteNoArgs() {
assertFalse(iec.canExecute(user, "", Collections.emptyList()));
Mockito.verify(user).sendMessage("commands.help.header", "[label]", null);
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteTooManyArgs() {
assertFalse(iec.canExecute(user, "", Arrays.asList("Hello", "there")));
Mockito.verify(user).sendMessage("commands.help.header", "[label]", null);
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteNoTeamNoIsland() {
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.errors.no-island");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteUnknownTargetUserInTeam() {
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.errors.unknown-player", TextVariables.NAME, "tasty");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteUnknownTargetUserHasIsland() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.errors.unknown-player", TextVariables.NAME, "tasty");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteLowRank() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(island.getRank(Mockito.any())).thenReturn(RanksManager.VISITOR_RANK);
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.errors.no-permission");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteSelf() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(uuid));
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.cannot-expel-yourself");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteTeamMember() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
UUID target = UUID.randomUUID();
when(pm.getUUID(Mockito.anyString())).thenReturn(target);
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(target));
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.cannot-expel-member");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteOfflinePlayer() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
UUID target = UUID.randomUUID();
when(pm.getUUID(Mockito.anyString())).thenReturn(target);
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.emptySet());
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.errors.offline-player");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteNotOnIsland() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
UUID target = UUID.randomUUID();
Player p = mock(Player.class);
when(p.isOnline()).thenReturn(true);
when(p.getUniqueId()).thenReturn(target);
User.getInstance(p);
when(pm.getUUID(Mockito.anyString())).thenReturn(target);
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.emptySet());
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.not-on-island");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteOp() {
when(im.locationIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(true);
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
UUID target = UUID.randomUUID();
Player p = mock(Player.class);
when(p.isOnline()).thenReturn(true);
when(p.getUniqueId()).thenReturn(target);
when(p.isOp()).thenReturn(true);
User.getInstance(p);
when(pm.getUUID(Mockito.anyString())).thenReturn(target);
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.emptySet());
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.cannot-expel");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteBypassPerm() {
when(im.locationIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(true);
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
UUID target = UUID.randomUUID();
Player p = mock(Player.class);
when(p.isOnline()).thenReturn(true);
when(p.getUniqueId()).thenReturn(target);
when(p.hasPermission(Mockito.anyString())).thenReturn(true);
User.getInstance(p);
when(pm.getUUID(Mockito.anyString())).thenReturn(target);
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.emptySet());
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.cannot-expel");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecute() {
when(im.locationIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(true);
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
setUpTarget();
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.emptySet());
assertTrue(iec.canExecute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user, Mockito.never()).sendMessage(Mockito.anyString());
}
private Player setUpTarget() {
UUID target = UUID.randomUUID();
Player p = mock(Player.class);
when(p.isOnline()).thenReturn(true);
when(p.getUniqueId()).thenReturn(target);
when(p.getLocation()).thenReturn(mock(Location.class));
when(p.performCommand(Mockito.anyString())).thenReturn(true);
when(p.getName()).thenReturn("target");
User.getInstance(p);
when(pm.getUUID(Mockito.anyString())).thenReturn(target);
return p;
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringHasIsland() {
testCanExecute();
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.success");
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.any());
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringNoIslandSendToSpawn() {
Optional<Island> optionalIsland = Optional.of(island);
when(im.getSpawn(Mockito.any())).thenReturn(optionalIsland);
testCanExecute();
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.success");
Mockito.verify(im).spawnTeleport(Mockito.any(), Mockito.any());
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringCreateIsland() {
GameModeAddon gma = mock(GameModeAddon.class);
CompositeCommand pc = mock(CompositeCommand.class);
Optional<CompositeCommand> optionalPlayerCommand = Optional.of(pc);
when(pc.getSubCommand(Mockito.anyString())).thenReturn(optionalPlayerCommand);
when(gma.getPlayerCommand()).thenReturn(optionalPlayerCommand);
Optional<GameModeAddon> optionalAddon = Optional.of(gma);
when(iwm.getAddon(Mockito.any())).thenReturn(optionalAddon);
when(im.getSpawn(Mockito.any())).thenReturn(Optional.empty());
testCanExecute();
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("general.success");
Mockito.verify(addon).logWarning(Mockito.eq("Expel: target had no island, so one was created"));
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringCreateIslandFailCommand() {
GameModeAddon gma = mock(GameModeAddon.class);
CompositeCommand pc = mock(CompositeCommand.class);
Optional<CompositeCommand> optionalPlayerCommand = Optional.empty();
when(pc.getSubCommand(Mockito.anyString())).thenReturn(optionalPlayerCommand);
when(gma.getPlayerCommand()).thenReturn(optionalPlayerCommand);
Optional<GameModeAddon> optionalAddon = Optional.of(gma);
when(iwm.getAddon(Mockito.any())).thenReturn(optionalAddon);
when(im.getSpawn(Mockito.any())).thenReturn(Optional.empty());
testCanExecute();
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
assertFalse(iec.execute(user, "", Collections.singletonList("tasty")));
Mockito.verify(addon).logError(Mockito.eq("Expel: target had no island, and one could not be created"));
Mockito.verify(user).sendMessage("commands.island.expel.cannot-expel");
}
}