Skip to content

Commit

Permalink
Fix for #2281
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 22, 2024
1 parent 5d38210 commit 762b9ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public boolean canExecute(User user, String label, List<String> args) {
}
// Can use if in a team
Island is = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
boolean inTeam = is.getMemberSet().contains(user.getUniqueId());
if (!inTeam) {
if (is == null || !is.getMemberSet().contains(user.getUniqueId())) {
user.sendMessage("general.errors.no-team");
return false;
}
Expand Down Expand Up @@ -99,6 +98,9 @@ protected boolean setOwner(User user, @NonNull UUID targetUUID2) {
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size() - 1) : "";
if (getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()) == null) {
return Optional.empty();
}
return Optional.of(Util.tabLimit(
getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()).getMemberSet().stream()
.filter(uuid -> !user.getUniqueId().equals(uuid)).map(getPlayers()::getName).toList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ public void testCanExecuteUserStringListOfStringNullOwner() {
assertFalse(its.canExecute(user, "", List.of("gibby")));
verify(user).sendMessage("general.errors.not-owner");
}

/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteUserStringListOfStringNotInTeamNoIsland() {
when(im.getPrimaryIsland(any(), any())).thenReturn(null);
assertFalse(its.canExecute(user, "", List.of("gibby")));
verify(user).sendMessage("general.errors.no-team");
}

/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
Expand Down Expand Up @@ -309,5 +319,15 @@ public void testTabCompleteUserStringListOfStringMember() {
when(island.getMemberSet()).thenReturn(ImmutableSet.of(target));
assertEquals("tastybento", its.tabComplete(user, "", List.of()).get().get(0));
}

/**
* Test method for
* {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamSetownerCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testTabCompleteUserStringListOfStringMemberNoIsland() {
when(im.getPrimaryIsland(any(), any())).thenReturn(null);
assertTrue(its.tabComplete(user, "", List.of()).isEmpty());
}

}

0 comments on commit 762b9ba

Please sign in to comment.