-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabUtils.java
31 lines (24 loc) · 1 KB
/
TabUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package fi.natroutter.natlibs.utilities;
import fi.natroutter.natlibs.objects.Complete;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class TabUtils {
public static List<String> empty(){return Collections.singletonList("");}
public static List<String> completesWithPerms(CommandSender sender, String arg, List<Complete> list) {
List<String> newList = list.stream()
.filter(c -> sender.hasPermission(c.getPermission()))
.map(Complete::getArg)
.collect(Collectors.toList());
return completes(sender, arg, newList);
}
public static List<String> completes(CommandSender sender, String arg, List<String> list) {
List<String> shorted = new ArrayList<>();
StringUtil.copyPartialMatches(arg, list, shorted);
Collections.sort(shorted);
return shorted;
}
}