mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 13:15:28 +01:00
parent
a612f20af9
commit
722f136e3f
@ -1,10 +1,7 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.team;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
@ -12,11 +9,17 @@ import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Kicks the specified player from the island team.
|
||||
* @author tastybento
|
||||
*/
|
||||
public class AdminTeamKickCommand extends CompositeCommand {
|
||||
|
||||
public AdminTeamKickCommand(CompositeCommand parent) {
|
||||
super(parent, "kick");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,18 +52,23 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID.equals(getIslands().getOwner(getWorld(), targetUUID))) {
|
||||
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
|
||||
if (targetUUID.equals(island.getOwner())) {
|
||||
user.sendMessage("commands.admin.team.kick.cannot-kick-owner");
|
||||
getIslands().getIsland(getWorld(), targetUUID).showMembers(user);
|
||||
island.showMembers(user);
|
||||
return false;
|
||||
}
|
||||
User.getInstance(targetUUID).sendMessage("commands.admin.team.kick.admin-kicked");
|
||||
User target = User.getInstance(targetUUID);
|
||||
target.sendMessage("commands.admin.team.kick.admin-kicked");
|
||||
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner()));
|
||||
|
||||
// Fire event so add-ons know
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(island)
|
||||
.reason(TeamEvent.Reason.KICK)
|
||||
|
@ -74,6 +74,7 @@ commands:
|
||||
cannot-kick-owner: "&cYou cannot kick the owner. Kick members first."
|
||||
not-in-team: "&cThis player is not in a team."
|
||||
admin-kicked: "&cThe admin kicked you from the team."
|
||||
success: "&b[name] &ahas been kicked from &b[owner]&a's island."
|
||||
setowner:
|
||||
parameters: "<player>"
|
||||
description: "transfers island ownership to the player"
|
||||
|
@ -1,18 +1,5 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.team;
|
||||
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,9 +13,9 @@ 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.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;
|
||||
@ -37,6 +24,20 @@ import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
@ -122,7 +123,6 @@ public class AdminTeamKickCommandTest {
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -172,7 +172,7 @@ public class AdminTeamKickCommandTest {
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
|
||||
when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(notUUID);
|
||||
when(is.getOwner()).thenReturn(notUUID);
|
||||
|
||||
AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
@ -188,15 +188,16 @@ public class AdminTeamKickCommandTest {
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
Island is = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
||||
String[] name = {"tastybento"};
|
||||
String name = "tastybento";
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(pm.getName(Mockito.any())).thenReturn(name);
|
||||
|
||||
when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(uuid);
|
||||
when(is.getOwner()).thenReturn(uuid);
|
||||
|
||||
AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList(name)));
|
||||
Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.team.kick.success"), Mockito.eq(TextVariables.NAME), Mockito.eq(name), Mockito.eq("[owner]"), Mockito.anyString());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user