Added better success message to AdminTeamKickCommand

#630
This commit is contained in:
Florian CUNY 2019-04-28 10:39:31 +02:00
parent a612f20af9
commit 722f136e3f
3 changed files with 41 additions and 31 deletions

View File

@ -1,10 +1,7 @@
package world.bentobox.bentobox.api.commands.admin.team; package world.bentobox.bentobox.api.commands.admin.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent; 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.api.user.User;
import world.bentobox.bentobox.database.objects.Island; 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 class AdminTeamKickCommand extends CompositeCommand {
public AdminTeamKickCommand(CompositeCommand parent) { public AdminTeamKickCommand(CompositeCommand parent) {
super(parent, "kick"); super(parent, "kick");
} }
@Override @Override
@ -49,18 +52,23 @@ public class AdminTeamKickCommand extends CompositeCommand {
} }
@Override @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)); 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"); user.sendMessage("commands.admin.team.kick.cannot-kick-owner");
getIslands().getIsland(getWorld(), targetUUID).showMembers(user); island.showMembers(user);
return false; 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); 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 // Fire event so add-ons know
Island island = getIslands().getIsland(getWorld(), targetUUID);
IslandBaseEvent event = TeamEvent.builder() IslandBaseEvent event = TeamEvent.builder()
.island(island) .island(island)
.reason(TeamEvent.Reason.KICK) .reason(TeamEvent.Reason.KICK)

View File

@ -74,6 +74,7 @@ commands:
cannot-kick-owner: "&cYou cannot kick the owner. Kick members first." cannot-kick-owner: "&cYou cannot kick the owner. Kick members first."
not-in-team: "&cThis player is not in a team." not-in-team: "&cThis player is not in a team."
admin-kicked: "&cThe admin kicked you from the team." admin-kicked: "&cThe admin kicked you from the team."
success: "&b[name] &ahas been kicked from &b[owner]&a's island."
setowner: setowner:
parameters: "<player>" parameters: "<player>"
description: "transfers island ownership to the player" description: "transfers island ownership to the player"

View File

@ -1,18 +1,5 @@
package world.bentobox.bentobox.api.commands.admin.team; 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.Bukkit;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; 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.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand; 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.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager; 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.LocalesManager;
import world.bentobox.bentobox.managers.PlayersManager; 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 * @author tastybento
* *
@ -122,7 +123,6 @@ public class AdminTeamKickCommandTest {
PluginManager pim = mock(PluginManager.class); PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim); when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server); when(Bukkit.getServer()).thenReturn(server);
} }
@ -172,7 +172,7 @@ public class AdminTeamKickCommandTest {
String[] name = {"tastybento"}; String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(notUUID); 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); AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); 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); when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
Island is = mock(Island.class); Island is = mock(Island.class);
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); 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.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); 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(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());
} }
} }