Sponge: Implement support for editing more than just users/groups with commands

This commit is contained in:
Luck
2016-11-14 18:45:48 +00:00
Unverified
parent 18a3dfd604
commit 9c8097ecb9
18 changed files with 1203 additions and 25 deletions
@@ -27,6 +27,7 @@ import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.PlatformType;
import me.lucko.luckperms.common.api.ApiProvider;
import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.commands.BaseCommand;
import me.lucko.luckperms.common.commands.ConsecutiveExecutor;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.config.LPConfiguration;
@@ -44,6 +45,7 @@ import me.lucko.luckperms.common.utils.DebugHandler;
import me.lucko.luckperms.common.utils.LocaleManager;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -247,6 +249,10 @@ public interface LuckPermsPlugin {
*/
Set<Contexts> getPreProcessContexts(boolean op);
default List<BaseCommand> getExtraCommands() {
return Collections.emptyList();
}
/**
* Gets a set of players ignoring logging output
* @return a {@link Set} of {@link UUID}s
@@ -23,7 +23,6 @@
package me.lucko.luckperms.common.commands;
import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor;
import lombok.Getter;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.group.CreateGroup;
@@ -51,34 +50,41 @@ import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@AllArgsConstructor
public class CommandManager {
@Getter
private final LuckPermsPlugin plugin;
@Getter
private final List<BaseCommand> mainCommands = ImmutableList.<BaseCommand>builder()
.add(new UserMainCommand())
.add(new GroupMainCommand())
.add(new TrackMainCommand())
.add(new LogMainCommand())
.add(new SyncCommand())
.add(new NetworkSyncCommand())
.add(new InfoCommand())
.add(new DebugCommand())
.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())
.build();
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 DebugCommand())
.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
@@ -24,6 +24,8 @@ package me.lucko.luckperms.common.commands.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.utils.ArgumentChecker;
import me.lucko.luckperms.common.utils.DateUtil;
@@ -112,6 +114,33 @@ public class ArgumentUtils {
}
}
public static ContextSet handleContexts(int fromIndex, List<String> args) {
if (args.size() <= fromIndex) {
return ContextSet.empty();
}
MutableContextSet contextSet = new MutableContextSet();
List<String> toQuery = args.subList(fromIndex, args.size());
for (String s : toQuery) {
int index = s.indexOf('=');
if (index != -1) {
String key = s.substring(0, index);
if (key.equals("")) {
continue;
}
String value = s.substring(index + 1);
if (value.equals("")) {
continue;
}
contextSet.add(key, value);
}
}
return contextSet.makeImmutable();
}
public static abstract class ArgumentException extends CommandException {}
public static class DetailedUsageException extends ArgumentException {}
public static class UseInheritException extends ArgumentException {}
@@ -134,6 +134,18 @@ public enum Permission {
LOG_NOTIFY(set("notify"), Type.LOG),
LOG_EXPORT(set("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),
MIGRATION(set("migration"), Type.NONE);
private static final String IDENTIFIER = "luckperms.";
@@ -167,7 +179,8 @@ public enum Permission {
USER("user"),
GROUP("group"),
TRACK("track"),
LOG("log");
LOG("log"),
SPONGE("sponge");
private final String tag;