mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Changed island team kick to use confirm API
Fix for: https://github.com/BentoBoxWorld/bentobox/issues/214
This commit is contained in:
parent
bad870d3da
commit
53f28eb68d
@ -1,19 +1,13 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandTeamKickCommand extends CompositeCommand {
|
||||
|
||||
Set<UUID> kickSet;
|
||||
|
||||
public IslandTeamKickCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "kick");
|
||||
}
|
||||
@ -24,7 +18,6 @@ public class IslandTeamKickCommand extends CompositeCommand {
|
||||
setOnlyPlayer(true);
|
||||
setParameters("commands.island.team.kick.parameters");
|
||||
setDescription("commands.island.team.kick.description");
|
||||
kickSet = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,37 +49,30 @@ public class IslandTeamKickCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.not-in-team");
|
||||
return false;
|
||||
}
|
||||
if (!getSettings().isKickConfirmation() || kickSet.contains(targetUUID)) {
|
||||
kickSet.remove(targetUUID);
|
||||
User.getInstance(targetUUID).sendMessage("commands.island.team.kick.leader-kicked");
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
user.sendMessage("general.success");
|
||||
if (!getSettings().isKickConfirmation()) {
|
||||
kick(user, targetUUID);
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.kick.type-again");
|
||||
kickSet.add(targetUUID);
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (kickSet.contains(targetUUID)) {
|
||||
kickSet.remove(targetUUID);
|
||||
user.sendMessage("general.errors.command-cancelled");
|
||||
}
|
||||
}}.runTaskLater(getPlugin(), getSettings().getKickWait() * 20);
|
||||
this.askConfirmation(user, () -> kick(user, targetUUID));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void kick(User user, UUID targetUUID) {
|
||||
User.getInstance(targetUUID).sendMessage("commands.island.team.kick.leader-kicked");
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
user.sendMessage("general.success");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
@ -96,17 +96,17 @@ public class IslandTeamKickCommandTest {
|
||||
ic = mock(CompositeCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
@ -118,7 +118,7 @@ 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
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
@ -135,7 +135,7 @@ public class IslandTeamKickCommandTest {
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@ -146,7 +146,7 @@ public class IslandTeamKickCommandTest {
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-leader"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@ -156,7 +156,7 @@ public class IslandTeamKickCommandTest {
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@ -168,7 +168,7 @@ public class IslandTeamKickCommandTest {
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@ -180,8 +180,8 @@ public class IslandTeamKickCommandTest {
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.kick.cannot-kick"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@ -194,45 +194,45 @@ public class IslandTeamKickCommandTest {
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoConfirmation() {
|
||||
when(s.isKickConfirmation()).thenReturn(false);
|
||||
|
||||
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
|
||||
|
||||
Set<UUID> members = new HashSet<>();
|
||||
members.add(notUUID);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
|
||||
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithConfirmation() {
|
||||
when(s.isKickConfirmation()).thenReturn(true);
|
||||
|
||||
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
|
||||
|
||||
Set<UUID> members = new HashSet<>();
|
||||
members.add(notUUID);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
|
||||
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
// Confirmation required
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.kick.type-again"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,14 +241,14 @@ public class IslandTeamKickCommandTest {
|
||||
@Test
|
||||
public void testExecuteTestResets() {
|
||||
when(s.isKickConfirmation()).thenReturn(false);
|
||||
|
||||
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
|
||||
|
||||
Set<UUID> members = new HashSet<>();
|
||||
members.add(notUUID);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
|
||||
|
||||
|
||||
// Require resets
|
||||
when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true);
|
||||
Inventory enderChest = mock(Inventory.class);
|
||||
@ -262,7 +262,7 @@ public class IslandTeamKickCommandTest {
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
|
||||
|
||||
Mockito.verify(enderChest).clear();
|
||||
Mockito.verify(inv).clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user