This commit is contained in:
tastybento 2024-01-22 14:50:24 -08:00 committed by GitHub
parent 5d3821094c
commit 13bd1bb8f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View File

@ -42,8 +42,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
}
// 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;
}
@ -99,6 +98,9 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
@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(),

View File

@ -178,6 +178,16 @@ public class IslandTeamSetownerCommandTest {
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)}.
@ -309,5 +319,15 @@ public class IslandTeamSetownerCommandTest {
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());
}
}