Skip to content

Commit

Permalink
Added better success message to AdminTeamKickCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Poslovitch committed Apr 28, 2019
1 parent a612f20 commit 722f136
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
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;
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
Expand Down Expand Up @@ -49,18 +52,23 @@ public boolean canExecute(User user, String label, List<String> args) {
}

@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)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,9 +13,9 @@
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;
Expand All @@ -37,6 +24,20 @@
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
*
Expand Down Expand Up @@ -122,7 +123,6 @@ public void setUp() throws Exception {
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);

}


Expand Down Expand Up @@ -172,7 +172,7 @@ public void testExecuteKickOwner() {
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)));
Expand All @@ -188,15 +188,16 @@ public void testExecute() {
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());
}

}

0 comments on commit 722f136

Please sign in to comment.