Skip to content

Commit

Permalink
Fixes kick command (#1960)
Browse files Browse the repository at this point in the history
PR #1957 broke kick command and noone could kick players from teams.
This should fix it.
  • Loading branch information
BONNe authored Apr 3, 2022
1 parent c02e566 commit ad0931f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean execute(User user, String label, List<String> args) {
return false;
}

int targetRank = Objects.requireNonNull(island).getRank(user);
int targetRank = Objects.requireNonNull(island).getRank(targetUUID);
if (rank <= targetRank) {
user.sendMessage("commands.island.team.kick.cannot-kick-rank",
TextVariables.NAME, getPlayers().getName(targetUUID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public void setUp() throws Exception {
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);

// Ranks
when(island.getRank(uuid)).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(user)).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(notUUID)).thenReturn(RanksManager.MEMBER_RANK);
}

@After
Expand All @@ -206,11 +210,75 @@ public void testExecuteNoTeam() {
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
*/
@Test
public void testExecuteNotTeamOwner() {
when(im.getOwner(any(), any())).thenReturn(notUUID);
public void testExecuteLowerTeamRank() {
when(island.getRank(user)).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(notUUID)).thenReturn(RanksManager.SUB_OWNER_RANK);

when(pm.getUUID(any())).thenReturn(notUUID);
when(pm.getName(notUUID)).thenReturn("poslovitch");

Set<UUID> members = new HashSet<>();
members.add(notUUID);
when(im.getMembers(any(), any())).thenReturn(members);

IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
}


/**
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
*/
@Test
public void testExecuteEqualTeamRank() {
when(island.getRank(user)).thenReturn(RanksManager.SUB_OWNER_RANK);
when(island.getRank(notUUID)).thenReturn(RanksManager.SUB_OWNER_RANK);

when(pm.getUUID(any())).thenReturn(notUUID);
when(pm.getName(notUUID)).thenReturn("poslovitch");

Set<UUID> members = new HashSet<>();
members.add(notUUID);
when(im.getMembers(any(), any())).thenReturn(members);

IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
}

/**
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
*/
@Test
public void testExecuteLargerTeamRank() {
when(island.getRank(user)).thenReturn(RanksManager.SUB_OWNER_RANK);
when(island.getRank(notUUID)).thenReturn(RanksManager.MEMBER_RANK);

when(pm.getUUID(any())).thenReturn(notUUID);
when(pm.getName(notUUID)).thenReturn("poslovitch");

Set<UUID> members = new HashSet<>();
members.add(notUUID);
when(im.getMembers(any(), any())).thenReturn(members);

IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(im).removePlayer(any(), eq(notUUID));
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch");
}

/**
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
*/
@Test
public void testExecuteNoCommandRank() {
when(island.getRankCommand(anyString())).thenReturn(RanksManager.SUB_OWNER_RANK);
when(island.getRank(user)).thenReturn(RanksManager.MEMBER_RANK);

IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.emptyList()));
verify(user).sendMessage(eq("general.errors.not-owner"));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member"));
}

/**
Expand Down

0 comments on commit ad0931f

Please sign in to comment.