Partially add clickable command listings - towards #68

This commit is contained in:
Luck 2016-12-07 22:09:11 +00:00
parent 4ecb2c7c27
commit 2da7979d94
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 296 additions and 274 deletions

View File

@ -50,6 +50,7 @@ import me.lucko.luckperms.common.commands.usersbulkedit.UsersBulkEditMainCommand
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import java.util.ArrayList;
import java.util.Collections;
@ -58,7 +59,186 @@ import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import io.github.mkremins.fanciful.ChatColor;
import io.github.mkremins.fanciful.FancyMessage;
public class CommandManager {
@Getter
private final LuckPermsPlugin plugin;
@Getter
private final List<BaseCommand> mainCommands;
public CommandManager(LuckPermsPlugin plugin) {
this.plugin = plugin;
ImmutableList.Builder<BaseCommand> l = ImmutableList.builder();
l.add(new UserMainCommand())
.add(new GroupMainCommand())
.add(new TrackMainCommand())
.addAll(plugin.getExtraCommands())
.add(new LogMainCommand())
.add(new SyncCommand())
.add(new NetworkSyncCommand())
.add(new InfoCommand())
.add(new VerboseCommand())
.add(new ImportCommand())
.add(new ExportCommand())
.add(new QueueCommand())
.add(new MigrationMainCommand())
.add(new UsersBulkEditMainCommand())
.add(new CreateGroup())
.add(new DeleteGroup())
.add(new ListGroups())
.add(new CreateTrack())
.add(new DeleteTrack())
.add(new ListTracks());
mainCommands = l.build();
}
/**
* Generic on command method to be called from the command executor object of the platform
* Unlike {@link #onCommand(Sender, String, List)}, this method is called in a new thread
*
* @param sender who sent the command
* @param label the command label used
* @param args the arguments provided
* @param result the callback to be called when the command has fully executed
*/
public void onCommand(Sender sender, String label, List<String> args, Consumer<CommandResult> result) {
plugin.doAsync(() -> {
CommandResult r = onCommand(sender, label, args);
if (result != null) {
plugin.doSync(() -> result.accept(r));
}
});
}
/**
* Generic on command method to be called from the command executor object of the platform
*
* @param sender who sent the command
* @param label the command label used
* @param args the arguments provided
* @return if the command was successful
*/
@SuppressWarnings("unchecked")
public CommandResult onCommand(Sender sender, String label, List<String> args) {
// Handle no arguments
if (args.size() == 0) {
sendCommandUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
// Look for the main command.
Optional<BaseCommand> o = mainCommands.stream()
.filter(m -> m.getName().equalsIgnoreCase(args.get(0)))
.limit(1)
.findAny();
// Main command not found
if (!o.isPresent()) {
sendCommandUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
// Check the Sender has permission to use the main command.
final Command main = o.get();
if (!main.isAuthorized(sender)) {
sendCommandUsage(sender, label);
return CommandResult.NO_PERMISSION;
}
List<String> arguments = new ArrayList<>(args);
handleRewrites(arguments);
arguments.remove(0); // remove the main command arg.
// Check the correct number of args were given for the main command
if (main.getArgumentCheck().test(arguments.size())) {
main.sendUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
// Try to execute the command.
CommandResult result;
try {
result = main.execute(plugin, sender, null, arguments, label);
} catch (CommandException e) {
result = handleException(e, sender, label, main);
} catch (Exception e) {
e.printStackTrace();
result = CommandResult.FAILURE;
}
return result;
}
/**
* Generic tab complete method to be called from the command executor object of the platform
*
* @param sender who is tab completing
* @param args the arguments provided so far
* @return a list of suggestions
*/
@SuppressWarnings("unchecked")
public List<String> onTabComplete(Sender sender, List<String> args) {
final List<Command> mains = mainCommands.stream()
.filter(m -> m.isAuthorized(sender))
.collect(Collectors.toList());
// Not yet past the point of entering a main command
if (args.size() <= 1) {
// Nothing yet entered
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return mains.stream()
.map(m -> m.getName().toLowerCase())
.collect(Collectors.toList());
}
// Started typing a main command
return mains.stream()
.map(m -> m.getName().toLowerCase())
.filter(s -> s.startsWith(args.get(0).toLowerCase()))
.collect(Collectors.toList());
}
// Find a main command matching the first arg
Optional<Command> o = mains.stream()
.filter(m -> m.getName().equalsIgnoreCase(args.get(0)))
.limit(1)
.findAny();
if (!o.isPresent()) {
return Collections.emptyList();
}
// Pass the processing onto the main command
return o.get().tabComplete(plugin, sender, args.subList(1, args.size()));
}
private void sendCommandUsage(Sender sender, String label) {
Util.sendPluginMessage(sender, "&2Running &bLuckPerms v" + plugin.getVersion() + "&2.");
mainCommands.stream()
.filter(c -> c.isAuthorized(sender))
.forEach(c -> {
@SuppressWarnings("unchecked")
String permission = (String) c.getPermission().map(p -> ((Permission) p).getExample()).orElse("None");
FancyMessage msg = new FancyMessage("> ").color(ChatColor.getByChar('3')).then().text(String.format(c.getUsage(), label)).color(ChatColor.getByChar('a'))
.formattedTooltip(
new FancyMessage("Command: ").color(ChatColor.getByChar('b')).then().text(c.getName()).color(ChatColor.getByChar('2')),
new FancyMessage("Description: ").color(ChatColor.getByChar('b')).then().text(c.getDescription()).color(ChatColor.getByChar('2')),
new FancyMessage("Usage: ").color(ChatColor.getByChar('b')).then().text(String.format(c.getUsage(), label)).color(ChatColor.getByChar('2')),
new FancyMessage("Permission: ").color(ChatColor.getByChar('b')).then().text(permission).color(ChatColor.getByChar('2')),
new FancyMessage(" "),
new FancyMessage("Click to auto-complete.").color(ChatColor.getByChar('7'))
)
.suggest(String.format(c.getUsage(), label));
sender.sendMessage(msg);
});
}
public static CommandResult handleException(CommandException e, Sender sender, String label, Command command) {
if (e instanceof ArgumentUtils.ArgumentException) {
if (e instanceof ArgumentUtils.DetailedUsageException) {
@ -223,165 +403,4 @@ public class CommandManager {
}
}
}
@Getter
private final LuckPermsPlugin plugin;
@Getter
private final List<BaseCommand> mainCommands;
public CommandManager(LuckPermsPlugin plugin) {
this.plugin = plugin;
ImmutableList.Builder<BaseCommand> l = ImmutableList.builder();
l.add(new UserMainCommand())
.add(new GroupMainCommand())
.add(new TrackMainCommand())
.addAll(plugin.getExtraCommands())
.add(new LogMainCommand())
.add(new SyncCommand())
.add(new NetworkSyncCommand())
.add(new InfoCommand())
.add(new VerboseCommand())
.add(new ImportCommand())
.add(new ExportCommand())
.add(new QueueCommand())
.add(new MigrationMainCommand())
.add(new UsersBulkEditMainCommand())
.add(new CreateGroup())
.add(new DeleteGroup())
.add(new ListGroups())
.add(new CreateTrack())
.add(new DeleteTrack())
.add(new ListTracks());
mainCommands = l.build();
}
/**
* Generic on command method to be called from the command executor object of the platform
* Unlike {@link #onCommand(Sender, String, List)}, this method is called in a new thread
*
* @param sender who sent the command
* @param label the command label used
* @param args the arguments provided
* @param result the callback to be called when the command has fully executed
*/
public void onCommand(Sender sender, String label, List<String> args, Consumer<CommandResult> result) {
plugin.doAsync(() -> {
CommandResult r = onCommand(sender, label, args);
if (result != null) {
plugin.doSync(() -> result.accept(r));
}
});
}
/**
* Generic on command method to be called from the command executor object of the platform
*
* @param sender who sent the command
* @param label the command label used
* @param args the arguments provided
* @return if the command was successful
*/
@SuppressWarnings("unchecked")
public CommandResult onCommand(Sender sender, String label, List<String> args) {
// Handle no arguments
if (args.size() == 0) {
sendCommandUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
// Look for the main command.
Optional<BaseCommand> o = mainCommands.stream()
.filter(m -> m.getName().equalsIgnoreCase(args.get(0)))
.limit(1)
.findAny();
// Main command not found
if (!o.isPresent()) {
sendCommandUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
// Check the Sender has permission to use the main command.
final Command main = o.get();
if (!main.isAuthorized(sender)) {
sendCommandUsage(sender, label);
return CommandResult.NO_PERMISSION;
}
List<String> arguments = new ArrayList<>(args);
handleRewrites(arguments);
arguments.remove(0); // remove the main command arg.
// Check the correct number of args were given for the main command
if (main.getArgumentCheck().test(arguments.size())) {
main.sendUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
// Try to execute the command.
CommandResult result;
try {
result = main.execute(plugin, sender, null, arguments, label);
} catch (CommandException e) {
result = handleException(e, sender, label, main);
} catch (Exception e) {
e.printStackTrace();
result = CommandResult.FAILURE;
}
return result;
}
/**
* Generic tab complete method to be called from the command executor object of the platform
*
* @param sender who is tab completing
* @param args the arguments provided so far
* @return a list of suggestions
*/
@SuppressWarnings("unchecked")
public List<String> onTabComplete(Sender sender, List<String> args) {
final List<Command> mains = mainCommands.stream()
.filter(m -> m.isAuthorized(sender))
.collect(Collectors.toList());
// Not yet past the point of entering a main command
if (args.size() <= 1) {
// Nothing yet entered
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return mains.stream()
.map(m -> m.getName().toLowerCase())
.collect(Collectors.toList());
}
// Started typing a main command
return mains.stream()
.map(m -> m.getName().toLowerCase())
.filter(s -> s.startsWith(args.get(0).toLowerCase()))
.collect(Collectors.toList());
}
// Find a main command matching the first arg
Optional<Command> o = mains.stream()
.filter(m -> m.getName().equalsIgnoreCase(args.get(0)))
.limit(1)
.findAny();
if (!o.isPresent()) {
return Collections.emptyList();
}
// Pass the processing onto the main command
return o.get().tabComplete(plugin, sender, args.subList(1, args.size()));
}
private void sendCommandUsage(Sender sender, String label) {
Util.sendPluginMessage(sender, "&2Running &bLuckPerms v" + plugin.getVersion() + "&2.");
mainCommands.stream()
.filter(c -> c.isAuthorized(sender))
.forEach(c -> Util.sendPluginMessage(sender, "&3> &a" + String.format(c.getUsage(), label)));
}
}

View File

@ -25,149 +25,152 @@ package me.lucko.luckperms.common.constants;
import lombok.AllArgsConstructor;
import lombok.Getter;
import com.google.common.collect.Sets;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import java.util.Set;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("SpellCheckingInspection")
@Getter
public enum Permission {
SYNC(set("sync"), Type.NONE),
INFO(set("info"), Type.NONE),
VERBOSE(set("verbose"), Type.NONE),
IMPORT(set("import"), Type.NONE),
SYNC(l("sync"), Type.NONE),
INFO(l("info"), Type.NONE),
VERBOSE(l("verbose"), Type.NONE),
IMPORT(l("import"), Type.NONE),
CREATE_GROUP(set("creategroup"), Type.NONE),
DELETE_GROUP(set("deletegroup"), Type.NONE),
LIST_GROUPS(set("listgroups"), Type.NONE),
CREATE_GROUP(l("creategroup"), Type.NONE),
DELETE_GROUP(l("deletegroup"), Type.NONE),
LIST_GROUPS(l("listgroups"), Type.NONE),
CREATE_TRACK(set("createtrack"), Type.NONE),
DELETE_TRACK(set("deletetrack"), Type.NONE),
LIST_TRACKS(set("listtracks"), Type.NONE),
CREATE_TRACK(l("createtrack"), Type.NONE),
DELETE_TRACK(l("deletetrack"), Type.NONE),
LIST_TRACKS(l("listtracks"), Type.NONE),
USER_INFO(set("info"), Type.USER),
USER_PERM_INFO(set("permission.info", "listnodes"), Type.USER),
USER_PERM_SET(set("permission.set", "setpermission"), Type.USER),
USER_PERM_UNSET(set("permission.unset", "unsetpermission"), Type.USER),
USER_PERM_SETTEMP(set("permission.settemp", "settemppermission"), Type.USER),
USER_PERM_UNSETTEMP(set("permission.unsettemp", "unsettemppermission"), Type.USER),
USER_PERM_CHECK(set("permission.check", "haspermission"), Type.USER),
USER_PERM_CHECK_INHERITS(set("permission.checkinherits", "inheritspermission"), Type.USER),
USER_PARENT_INFO(set("parent.info", "listgroups"), Type.USER),
USER_PARENT_SET(set("parent.set"), Type.USER),
USER_PARENT_ADD(set("parent.add", "addgroup"), Type.USER),
USER_PARENT_REMOVE(set("parent.remove", "removegroup"), Type.USER),
USER_PARENT_ADDTEMP(set("parent.addtemp", "addtempgroup"), Type.USER),
USER_PARENT_REMOVETEMP(set("parent.removetemp", "removetempgroup"), Type.USER),
USER_META_INFO(set("meta.info", "chatmeta"), Type.USER),
USER_META_SET(set("meta.set", "setmeta"), Type.USER),
USER_META_UNSET(set("meta.unset", "unsetmeta"), Type.USER),
USER_META_SETTEMP(set("meta.settemp", "settempmeta"), Type.USER),
USER_META_UNSETTEMP(set("meta.unsettemp", "unsettempmeta"), Type.USER),
USER_META_ADDPREFIX(set("meta.addprefix", "addprefix"), Type.USER),
USER_META_ADDSUFFIX(set("meta.addsuffix", "addsuffix"), Type.USER),
USER_META_REMOVEPREFIX(set("meta.removeprefix", "removeprefix"), Type.USER),
USER_META_REMOVESUFFIX(set("meta.removesuffix", "removesuffix"), Type.USER),
USER_META_ADDTEMP_PREFIX(set("meta.addtempprefix", "addtempprefix"), Type.USER),
USER_META_ADDTEMP_SUFFIX(set("meta.addtempsuffix", "addtempsuffix"), Type.USER),
USER_META_REMOVETEMP_PREFIX(set("meta.removetempprefix", "removetempprefix"), Type.USER),
USER_META_REMOVETEMP_SUFFIX(set("meta.removetempsuffix", "removetempsuffix"), Type.USER),
USER_META_CLEAR(set("meta.clear", "clearmeta"), Type.USER),
USER_GETUUID(set("getuuid"), Type.USER),
USER_SWITCHPRIMARYGROUP(set("switchprimarygroup", "setprimarygroup"), Type.USER),
USER_SHOWTRACKS(set("showtracks"), Type.USER),
USER_PROMOTE(set("promote"), Type.USER),
USER_DEMOTE(set("demote"), Type.USER),
USER_BULKCHANGE(set("bulkchange"), Type.USER),
USER_CLEAR(set("clear"), Type.USER),
USER_INFO(l("info"), Type.USER),
USER_PERM_INFO(l("permission.info", "listnodes"), Type.USER),
USER_PERM_SET(l("permission.set", "setpermission"), Type.USER),
USER_PERM_UNSET(l("permission.unset", "unsetpermission"), Type.USER),
USER_PERM_SETTEMP(l("permission.settemp", "settemppermission"), Type.USER),
USER_PERM_UNSETTEMP(l("permission.unsettemp", "unsettemppermission"), Type.USER),
USER_PERM_CHECK(l("permission.check", "haspermission"), Type.USER),
USER_PERM_CHECK_INHERITS(l("permission.checkinherits", "inheritspermission"), Type.USER),
USER_PARENT_INFO(l("parent.info", "listgroups"), Type.USER),
USER_PARENT_SET(l("parent.set"), Type.USER),
USER_PARENT_ADD(l("parent.add", "addgroup"), Type.USER),
USER_PARENT_REMOVE(l("parent.remove", "removegroup"), Type.USER),
USER_PARENT_ADDTEMP(l("parent.addtemp", "addtempgroup"), Type.USER),
USER_PARENT_REMOVETEMP(l("parent.removetemp", "removetempgroup"), Type.USER),
USER_META_INFO(l("meta.info", "chatmeta"), Type.USER),
USER_META_SET(l("meta.set", "setmeta"), Type.USER),
USER_META_UNSET(l("meta.unset", "unsetmeta"), Type.USER),
USER_META_SETTEMP(l("meta.settemp", "settempmeta"), Type.USER),
USER_META_UNSETTEMP(l("meta.unsettemp", "unsettempmeta"), Type.USER),
USER_META_ADDPREFIX(l("meta.addprefix", "addprefix"), Type.USER),
USER_META_ADDSUFFIX(l("meta.addsuffix", "addsuffix"), Type.USER),
USER_META_REMOVEPREFIX(l("meta.removeprefix", "removeprefix"), Type.USER),
USER_META_REMOVESUFFIX(l("meta.removesuffix", "removesuffix"), Type.USER),
USER_META_ADDTEMP_PREFIX(l("meta.addtempprefix", "addtempprefix"), Type.USER),
USER_META_ADDTEMP_SUFFIX(l("meta.addtempsuffix", "addtempsuffix"), Type.USER),
USER_META_REMOVETEMP_PREFIX(l("meta.removetempprefix", "removetempprefix"), Type.USER),
USER_META_REMOVETEMP_SUFFIX(l("meta.removetempsuffix", "removetempsuffix"), Type.USER),
USER_META_CLEAR(l("meta.clear", "clearmeta"), Type.USER),
USER_GETUUID(l("getuuid"), Type.USER),
USER_SWITCHPRIMARYGROUP(l("switchprimarygroup", "setprimarygroup"), Type.USER),
USER_SHOWTRACKS(l("showtracks"), Type.USER),
USER_PROMOTE(l("promote"), Type.USER),
USER_DEMOTE(l("demote"), Type.USER),
USER_BULKCHANGE(l("bulkchange"), Type.USER),
USER_CLEAR(l("clear"), Type.USER),
GROUP_INFO(set("info"), Type.GROUP),
GROUP_PERM_INFO(set("permission.info", "listnodes"), Type.GROUP),
GROUP_PERM_SET(set("permission.set", "setpermission"), Type.GROUP),
GROUP_PERM_UNSET(set("permission.unset", "unsetpermission"), Type.GROUP),
GROUP_PERM_SETTEMP(set("permission.settemp", "settemppermission"), Type.GROUP),
GROUP_PERM_UNSETTEMP(set("permission.unsettemp", "unsettemppermission"), Type.GROUP),
GROUP_PERM_CHECK(set("permission.check", "haspermission"), Type.GROUP),
GROUP_PERM_CHECK_INHERITS(set("permission.checkinherits", "inheritspermission"), Type.GROUP),
GROUP_PARENT_INFO(set("parent.info", "listparents"), Type.GROUP),
GROUP_PARENT_SET(set("parent.set"), Type.GROUP),
GROUP_PARENT_ADD(set("parent.add", "setinherit"), Type.GROUP),
GROUP_PARENT_REMOVE(set("parent.remove", "unsetinherit"), Type.GROUP),
GROUP_PARENT_ADDTEMP(set("parent.addtemp", "settempinherit"), Type.GROUP),
GROUP_PARENT_REMOVETEMP(set("parent.removetemp", "unsettempinherit"), Type.GROUP),
GROUP_META_INFO(set("meta.info", "chatmeta"), Type.GROUP),
GROUP_META_SET(set("meta.set", "setmeta"), Type.GROUP),
GROUP_META_UNSET(set("meta.unset", "unsetmeta"), Type.GROUP),
GROUP_META_SETTEMP(set("meta.settemp", "settempmeta"), Type.GROUP),
GROUP_META_UNSETTEMP(set("meta.unsettemp", "unsettempmeta"), Type.GROUP),
GROUP_META_ADDPREFIX(set("meta.addprefix", "addprefix"), Type.GROUP),
GROUP_META_ADDSUFFIX(set("meta.addsuffix", "addsuffix"), Type.GROUP),
GROUP_META_REMOVEPREFIX(set("meta.removeprefix", "removeprefix"), Type.GROUP),
GROUP_META_REMOVESUFFIX(set("meta.removesuffix", "removesuffix"), Type.GROUP),
GROUP_META_ADDTEMP_PREFIX(set("meta.addtempprefix", "addtempprefix"), Type.GROUP),
GROUP_META_ADDTEMP_SUFFIX(set("meta.addtempsuffix", "addtempsuffix"), Type.GROUP),
GROUP_META_REMOVETEMP_PREFIX(set("meta.removetempprefix", "removetempprefix"), Type.GROUP),
GROUP_META_REMOVETEMP_SUFFIX(set("meta.removetempsuffix", "removetempsuffix"), Type.GROUP),
GROUP_META_CLEAR(set("meta.clear", "clearmeta"), Type.GROUP),
GROUP_SHOWTRACKS(set("showtracks"), Type.GROUP),
GROUP_BULKCHANGE(set("bulkchange"), Type.GROUP),
GROUP_CLEAR(set("clear"), Type.GROUP),
GROUP_RENAME(set("rename"), Type.GROUP),
GROUP_CLONE(set("clone"), Type.GROUP),
GROUP_INFO(l("info"), Type.GROUP),
GROUP_PERM_INFO(l("permission.info", "listnodes"), Type.GROUP),
GROUP_PERM_SET(l("permission.set", "setpermission"), Type.GROUP),
GROUP_PERM_UNSET(l("permission.unset", "unsetpermission"), Type.GROUP),
GROUP_PERM_SETTEMP(l("permission.settemp", "settemppermission"), Type.GROUP),
GROUP_PERM_UNSETTEMP(l("permission.unsettemp", "unsettemppermission"), Type.GROUP),
GROUP_PERM_CHECK(l("permission.check", "haspermission"), Type.GROUP),
GROUP_PERM_CHECK_INHERITS(l("permission.checkinherits", "inheritspermission"), Type.GROUP),
GROUP_PARENT_INFO(l("parent.info", "listparents"), Type.GROUP),
GROUP_PARENT_SET(l("parent.set"), Type.GROUP),
GROUP_PARENT_ADD(l("parent.add", "setinherit"), Type.GROUP),
GROUP_PARENT_REMOVE(l("parent.remove", "unsetinherit"), Type.GROUP),
GROUP_PARENT_ADDTEMP(l("parent.addtemp", "settempinherit"), Type.GROUP),
GROUP_PARENT_REMOVETEMP(l("parent.removetemp", "unsettempinherit"), Type.GROUP),
GROUP_META_INFO(l("meta.info", "chatmeta"), Type.GROUP),
GROUP_META_SET(l("meta.set", "setmeta"), Type.GROUP),
GROUP_META_UNSET(l("meta.unset", "unsetmeta"), Type.GROUP),
GROUP_META_SETTEMP(l("meta.settemp", "settempmeta"), Type.GROUP),
GROUP_META_UNSETTEMP(l("meta.unsettemp", "unsettempmeta"), Type.GROUP),
GROUP_META_ADDPREFIX(l("meta.addprefix", "addprefix"), Type.GROUP),
GROUP_META_ADDSUFFIX(l("meta.addsuffix", "addsuffix"), Type.GROUP),
GROUP_META_REMOVEPREFIX(l("meta.removeprefix", "removeprefix"), Type.GROUP),
GROUP_META_REMOVESUFFIX(l("meta.removesuffix", "removesuffix"), Type.GROUP),
GROUP_META_ADDTEMP_PREFIX(l("meta.addtempprefix", "addtempprefix"), Type.GROUP),
GROUP_META_ADDTEMP_SUFFIX(l("meta.addtempsuffix", "addtempsuffix"), Type.GROUP),
GROUP_META_REMOVETEMP_PREFIX(l("meta.removetempprefix", "removetempprefix"), Type.GROUP),
GROUP_META_REMOVETEMP_SUFFIX(l("meta.removetempsuffix", "removetempsuffix"), Type.GROUP),
GROUP_META_CLEAR(l("meta.clear", "clearmeta"), Type.GROUP),
GROUP_SHOWTRACKS(l("showtracks"), Type.GROUP),
GROUP_BULKCHANGE(l("bulkchange"), Type.GROUP),
GROUP_CLEAR(l("clear"), Type.GROUP),
GROUP_RENAME(l("rename"), Type.GROUP),
GROUP_CLONE(l("clone"), Type.GROUP),
TRACK_INFO(set("info"), Type.TRACK),
TRACK_APPEND(set("append"), Type.TRACK),
TRACK_INSERT(set("insert"), Type.TRACK),
TRACK_REMOVE(set("remove"), Type.TRACK),
TRACK_CLEAR(set("clear"), Type.TRACK),
TRACK_RENAME(set("rename"), Type.TRACK),
TRACK_CLONE(set("clone"), Type.TRACK),
TRACK_INFO(l("info"), Type.TRACK),
TRACK_APPEND(l("append"), Type.TRACK),
TRACK_INSERT(l("insert"), Type.TRACK),
TRACK_REMOVE(l("remove"), Type.TRACK),
TRACK_CLEAR(l("clear"), Type.TRACK),
TRACK_RENAME(l("rename"), Type.TRACK),
TRACK_CLONE(l("clone"), Type.TRACK),
LOG_RECENT(set("recent"), Type.LOG),
LOG_USER_HISTORY(set("userhistory"), Type.LOG),
LOG_GROUP_HISTORY(set("grouphistory"), Type.LOG),
LOG_TRACK_HISTORY(set("trackhistory"), Type.LOG),
LOG_SEARCH(set("search"), Type.LOG),
LOG_NOTIFY(set("notify"), Type.LOG),
LOG_EXPORT(set("export"), Type.LOG),
LOG_RECENT(l("recent"), Type.LOG),
LOG_USER_HISTORY(l("userhistory"), Type.LOG),
LOG_GROUP_HISTORY(l("grouphistory"), Type.LOG),
LOG_TRACK_HISTORY(l("trackhistory"), Type.LOG),
LOG_SEARCH(l("search"), Type.LOG),
LOG_NOTIFY(l("notify"), Type.LOG),
LOG_EXPORT(l("export"), Type.LOG),
SPONGE_PERMISSION_INFO(set("permission.info"), Type.SPONGE),
SPONGE_PERMISSION_SET(set("permission.set"), Type.SPONGE),
SPONGE_PERMISSION_CLEAR(set("permission.clear"), Type.SPONGE),
SPONGE_PARENT_INFO(set("parent.info"), Type.SPONGE),
SPONGE_PARENT_ADD(set("parent.add"), Type.SPONGE),
SPONGE_PARENT_REMOVE(set("parent.remove"), Type.SPONGE),
SPONGE_PARENT_CLEAR(set("parent.clear"), Type.SPONGE),
SPONGE_OPTION_INFO(set("option.info"), Type.SPONGE),
SPONGE_OPTION_SET(set("option.set"), Type.SPONGE),
SPONGE_OPTION_UNSET(set("option.unset"), Type.SPONGE),
SPONGE_OPTION_CLEAR(set("option.clear"), Type.SPONGE),
SPONGE_PERMISSION_INFO(l("permission.info"), Type.SPONGE),
SPONGE_PERMISSION_SET(l("permission.set"), Type.SPONGE),
SPONGE_PERMISSION_CLEAR(l("permission.clear"), Type.SPONGE),
SPONGE_PARENT_INFO(l("parent.info"), Type.SPONGE),
SPONGE_PARENT_ADD(l("parent.add"), Type.SPONGE),
SPONGE_PARENT_REMOVE(l("parent.remove"), Type.SPONGE),
SPONGE_PARENT_CLEAR(l("parent.clear"), Type.SPONGE),
SPONGE_OPTION_INFO(l("option.info"), Type.SPONGE),
SPONGE_OPTION_SET(l("option.set"), Type.SPONGE),
SPONGE_OPTION_UNSET(l("option.unset"), Type.SPONGE),
SPONGE_OPTION_CLEAR(l("option.clear"), Type.SPONGE),
MIGRATION(set("migration"), Type.NONE);
MIGRATION(l("migration"), Type.NONE);
private static final String IDENTIFIER = "luckperms.";
private static Set<String> set(String... args) {
return Sets.newHashSet(args);
private static List<String> l(String... args) {
return Arrays.asList(args);
}
private Set<String> nodes;
private List<String> nodes;
private Type type;
Permission(Set<String> tags, Type type) {
Permission(List<String> tags, Type type) {
this.type = type;
if (type == Type.NONE) {
this.nodes = tags.stream().map(t -> IDENTIFIER + t).collect(ImmutableCollectors.toImmutableSet());
this.nodes = tags.stream().map(t -> IDENTIFIER + t).collect(ImmutableCollectors.toImmutableList());
} else {
this.nodes = tags.stream().map(t -> IDENTIFIER + type.getTag() + "." + t).collect(ImmutableCollectors.toImmutableSet());
this.nodes = tags.stream().map(t -> IDENTIFIER + type.getTag() + "." + t).collect(ImmutableCollectors.toImmutableList());
}
}
public String getExample() {
return nodes.get(0);
}
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(this);
}