mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-02 13:31:47 +01:00
Improved tab-completion for AdminSetrankCommand
Relates to https://github.com/BentoBoxWorld/BentoBox/issues/787
This commit is contained in:
parent
958bafdabf
commit
ceef422c54
@ -13,6 +13,7 @@ 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.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -81,6 +82,19 @@ public class AdminSetrankCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
return Optional.of(getPlugin().getRanksManager().getRanks().keySet().stream().map(user::getTranslation).collect(Collectors.toList()));
|
||||
// Return the player names
|
||||
if (args.size() == 2) {
|
||||
return Optional.of(Util.getOnlinePlayerList(user));
|
||||
}
|
||||
|
||||
// Return the rank first
|
||||
if (args.size() == 3) {
|
||||
return Optional.of(getPlugin().getRanksManager().getRanks()
|
||||
.entrySet().stream()
|
||||
.filter(entry -> entry.getValue() > RanksManager.VISITOR_RANK)
|
||||
.map(entry -> user.getTranslation(entry.getKey())).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -214,15 +215,16 @@ public class AdminSetrankCommandTest {
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Ignore("NPE on Bukkit method")
|
||||
@Test
|
||||
public void testTabCompleteUserStringListOfString() {
|
||||
when(rm.getRanks()).thenReturn(Collections.singletonMap("visitor", 0));
|
||||
when(user.getTranslation(any())).thenReturn("visitor");
|
||||
Optional<List<String>> result = c.tabComplete(user, "", Collections.emptyList());
|
||||
when(rm.getRanks()).thenReturn(Collections.singletonMap("owner", 0));
|
||||
when(user.getTranslation(any())).thenReturn("owner");
|
||||
Optional<List<String>> result = c.tabComplete(user, "", Arrays.asList("setrank", ""));
|
||||
assertTrue(result.isPresent());
|
||||
result.ifPresent(list -> {
|
||||
assertTrue(list.size() == 1);
|
||||
assertEquals("visitor", list.get(0));
|
||||
assertEquals("owner", list.get(0));
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user