Skip to content

Commit

Permalink
Change admin kick command to just kick from all teams.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 26, 2024
1 parent 2fedb88 commit 55daa72
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.IslandInfo;
import world.bentobox.bentobox.util.Util;

/**
Expand Down Expand Up @@ -79,7 +78,7 @@ public boolean execute(User user, String label, @NonNull List<String> args) {
.rankChange(island.getRank(target), RanksManager.VISITOR_RANK).build();
}
});
user.sendRawMessage("Player removed from all teams in this world");
user.sendMessage("commands.admin.team.kick.success-all");

return true;
}
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 @@ -159,6 +159,7 @@ commands:
not-in-team: '&c This player is not in a team.'
admin-kicked: '&c The admin kicked you from the team.'
success: '&b [name] &a has been kicked from &b [owner]&a ''s island.'
success-all: '&b Player removed from all teams in this world'
setowner:
parameters: <player>
description: transfers island ownership to the player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class AdminTeamKickCommandTest {
private World world;
@Mock
private PluginManager pim;
@Mock
private Island island;
@Mock
private Island island2;

/**
*/
Expand Down Expand Up @@ -106,9 +110,14 @@ public void setUp() throws Exception {
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);

// Island
when(island.getOwner()).thenReturn(uuid);
when(island2.getOwner()).thenReturn(notUUID);

// Player has island to begin with
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
when(im.getIslands(world, uuid)).thenReturn(List.of(island, island2));
// when(im.isOwner(any(),any())).thenReturn(true);
// when(im.getOwner(any(),any())).thenReturn(uuid);
when(plugin.getIslands()).thenReturn(im);
Expand Down Expand Up @@ -172,46 +181,21 @@ public void testCanExecutePlayerNotInTeam() {
verify(user).sendMessage(eq("commands.admin.team.kick.not-in-team"));
}

/**
* Test method for {@link AdminTeamKickCommand#execute(User, String, List)} .
*/
@Test
public void testExecuteKickOwner() {
when(im.inTeam(any(), any())).thenReturn(true);
Island is = mock(Island.class);
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
when(pm.getUUID(any())).thenReturn(notUUID);

when(is.getOwner()).thenReturn(notUUID);

AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
verify(user).sendMessage(eq("commands.admin.team.kick.cannot-kick-owner"));
verify(user).sendMessage("commands.admin.info.team-members-title");
verify(im, never()).removePlayer(eq(world), eq(notUUID));
verify(user, never()).sendMessage(eq("commands.admin.team.kick.success"), anyString(), anyString(), anyString(), anyString());
verify(pim, never()).callEvent(any());
}

/**
* Test method for {@link world.bentobox.bentobox.api.commands.admin.team.AdminTeamKickCommand#execute(User, String, List)}.
*/
@Test
public void testExecute() {
when(im.inTeam(any(), any())).thenReturn(true);
Island is = mock(Island.class);
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
String name = "tastybento";
when(pm.getUUID(any())).thenReturn(notUUID);
when(pm.getUUID(any())).thenReturn(uuid);
when(pm.getName(any())).thenReturn(name);

when(is.getOwner()).thenReturn(uuid);

AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList(name)));
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList(name)));
verify(im).removePlayer(is, notUUID);
verify(im, never()).removePlayer(island, uuid);
verify(im).removePlayer(island2, uuid);
verify(user).sendMessage(eq("commands.admin.team.kick.success"), eq(TextVariables.NAME), eq(name), eq("[owner]"), anyString());
// Offline so event will be called 4 times
verify(pim, times(4)).callEvent(any());
Expand Down

0 comments on commit 55daa72

Please sign in to comment.