mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 05:28:59 +00:00
Check permissions for every top completion
This commit is contained in:
@@ -9,21 +9,25 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static com.dre.brewery.utility.PermissionUtil.BPermission.DRINK;
|
import static com.dre.brewery.utility.PermissionUtil.BPermission.*;
|
||||||
import static com.dre.brewery.utility.PermissionUtil.BPermission.WAKEUP;
|
|
||||||
|
|
||||||
public class TabListener implements TabCompleter {
|
public class TabListener implements TabCompleter {
|
||||||
|
private static final Map<String, PermissionUtil.BPermission> COMMAND_COMPLETIONS = new HashMap<>(10);
|
||||||
private static final String[] COMPLETIONS = {"unLabel", "help"};
|
static {
|
||||||
private static final String[] EXT_COMPLETIONS = {"info", "create", "reload", "drink", "itemName", "seal", "static", "puke", "wakeup"};
|
COMMAND_COMPLETIONS.put("help", null);
|
||||||
|
COMMAND_COMPLETIONS.put("unLabel", UNLABEL);
|
||||||
|
COMMAND_COMPLETIONS.put("create", CREATE);
|
||||||
|
COMMAND_COMPLETIONS.put("reload", RELOAD);
|
||||||
|
COMMAND_COMPLETIONS.put("drink", DRINK);
|
||||||
|
COMMAND_COMPLETIONS.put("itemName", RELOAD);
|
||||||
|
COMMAND_COMPLETIONS.put("seal", SEAL);
|
||||||
|
COMMAND_COMPLETIONS.put("static", STATIC);
|
||||||
|
COMMAND_COMPLETIONS.put("puke", PUKE);
|
||||||
|
COMMAND_COMPLETIONS.put("wakeup", WAKEUP);
|
||||||
|
}
|
||||||
|
|
||||||
private static final String[] QUALITY = {"1", "10"};
|
private static final String[] QUALITY = {"1", "10"};
|
||||||
|
|
||||||
@@ -38,20 +42,17 @@ public class TabListener implements TabCompleter {
|
|||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
|
|
||||||
List<String> commands;
|
List<String> commands = COMMAND_COMPLETIONS.entrySet().stream()
|
||||||
if (PermissionUtil.noExtendedPermissions(sender)) {
|
.filter(entry -> entry.getKey().startsWith(args[0]) && (entry.getValue() == null || entry.getValue().checkCached(sender)))
|
||||||
commands = filterWithInput(COMPLETIONS, args[0]);
|
.map(Map.Entry::getKey)
|
||||||
} else {
|
.collect(Collectors.toList());
|
||||||
Stream<String> filteredCompletionsStream = Arrays.stream(COMPLETIONS)
|
|
||||||
.filter(s -> s.startsWith(args[0]));
|
|
||||||
Stream<String> filteredExtendedCompletionsStream = Arrays.stream(EXT_COMPLETIONS)
|
|
||||||
.filter(s -> s.startsWith(args[0]));
|
|
||||||
|
|
||||||
commands = Stream.concat(filteredCompletionsStream, filteredExtendedCompletionsStream)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
if (commands.isEmpty()) {
|
if (commands.isEmpty()) {
|
||||||
return null; // Player List
|
if (PLAYER.checkCached(sender)) {
|
||||||
|
return null; // Player List
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>(0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user