mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 13:15:44 +01:00
Cleanup command abstraction classes
This commit is contained in:
parent
4c83d439af
commit
2ccb475aa0
@ -25,10 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandManager;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentTokenizer;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
@ -40,10 +38,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitCommandExecutor extends CommandManager implements CommandExecutor, TabExecutor {
|
||||
private static final Splitter TAB_COMPLETE_ARGUMENT_SPLITTER = Splitter.on(COMMAND_SEPARATOR_PATTERN);
|
||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||
private static final Joiner ARGUMENT_JOINER = Joiner.on(' ');
|
||||
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public BukkitCommandExecutor(LPBukkitPlugin plugin) {
|
||||
@ -53,18 +47,16 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, @NonNull String[] args) {
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
onCommand(lpSender, label, arguments);
|
||||
Sender wrapped = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = ArgumentTokenizer.EXECUTE.tokenizeInput(args);
|
||||
executeCommand(wrapped, label, arguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, @NonNull String[] args) {
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
return onTabComplete(lpSender, arguments);
|
||||
Sender wrapped = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args);
|
||||
return tabCompleteCommand(wrapped, arguments);
|
||||
}
|
||||
}
|
||||
|
@ -113,12 +113,9 @@ public final class LuckPermsDefaultsMap implements Map<Boolean, Set<Permission>>
|
||||
}
|
||||
|
||||
// return wrappers around this map impl
|
||||
@Override
|
||||
public @NonNull Collection<Set<Permission>> values() { return this.values; }
|
||||
@Override
|
||||
public @NonNull Set<Entry<Boolean, Set<Permission>>> entrySet() { return this.entrySet; }
|
||||
@Override
|
||||
public @NonNull Set<Boolean> keySet() { return KEY_SET; }
|
||||
@Override public @NonNull Collection<Set<Permission>> values() { return this.values; }
|
||||
@Override public @NonNull Set<Entry<Boolean, Set<Permission>>> entrySet() { return this.entrySet; }
|
||||
@Override public @NonNull Set<Boolean> keySet() { return KEY_SET; }
|
||||
|
||||
// return accurate results for the Map spec
|
||||
@Override public int size() { return 2; }
|
||||
|
@ -32,7 +32,7 @@ import de.bananaco.bpermissions.api.World;
|
||||
import de.bananaco.bpermissions.api.WorldManager;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -67,7 +67,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class MigrationBPermissions extends SubCommand<Object> {
|
||||
public class MigrationBPermissions extends ChildCommand<Object> {
|
||||
private static final Field UCONFIG_FIELD;
|
||||
static {
|
||||
try {
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.bukkit.migration;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -68,7 +68,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MigrationGroupManager extends SubCommand<Object> {
|
||||
public class MigrationGroupManager extends ChildCommand<Object> {
|
||||
public MigrationGroupManager(LocaleManager locale) {
|
||||
super(CommandSpec.MIGRATION_GROUPMANAGER.localize(locale), "groupmanager", CommandPermission.MIGRATION, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.bukkit.migration;
|
||||
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -56,7 +56,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class MigrationPermissionsBukkit extends SubCommand<Object> {
|
||||
public class MigrationPermissionsBukkit extends ChildCommand<Object> {
|
||||
public MigrationPermissionsBukkit(LocaleManager locale) {
|
||||
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "permissionsbukkit", CommandPermission.MIGRATION, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.bukkit.migration;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -74,7 +74,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
public class MigrationPermissionsEx extends ChildCommand<Object> {
|
||||
private static final Method GET_DATA_METHOD;
|
||||
private static final Field TIMED_PERMISSIONS_FIELD;
|
||||
private static final Field TIMED_PERMISSIONS_TIME_FIELD;
|
||||
|
@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -78,7 +78,7 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
// Only supports the latest versions of the PP API. (it seems to change randomly almost every release)
|
||||
public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
public class MigrationPowerfulPerms extends ChildCommand<Object> {
|
||||
public MigrationPowerfulPerms(LocaleManager locale) {
|
||||
super(CommandSpec.MIGRATION_POWERFULPERMS.localize(locale), "powerfulperms", CommandPermission.MIGRATION, Predicates.not(5));
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.bukkit.migration;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -69,7 +69,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class MigrationZPermissions extends SubCommand<Object> {
|
||||
public class MigrationZPermissions extends ChildCommand<Object> {
|
||||
public MigrationZPermissions(LocaleManager locale) {
|
||||
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "zpermissions", CommandPermission.MIGRATION, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -25,10 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.bungee;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandManager;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentTokenizer;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@ -38,10 +36,6 @@ import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeCommandExecutor extends Command implements TabExecutor {
|
||||
private static final Splitter TAB_COMPLETE_ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN);
|
||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||
private static final Joiner ARGUMENT_JOINER = Joiner.on(' ');
|
||||
|
||||
private final LPBungeePlugin plugin;
|
||||
private final CommandManager manager;
|
||||
|
||||
@ -53,17 +47,15 @@ public class BungeeCommandExecutor extends Command implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
this.manager.onCommand(lpSender, "lpb", arguments);
|
||||
Sender wrapped = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = ArgumentTokenizer.EXECUTE.tokenizeInput(args);
|
||||
this.manager.executeCommand(wrapped, "lpb", arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
|
||||
|
||||
return this.manager.onTabComplete(lpSender, arguments);
|
||||
Sender wrapped = this.plugin.getSenderFactory().wrap(sender);
|
||||
List<String> arguments = ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args);
|
||||
return this.manager.tabCompleteCommand(wrapped, arguments);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.bungee.migration;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -55,7 +55,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
public class MigrationBungeePerms extends ChildCommand<Object> {
|
||||
public MigrationBungeePerms(LocaleManager locale) {
|
||||
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "bungeeperms", CommandPermission.MIGRATION, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import java.util.Objects;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class ApiActionLog implements ActionLog {
|
||||
private final Log handle;
|
||||
|
||||
|
@ -41,12 +41,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class ApiContextManager implements net.luckperms.api.context.ContextManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final ContextManager handle;
|
||||
|
||||
public ApiContextManager(LuckPermsPlugin plugin, ContextManager handle) {
|
||||
public ApiContextManager(LuckPermsPlugin plugin, ContextManager<?> handle) {
|
||||
this.plugin = plugin;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandManager;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentTokenizer;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.sender.DummySender;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
@ -207,7 +208,6 @@ public class LegacyImporter implements Runnable {
|
||||
}
|
||||
|
||||
private static class ImportCommand extends DummySender {
|
||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||
private static final Splitter SPACE_SPLITTER = Splitter.on(" ");
|
||||
|
||||
private final CommandManager commandManager;
|
||||
@ -241,7 +241,7 @@ public class LegacyImporter implements Runnable {
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> args = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(getCommand()));
|
||||
List<String> args = ArgumentTokenizer.EXECUTE.tokenizeInput(getCommand());
|
||||
|
||||
// rewrite rule for switchprimarygroup command
|
||||
if (args.size() >= 3 && args.get(0).equals("user") && args.get(2).equals("switchprimarygroup")) {
|
||||
@ -250,7 +250,7 @@ public class LegacyImporter implements Runnable {
|
||||
args.add(3, "switchprimarygroup");
|
||||
}
|
||||
|
||||
CommandResult result = this.commandManager.onCommand(this, "lp", args, Runnable::run).get();
|
||||
CommandResult result = this.commandManager.executeCommand(this, "lp", args, Runnable::run).get();
|
||||
setResult(result);
|
||||
} catch (Exception e) {
|
||||
setResult(CommandResult.FAILURE);
|
||||
|
@ -30,14 +30,15 @@ import com.google.common.collect.ImmutableList;
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.commands.group.CreateGroup;
|
||||
import me.lucko.luckperms.common.commands.group.DeleteGroup;
|
||||
import me.lucko.luckperms.common.commands.group.GroupMainCommand;
|
||||
import me.lucko.luckperms.common.commands.group.GroupParentCommand;
|
||||
import me.lucko.luckperms.common.commands.group.ListGroups;
|
||||
import me.lucko.luckperms.common.commands.log.LogMainCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationMainCommand;
|
||||
import me.lucko.luckperms.common.commands.log.LogParentCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationParentCommand;
|
||||
import me.lucko.luckperms.common.commands.misc.ApplyEditsCommand;
|
||||
import me.lucko.luckperms.common.commands.misc.BulkUpdateCommand;
|
||||
import me.lucko.luckperms.common.commands.misc.CheckCommand;
|
||||
@ -54,35 +55,35 @@ import me.lucko.luckperms.common.commands.misc.VerboseCommand;
|
||||
import me.lucko.luckperms.common.commands.track.CreateTrack;
|
||||
import me.lucko.luckperms.common.commands.track.DeleteTrack;
|
||||
import me.lucko.luckperms.common.commands.track.ListTracks;
|
||||
import me.lucko.luckperms.common.commands.track.TrackMainCommand;
|
||||
import me.lucko.luckperms.common.commands.user.UserMainCommand;
|
||||
import me.lucko.luckperms.common.commands.track.TrackParentCommand;
|
||||
import me.lucko.luckperms.common.commands.user.UserParentCommand;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||
import me.lucko.luckperms.common.util.TextUtils;
|
||||
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.event.ClickEvent;
|
||||
import net.kyori.text.event.HoverEvent;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Optional;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Root command manager for the '/luckperms' command.
|
||||
*/
|
||||
public class CommandManager {
|
||||
public static final Pattern COMMAND_SEPARATOR_PATTERN = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
@ -91,19 +92,19 @@ public class CommandManager {
|
||||
|
||||
private final TabCompletions tabCompletions;
|
||||
|
||||
private final List<Command<?, ?>> mainCommands;
|
||||
private final Map<String, Command<?>> mainCommands;
|
||||
|
||||
public CommandManager(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
LocaleManager locale = plugin.getLocaleManager();
|
||||
|
||||
this.tabCompletions = new TabCompletions(plugin);
|
||||
this.mainCommands = ImmutableList.<Command<?, ?>>builder()
|
||||
.add(new UserMainCommand(locale))
|
||||
.add(new GroupMainCommand(locale))
|
||||
.add(new TrackMainCommand(locale))
|
||||
this.mainCommands = ImmutableList.<Command<?>>builder()
|
||||
.add(new UserParentCommand(locale))
|
||||
.add(new GroupParentCommand(locale))
|
||||
.add(new TrackParentCommand(locale))
|
||||
.addAll(plugin.getExtraCommands())
|
||||
.add(new LogMainCommand(locale))
|
||||
.add(new LogParentCommand(locale))
|
||||
.add(new SyncCommand(locale))
|
||||
.add(new InfoCommand(locale))
|
||||
.add(new EditorCommand(locale))
|
||||
@ -116,7 +117,7 @@ public class CommandManager {
|
||||
.add(new ExportCommand(locale))
|
||||
.add(new ReloadConfigCommand(locale))
|
||||
.add(new BulkUpdateCommand(locale))
|
||||
.add(new MigrationMainCommand(locale))
|
||||
.add(new MigrationParentCommand(locale))
|
||||
.add(new ApplyEditsCommand(locale))
|
||||
.add(new CreateGroup(locale))
|
||||
.add(new DeleteGroup(locale))
|
||||
@ -124,7 +125,9 @@ public class CommandManager {
|
||||
.add(new CreateTrack(locale))
|
||||
.add(new DeleteTrack(locale))
|
||||
.add(new ListTracks(locale))
|
||||
.build();
|
||||
.build()
|
||||
.stream()
|
||||
.collect(ImmutableCollectors.toMap(c -> c.getName().toLowerCase(), Function.identity()));
|
||||
}
|
||||
|
||||
public LuckPermsPlugin getPlugin() {
|
||||
@ -135,11 +138,11 @@ public class CommandManager {
|
||||
return this.tabCompletions;
|
||||
}
|
||||
|
||||
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args) {
|
||||
return onCommand(sender, label, args, this.executor);
|
||||
public CompletableFuture<CommandResult> executeCommand(Sender sender, String label, List<String> args) {
|
||||
return executeCommand(sender, label, args, this.executor);
|
||||
}
|
||||
|
||||
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args, Executor executor) {
|
||||
public CompletableFuture<CommandResult> executeCommand(Sender sender, String label, List<String> args, Executor executor) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return execute(sender, label, args);
|
||||
@ -152,12 +155,10 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
public boolean hasPermissionForAny(Sender sender) {
|
||||
return this.mainCommands.stream().anyMatch(c -> c.shouldDisplay() && c.isAuthorized(sender));
|
||||
return this.mainCommands.values().stream().anyMatch(c -> c.shouldDisplay() && c.isAuthorized(sender));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private CommandResult execute(Sender sender, String label, List<String> args) {
|
||||
List<String> arguments = new ArrayList<>(args);
|
||||
private CommandResult execute(Sender sender, String label, List<String> arguments) {
|
||||
handleRewrites(arguments, true);
|
||||
|
||||
// Handle no arguments
|
||||
@ -166,31 +167,27 @@ public class CommandManager {
|
||||
if (hasPermissionForAny(sender)) {
|
||||
Message.VIEW_AVAILABLE_COMMANDS_PROMPT.send(sender, label);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
}
|
||||
|
||||
Collection<? extends Group> groups = this.plugin.getGroupManager().getAll().values();
|
||||
if (groups.size() <= 1 && groups.stream().allMatch(g -> g.getOwnNodes(QueryOptions.nonContextual()).isEmpty())) {
|
||||
if (groups.size() <= 1 && groups.stream().allMatch(g -> g.normalData().immutable().isEmpty())) {
|
||||
Message.FIRST_TIME_SETUP.send(sender, label, sender.getName());
|
||||
} else {
|
||||
Message.NO_PERMISSION_FOR_SUBCOMMANDS.send(sender);
|
||||
}
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for the main command.
|
||||
Optional<Command<?, ?>> o = this.mainCommands.stream()
|
||||
.filter(m -> m.getName().equalsIgnoreCase(arguments.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
Command<?> main = this.mainCommands.get(arguments.get(0).toLowerCase());
|
||||
|
||||
// Main command not found
|
||||
if (!o.isPresent()) {
|
||||
if (main == null) {
|
||||
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;
|
||||
@ -209,7 +206,7 @@ public class CommandManager {
|
||||
try {
|
||||
result = main.execute(this.plugin, sender, null, arguments, label);
|
||||
} catch (CommandException e) {
|
||||
result = handleException(e, sender, label, main);
|
||||
result = e.handle(sender, label, main);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
result = CommandResult.FAILURE;
|
||||
@ -218,56 +215,29 @@ public class CommandManager {
|
||||
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) {
|
||||
List<String> arguments = new ArrayList<>(args);
|
||||
|
||||
public List<String> tabCompleteCommand(Sender sender, List<String> arguments) {
|
||||
// we rewrite tab completions too!
|
||||
handleRewrites(arguments, false);
|
||||
|
||||
final List<Command> mains = this.mainCommands.stream()
|
||||
final List<Command<?>> mains = this.mainCommands.values().stream()
|
||||
.filter(Command::shouldDisplay)
|
||||
.filter(m -> m.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Not yet past the point of entering a main command
|
||||
if (arguments.size() <= 1) {
|
||||
|
||||
// Nothing yet entered
|
||||
if (arguments.isEmpty() || arguments.get(0).equals("")) {
|
||||
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(arguments.get(0).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// Find a main command matching the first arg
|
||||
Optional<Command> o = mains.stream()
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> mains.stream().map(c -> c.getName().toLowerCase())))
|
||||
.from(1, partial -> mains.stream()
|
||||
.filter(m -> m.getName().equalsIgnoreCase(arguments.get(0)))
|
||||
.findFirst();
|
||||
|
||||
arguments.remove(0); // remove the main command arg.
|
||||
|
||||
// Pass the processing onto the main command
|
||||
return o.map(cmd -> cmd.tabComplete(this.plugin, sender, arguments)).orElseGet(Collections::emptyList);
|
||||
.findFirst()
|
||||
.map(cmd -> cmd.tabComplete(this.plugin, sender, arguments.subList(1, arguments.size())))
|
||||
.orElse(Collections.emptyList())
|
||||
)
|
||||
.complete(arguments);
|
||||
}
|
||||
|
||||
private void sendCommandUsage(Sender sender, String label) {
|
||||
Message.BLANK.send(sender, "&2Running &bLuckPerms v" + this.plugin.getBootstrap().getVersion() + "&2.");
|
||||
this.mainCommands.stream()
|
||||
this.mainCommands.values().stream()
|
||||
.filter(Command::shouldDisplay)
|
||||
.filter(c -> c.isAuthorized(sender))
|
||||
.forEach(c -> {
|
||||
@ -289,39 +259,6 @@ public class CommandManager {
|
||||
});
|
||||
}
|
||||
|
||||
public static CommandResult handleException(CommandException e, Sender sender, String label, Command command) {
|
||||
if (e instanceof ArgumentParser.ArgumentException) {
|
||||
if (e instanceof ArgumentParser.DetailedUsageException) {
|
||||
command.sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.InvalidServerWorldException) {
|
||||
Message.SERVER_WORLD_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.PastDateException) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.InvalidDateException) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentParser.InvalidDateException) e).getInvalidDate());
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.InvalidPriorityException) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, ((ArgumentParser.InvalidPriorityException) e).getInvalidPriority());
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
// Not something we can catch.
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles aliases
|
||||
*
|
||||
@ -390,26 +327,4 @@ public class CommandManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips outer quote marks from a list of parsed arguments.
|
||||
*
|
||||
* @param input the list of arguments to strip quotes from
|
||||
* @return an ArrayList containing the contents of input without quotes
|
||||
*/
|
||||
public static List<String> stripQuotes(List<String> input) {
|
||||
input = new ArrayList<>(input);
|
||||
ListIterator<String> iterator = input.listIterator();
|
||||
while (iterator.hasNext()) {
|
||||
String value = iterator.next();
|
||||
if (value.length() < 3) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
|
||||
iterator.set(value.substring(1, value.length() - 1));
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ import java.util.function.Predicate;
|
||||
/**
|
||||
* Abstract SubCommand class
|
||||
*/
|
||||
public abstract class SubCommand<T> extends Command<T, Void> {
|
||||
public abstract class ChildCommand<T> extends Command<T> {
|
||||
|
||||
public SubCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
|
||||
public ChildCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
|
||||
super(spec, name, permission, argumentCheck);
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.command.Argument;
|
||||
@ -46,9 +44,8 @@ import java.util.function.Predicate;
|
||||
* An abstract command class
|
||||
*
|
||||
* @param <T> the argument type required by the command
|
||||
* @param <S> the type of any child commands
|
||||
*/
|
||||
public abstract class Command<T, S> {
|
||||
public abstract class Command<T> {
|
||||
|
||||
/**
|
||||
* The commands specification.
|
||||
@ -72,25 +69,11 @@ public abstract class Command<T, S> {
|
||||
*/
|
||||
private final @NonNull Predicate<Integer> argumentCheck;
|
||||
|
||||
/**
|
||||
* Child commands. Nullable.
|
||||
*/
|
||||
private final @Nullable List<Command<S, ?>> children;
|
||||
|
||||
public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @Nullable CommandPermission permission, @NonNull Predicate<Integer> argumentCheck, @Nullable List<Command<S, ?>> children) {
|
||||
public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @Nullable CommandPermission permission, @NonNull Predicate<Integer> argumentCheck) {
|
||||
this.spec = spec;
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
this.argumentCheck = argumentCheck;
|
||||
this.children = children == null ? null : ImmutableList.copyOf(children);
|
||||
}
|
||||
|
||||
public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @Nullable CommandPermission permission, @NonNull Predicate<Integer> argumentCheck) {
|
||||
this(spec, name, permission, argumentCheck, null);
|
||||
}
|
||||
|
||||
public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @NonNull Predicate<Integer> argumentCheck) {
|
||||
this(spec, name, null, argumentCheck, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,15 +115,6 @@ public abstract class Command<T, S> {
|
||||
return this.argumentCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the commands children
|
||||
*
|
||||
* @return any child commands
|
||||
*/
|
||||
public @NonNull Optional<List<Command<S, ?>>> getChildren() {
|
||||
return Optional.ofNullable(this.children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the commands description.
|
||||
*
|
||||
|
@ -25,9 +25,22 @@
|
||||
|
||||
package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
/**
|
||||
* Exception to be thrown if there is an error processing a command
|
||||
*/
|
||||
public class CommandException extends Exception {
|
||||
public abstract class CommandException extends Exception {
|
||||
|
||||
public abstract CommandResult handle(Sender sender);
|
||||
|
||||
public CommandResult handle(Sender sender, String label, Command<?> command) {
|
||||
return handle(sender);
|
||||
}
|
||||
|
||||
public CommandResult handle(Sender sender, GenericChildCommand command) {
|
||||
return handle(sender);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.command.Argument;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
@ -42,7 +43,7 @@ import java.util.function.Predicate;
|
||||
* A sub command which can be be applied to both groups and users.
|
||||
* This doesn't extend the other Command or SubCommand classes to avoid generics hell.
|
||||
*/
|
||||
public abstract class SharedSubCommand {
|
||||
public abstract class GenericChildCommand {
|
||||
|
||||
private final LocalizedCommandSpec spec;
|
||||
|
||||
@ -62,7 +63,7 @@ public abstract class SharedSubCommand {
|
||||
*/
|
||||
private final Predicate<? super Integer> argumentCheck;
|
||||
|
||||
public SharedSubCommand(LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission, Predicate<? super Integer> argumentCheck) {
|
||||
public GenericChildCommand(LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission, Predicate<? super Integer> argumentCheck) {
|
||||
this.spec = spec;
|
||||
this.name = name;
|
||||
this.userPermission = userPermission;
|
||||
@ -119,8 +120,15 @@ public abstract class SharedSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAuthorized(Sender sender, boolean user) {
|
||||
return user ? this.userPermission.isAuthorized(sender) : this.groupPermission.isAuthorized(sender);
|
||||
public boolean isAuthorized(Sender sender, HolderType type) {
|
||||
switch (type) {
|
||||
case USER:
|
||||
return this.userPermission.isAuthorized(sender);
|
||||
case GROUP:
|
||||
return this.groupPermission.isAuthorized(sender);
|
||||
default:
|
||||
throw new AssertionError(type);
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescription() {
|
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A shared main command. Shared meaning it can apply to both users and groups.
|
||||
* This extends sub command as they're actually sub commands of the main user/group commands.
|
||||
* @param <T>
|
||||
*/
|
||||
public class GenericParentCommand<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
|
||||
private final List<GenericChildCommand> children;
|
||||
|
||||
private final HolderType type;
|
||||
|
||||
public GenericParentCommand(LocalizedCommandSpec spec, String name, HolderType type, List<GenericChildCommand> children) {
|
||||
super(spec, name, null, Predicates.alwaysFalse());
|
||||
this.children = children;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsageDetailed(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
GenericChildCommand sub = this.children.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (sub == null) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!sub.isAuthorized(sender, this.type)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (sub.getArgumentCheck().test(args.size() - 1)) {
|
||||
sub.sendDetailedUsage(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
CommandResult result;
|
||||
try {
|
||||
result = sub.execute(plugin, sender, holder, args.subList(1, args.size()), label, this.type == HolderType.USER ? sub.getUserPermission() : sub.getGroupPermission());
|
||||
} catch (CommandException e) {
|
||||
result = e.handle(sender, sub);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> this.children.stream()
|
||||
.filter(s -> s.isAuthorized(sender, this.type))
|
||||
.map(s -> s.getName().toLowerCase())
|
||||
))
|
||||
.from(1, partial -> this.children.stream()
|
||||
.filter(s -> s.isAuthorized(sender, this.type))
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.findFirst()
|
||||
.map(cmd -> cmd.tabComplete(plugin, sender, args.subList(1, args.size())))
|
||||
.orElse(Collections.emptyList())
|
||||
)
|
||||
.complete(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return this.children.stream().anyMatch(sc -> sc.isAuthorized(sender, this.type));
|
||||
}
|
||||
|
||||
private void sendUsageDetailed(Sender sender, String label) {
|
||||
List<GenericChildCommand> subs = this.children.stream()
|
||||
.filter(s -> s.isAuthorized(sender, this.type))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!subs.isEmpty()) {
|
||||
switch (this.type) {
|
||||
case USER:
|
||||
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s user <user> " + getName().toLowerCase(), label));
|
||||
break;
|
||||
case GROUP:
|
||||
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s group <group> " + getName().toLowerCase(), label));
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError(this.type);
|
||||
}
|
||||
|
||||
for (GenericChildCommand s : subs) {
|
||||
s.sendUsage(sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandManager;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class MainCommand<T, I> extends Command<Void, T> {
|
||||
|
||||
// equals 1 if the command doesn't take a mid argument, e.g. /lp log sub-command....
|
||||
// equals 2 if the command does take a mid argument, e.g. /lp user <USER> sub-command....
|
||||
private final int minArgs;
|
||||
|
||||
public MainCommand(LocalizedCommandSpec spec, String name, int minArgs, List<Command<T, ?>> children) {
|
||||
super(spec, name, null, Predicates.alwaysFalse(), children);
|
||||
this.minArgs = minArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) {
|
||||
if (args.size() < this.minArgs) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<Command<T, ?>> o = getChildren().get().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(this.minArgs - 1)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final Command<T, ?> sub = o.get();
|
||||
if (!sub.isAuthorized(sender)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > this.minArgs) {
|
||||
strippedArgs.addAll(args.subList(this.minArgs, args.size()));
|
||||
}
|
||||
|
||||
if (sub.getArgumentCheck().test(strippedArgs.size())) {
|
||||
sub.sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String name = args.get(0);
|
||||
I targetId = parseTarget(name, plugin, sender);
|
||||
if (targetId == null) {
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
ReentrantLock lock = getLockForTarget(targetId);
|
||||
lock.lock();
|
||||
try {
|
||||
T target = getTarget(targetId, plugin, sender);
|
||||
if (target != null) {
|
||||
CommandResult result;
|
||||
try {
|
||||
result = sub.execute(plugin, sender, target, strippedArgs, label);
|
||||
} catch (CommandException e) {
|
||||
result = CommandManager.handleException(e, sender, label, sub);
|
||||
}
|
||||
|
||||
cleanup(target, plugin);
|
||||
return result;
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
final List<String> objects = getTargets(plugin);
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).trim().isEmpty()) {
|
||||
return objects;
|
||||
}
|
||||
|
||||
return objects.stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
final List<Command<T, ?>> subs = getChildren().get().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (args.size() == 2) {
|
||||
if (args.get(1).trim().isEmpty()) {
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<Command<T, ?>> o = subs.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(1)))
|
||||
.findFirst();
|
||||
|
||||
return o.map(cmd -> cmd.tabComplete(plugin, sender, args.subList(2, args.size()))).orElseGet(Collections::emptyList);
|
||||
|
||||
}
|
||||
|
||||
protected abstract List<String> getTargets(LuckPermsPlugin plugin);
|
||||
|
||||
protected abstract I parseTarget(String target, LuckPermsPlugin plugin, Sender sender);
|
||||
|
||||
protected abstract ReentrantLock getLockForTarget(I target);
|
||||
|
||||
protected abstract T getTarget(I target, LuckPermsPlugin plugin, Sender sender);
|
||||
|
||||
protected abstract void cleanup(T t, LuckPermsPlugin plugin);
|
||||
|
||||
@Override
|
||||
public void sendUsage(Sender sender, String label) {
|
||||
List<Command> subs = getChildren().get().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!subs.isEmpty()) {
|
||||
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format(getUsage(), label));
|
||||
for (Command s : subs) {
|
||||
s.sendUsage(sender, label);
|
||||
}
|
||||
} else {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendDetailedUsage(Sender sender, String label) {
|
||||
sendUsage(sender, label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return getChildren().get().stream().anyMatch(sc -> sc.isAuthorized(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Optional<List<Command<T, ?>>> getChildren() {
|
||||
return super.getChildren();
|
||||
}
|
||||
}
|
@ -0,0 +1,208 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class ParentCommand<T, I> extends Command<Void> {
|
||||
|
||||
/** Child sub commands */
|
||||
private final List<Command<T>> children;
|
||||
/** The type of parent command */
|
||||
private final Type type;
|
||||
|
||||
public ParentCommand(LocalizedCommandSpec spec, String name, Type type, List<Command<T>> children) {
|
||||
super(spec, name, null, Predicates.alwaysFalse());
|
||||
this.children = children;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public @NonNull List<Command<T>> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void ignored, List<String> args, String label) {
|
||||
// check if required argument and/or subcommand is missing
|
||||
if (args.size() < this.type.minArgs) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Command<T> sub = getChildren().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(this.type.cmdIndex)))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (sub == null) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!sub.isAuthorized(sender)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (sub.getArgumentCheck().test(args.size() - this.type.minArgs)) {
|
||||
sub.sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String targetArgument = args.get(0);
|
||||
I targetId = null;
|
||||
if (this.type == Type.TAKES_ARGUMENT_FOR_TARGET) {
|
||||
targetId = parseTarget(targetArgument, plugin, sender);
|
||||
if (targetId == null) {
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ReentrantLock lock = getLockForTarget(targetId);
|
||||
lock.lock();
|
||||
try {
|
||||
T target = getTarget(targetId, plugin, sender);
|
||||
if (target == null) {
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
CommandResult result;
|
||||
try {
|
||||
result = sub.execute(plugin, sender, target, args.subList(this.type.minArgs, args.size()), label);
|
||||
} catch (CommandException e) {
|
||||
result = e.handle(sender, label, sub);
|
||||
}
|
||||
|
||||
cleanup(target, plugin);
|
||||
return result;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
switch (this.type) {
|
||||
case TAKES_ARGUMENT_FOR_TARGET:
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> getTargets(plugin).stream()))
|
||||
.at(1, CompletionSupplier.startsWith(() -> getChildren().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.map(s -> s.getName().toLowerCase())
|
||||
))
|
||||
.from(2, partial -> getChildren().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(1)))
|
||||
.findFirst()
|
||||
.map(cmd -> cmd.tabComplete(plugin, sender, args.subList(2, args.size())))
|
||||
.orElse(Collections.emptyList())
|
||||
)
|
||||
.complete(args);
|
||||
case NO_TARGET_ARGUMENT:
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> getChildren().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.map(s -> s.getName().toLowerCase())
|
||||
))
|
||||
.from(1, partial -> getChildren().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.findFirst()
|
||||
.map(cmd -> cmd.tabComplete(plugin, sender, args.subList(1, args.size())))
|
||||
.orElse(Collections.emptyList())
|
||||
)
|
||||
.complete(args);
|
||||
default:
|
||||
throw new AssertionError(this.type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUsage(Sender sender, String label) {
|
||||
List<Command<?>> subs = getChildren().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!subs.isEmpty()) {
|
||||
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format(getUsage(), label));
|
||||
for (Command<?> s : subs) {
|
||||
s.sendUsage(sender, label);
|
||||
}
|
||||
} else {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendDetailedUsage(Sender sender, String label) {
|
||||
sendUsage(sender, label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return getChildren().stream().anyMatch(sc -> sc.isAuthorized(sender));
|
||||
}
|
||||
|
||||
protected abstract List<String> getTargets(LuckPermsPlugin plugin);
|
||||
|
||||
protected abstract I parseTarget(String target, LuckPermsPlugin plugin, Sender sender);
|
||||
|
||||
protected abstract ReentrantLock getLockForTarget(I target);
|
||||
|
||||
protected abstract T getTarget(I target, LuckPermsPlugin plugin, Sender sender);
|
||||
|
||||
protected abstract void cleanup(T t, LuckPermsPlugin plugin);
|
||||
|
||||
public enum Type {
|
||||
// e.g. /lp log sub-command....
|
||||
NO_TARGET_ARGUMENT(0),
|
||||
// e.g. /lp user <USER> sub-command....
|
||||
TAKES_ARGUMENT_FOR_TARGET(1);
|
||||
|
||||
private final int cmdIndex;
|
||||
private final int minArgs;
|
||||
|
||||
Type(int cmdIndex) {
|
||||
this.cmdIndex = cmdIndex;
|
||||
this.minArgs = cmdIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,191 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.abstraction;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A shared main command. Shared meaning it can apply to both users and groups.
|
||||
* This extends sub command as they're actually sub commands of the main user/group commands.
|
||||
* @param <T>
|
||||
*/
|
||||
public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T> {
|
||||
|
||||
private final List<SharedSubCommand> secondaryCommands;
|
||||
|
||||
/**
|
||||
* If this instance of the shared command is targeting a user. Otherwise, it targets a group.
|
||||
*/
|
||||
private final boolean user;
|
||||
|
||||
public SharedMainCommand(LocalizedCommandSpec spec, String name, boolean user, List<SharedSubCommand> secondaryCommands) {
|
||||
super(spec, name, null, Predicates.alwaysFalse());
|
||||
this.secondaryCommands = secondaryCommands;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsageDetailed(sender, this.user, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<SharedSubCommand> o = this.secondaryCommands.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final SharedSubCommand sub = o.get();
|
||||
if (!sub.isAuthorized(sender, this.user)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > 1) {
|
||||
strippedArgs.addAll(args.subList(1, args.size()));
|
||||
}
|
||||
|
||||
if (sub.getArgumentCheck().test(strippedArgs.size())) {
|
||||
sub.sendDetailedUsage(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
CommandResult result;
|
||||
try {
|
||||
result = sub.execute(plugin, sender, t, strippedArgs, label, this.user ? sub.getUserPermission() : sub.getGroupPermission());
|
||||
} catch (CommandException e) {
|
||||
result = handleException(e, sender, sub);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
final List<SharedSubCommand> subs = this.secondaryCommands.stream()
|
||||
.filter(s -> s.isAuthorized(sender, this.user))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<SharedSubCommand> o = subs.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
return o.map(cmd -> cmd.tabComplete(plugin, sender, args.subList(1, args.size()))).orElseGet(Collections::emptyList);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return this.secondaryCommands.stream().anyMatch(sc -> sc.isAuthorized(sender, this.user));
|
||||
}
|
||||
|
||||
private void sendUsageDetailed(Sender sender, boolean user, String label) {
|
||||
List<SharedSubCommand> subs = this.secondaryCommands.stream()
|
||||
.filter(s -> s.isAuthorized(sender, user))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!subs.isEmpty()) {
|
||||
if (user) {
|
||||
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s user <user> " + getName().toLowerCase(), label));
|
||||
} else {
|
||||
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s group <group> " + getName().toLowerCase(), label));
|
||||
}
|
||||
|
||||
for (SharedSubCommand s : subs) {
|
||||
s.sendUsage(sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
private static CommandResult handleException(CommandException e, Sender sender, SharedSubCommand command) {
|
||||
if (e instanceof ArgumentParser.ArgumentException) {
|
||||
if (e instanceof ArgumentParser.DetailedUsageException) {
|
||||
command.sendDetailedUsage(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.InvalidServerWorldException) {
|
||||
Message.SERVER_WORLD_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.PastDateException) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.InvalidDateException) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentParser.InvalidDateException) e).getInvalidDate());
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (e instanceof ArgumentParser.InvalidPriorityException) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, ((ArgumentParser.InvalidPriorityException) e).getInvalidPriority());
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
// Not something we can catch.
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
}
|
@ -39,10 +39,10 @@ import java.util.function.Predicate;
|
||||
/**
|
||||
* Represents a single "main" command (one without any children)
|
||||
*/
|
||||
public abstract class SingleCommand extends Command<Void, Void> {
|
||||
public abstract class SingleCommand extends Command<Void> {
|
||||
|
||||
public SingleCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
|
||||
super(spec, name, permission, argumentCheck, null);
|
||||
super(spec, name, permission, argumentCheck);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,21 +31,22 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface CompletionSupplier {
|
||||
|
||||
CompletionSupplier EMPTY = partial -> Collections.emptyList();
|
||||
|
||||
static CompletionSupplier startsWith(String... strings) {
|
||||
return partial -> Arrays.stream(strings).filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
|
||||
return startsWith(() -> Arrays.stream(strings));
|
||||
}
|
||||
|
||||
static CompletionSupplier startsWith(Collection<String> strings) {
|
||||
return partial -> strings.stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
|
||||
return startsWith(strings::stream);
|
||||
}
|
||||
|
||||
static CompletionSupplier startsWith(Supplier<? extends Collection<String>> stringsSupplier) {
|
||||
return partial -> stringsSupplier.get().stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
|
||||
static CompletionSupplier startsWith(Supplier<Stream<String>> stringsSupplier) {
|
||||
return partial -> stringsSupplier.get().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<String> supplyCompletions(String partial);
|
||||
|
@ -52,8 +52,8 @@ public final class TabCompletions {
|
||||
private final CompletionSupplier contexts;
|
||||
|
||||
public TabCompletions(LuckPermsPlugin plugin) {
|
||||
this.groups = CompletionSupplier.startsWith(() -> plugin.getGroupManager().getAll().keySet());
|
||||
this.tracks = CompletionSupplier.startsWith(() -> plugin.getTrackManager().getAll().keySet());
|
||||
this.groups = CompletionSupplier.startsWith(() -> plugin.getGroupManager().getAll().keySet().stream());
|
||||
this.tracks = CompletionSupplier.startsWith(() -> plugin.getTrackManager().getAll().keySet().stream());
|
||||
this.permissions = partial -> {
|
||||
PermissionRegistry cache = plugin.getPermissionRegistry();
|
||||
|
||||
|
@ -25,10 +25,14 @@
|
||||
|
||||
package me.lucko.luckperms.common.command.utils;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.commands.user.UserMainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.commands.user.UserParentCommand;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
@ -210,13 +214,39 @@ public class ArgumentParser {
|
||||
|
||||
public static UUID parseUserTarget(int index, List<String> args, LuckPermsPlugin plugin, Sender sender) {
|
||||
final String target = args.get(index);
|
||||
return UserMainCommand.parseTargetUniqueId(target, plugin, sender);
|
||||
return UserParentCommand.parseTargetUniqueId(target, plugin, sender);
|
||||
}
|
||||
|
||||
public abstract static class ArgumentException extends CommandException {}
|
||||
public static class DetailedUsageException extends ArgumentException {}
|
||||
public static class InvalidServerWorldException extends ArgumentException {}
|
||||
public static class PastDateException extends ArgumentException {}
|
||||
public abstract static class ArgumentException extends CommandException {
|
||||
|
||||
}
|
||||
|
||||
public static class DetailedUsageException extends ArgumentException {
|
||||
@Override
|
||||
public CommandResult handle(Sender sender) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender, String label, Command<?> command) {
|
||||
command.sendDetailedUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult handle(Sender sender, GenericChildCommand command) {
|
||||
command.sendDetailedUsage(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PastDateException extends ArgumentException {
|
||||
@Override
|
||||
public CommandResult handle(Sender sender) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidDateException extends ArgumentException {
|
||||
private final String invalidDate;
|
||||
@ -225,8 +255,10 @@ public class ArgumentParser {
|
||||
this.invalidDate = invalidDate;
|
||||
}
|
||||
|
||||
public String getInvalidDate() {
|
||||
return this.invalidDate;
|
||||
@Override
|
||||
public CommandResult handle(Sender sender) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, this.invalidDate);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,8 +269,10 @@ public class ArgumentParser {
|
||||
this.invalidPriority = invalidPriority;
|
||||
}
|
||||
|
||||
public String getInvalidPriority() {
|
||||
return this.invalidPriority;
|
||||
@Override
|
||||
public CommandResult handle(Sender sender) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, this.invalidPriority);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.command.utils;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Tokenizes command input into distinct "argument" tokens.
|
||||
*
|
||||
* <p>Splits on whitespace, except when surrounded by quotes.</p>
|
||||
*/
|
||||
public enum ArgumentTokenizer {
|
||||
|
||||
EXECUTE {
|
||||
@Override
|
||||
public List<String> tokenizeInput(String[] args) {
|
||||
return stripQuotes(EXECUTE_ARGUMENT_SPLITTER.split(ARGUMENT_JOINER.join(args)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tokenizeInput(String args) {
|
||||
return stripQuotes(EXECUTE_ARGUMENT_SPLITTER.split(args));
|
||||
}
|
||||
},
|
||||
TAB_COMPLETE {
|
||||
@Override
|
||||
public List<String> tokenizeInput(String[] args) {
|
||||
return stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.split(ARGUMENT_JOINER.join(args)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tokenizeInput(String args) {
|
||||
return stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.split(args));
|
||||
}
|
||||
};
|
||||
|
||||
private static final Pattern ARGUMENT_SEPARATOR_PATTERN = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
|
||||
private static final Splitter TAB_COMPLETE_ARGUMENT_SPLITTER = Splitter.on(ARGUMENT_SEPARATOR_PATTERN);
|
||||
private static final Splitter EXECUTE_ARGUMENT_SPLITTER = TAB_COMPLETE_ARGUMENT_SPLITTER.omitEmptyStrings();
|
||||
private static final Joiner ARGUMENT_JOINER = Joiner.on(' ');
|
||||
|
||||
public abstract List<String> tokenizeInput(String[] args);
|
||||
|
||||
public abstract List<String> tokenizeInput(String args);
|
||||
|
||||
private static List<String> stripQuotes(Iterable<String> input) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String argument : input) {
|
||||
if (argument.length() >= 3 && argument.charAt(0) == '"' && argument.charAt(argument.length() - 1) == '"') {
|
||||
list.add(argument.substring(1, argument.length() - 1));
|
||||
} else {
|
||||
list.add(argument);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -146,7 +146,7 @@ public final class MessageUtils {
|
||||
|
||||
public static String contextSetToString(LocaleManager localeManager, ContextSet set) {
|
||||
if (set.isEmpty()) {
|
||||
return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(localeManager);
|
||||
return Message.CONTEXT_PAIR_GLOBAL_INLINE.asString(localeManager);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -27,17 +27,18 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedMainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericParentCommand;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
|
||||
import net.luckperms.api.node.ChatMetaType;
|
||||
|
||||
public class CommandMeta<T extends PermissionHolder> extends SharedMainCommand<T> {
|
||||
public CommandMeta(LocaleManager locale, boolean user) {
|
||||
super(CommandSpec.META.localize(locale), "Meta", user, ImmutableList.<SharedSubCommand>builder()
|
||||
public class CommandMeta<T extends PermissionHolder> extends GenericParentCommand<T> {
|
||||
public CommandMeta(LocaleManager locale, HolderType type) {
|
||||
super(CommandSpec.META.localize(locale), "Meta", type, ImmutableList.<GenericChildCommand>builder()
|
||||
.add(new MetaInfo(locale))
|
||||
.add(new MetaSet(locale))
|
||||
.add(new MetaUnset(locale))
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -54,7 +54,7 @@ import net.luckperms.api.node.ChatMetaType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaAddChatMeta extends SharedSubCommand {
|
||||
public class MetaAddChatMeta extends GenericChildCommand {
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaAddChatMeta(LocaleManager locale, ChatMetaType type) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -58,7 +58,7 @@ import net.luckperms.api.node.ChatMetaType;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
public class MetaAddTempChatMeta extends SharedSubCommand {
|
||||
public class MetaAddTempChatMeta extends GenericChildCommand {
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaAddTempChatMeta(LocaleManager locale, ChatMetaType type) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -50,7 +50,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaClear extends SharedSubCommand {
|
||||
public class MetaClear extends GenericChildCommand {
|
||||
public MetaClear(LocaleManager locale) {
|
||||
super(CommandSpec.META_CLEAR.localize(locale), "clear", CommandPermission.USER_META_CLEAR, CommandPermission.GROUP_META_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
@ -67,7 +67,7 @@ import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class MetaInfo extends SharedSubCommand {
|
||||
public class MetaInfo extends GenericChildCommand {
|
||||
private static String processLocation(Node node, PermissionHolder holder) {
|
||||
String location = node.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
|
||||
return location.equalsIgnoreCase(holder.getObjectName()) ? "self" : location;
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -54,7 +54,7 @@ import net.luckperms.api.node.ChatMetaType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaRemoveChatMeta extends SharedSubCommand {
|
||||
public class MetaRemoveChatMeta extends GenericChildCommand {
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaRemoveChatMeta(LocaleManager locale, ChatMetaType type) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -54,7 +54,7 @@ import net.luckperms.api.node.ChatMetaType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
||||
public class MetaRemoveTempChatMeta extends GenericChildCommand {
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaRemoveTempChatMeta(LocaleManager locale, ChatMetaType type) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -56,7 +56,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaSet extends SharedSubCommand {
|
||||
public class MetaSet extends GenericChildCommand {
|
||||
public MetaSet(LocaleManager locale) {
|
||||
super(CommandSpec.META_SET.localize(locale), "set", CommandPermission.USER_META_SET, CommandPermission.GROUP_META_SET, Predicates.inRange(0, 1));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -58,7 +58,7 @@ import net.luckperms.api.query.QueryOptions;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class MetaSetChatMeta extends SharedSubCommand {
|
||||
public class MetaSetChatMeta extends GenericChildCommand {
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaSetChatMeta(LocaleManager locale, ChatMetaType type) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -60,7 +60,7 @@ import net.luckperms.api.node.NodeType;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
public class MetaSetTemp extends SharedSubCommand {
|
||||
public class MetaSetTemp extends GenericChildCommand {
|
||||
public MetaSetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.META_SETTEMP.localize(locale), "settemp", CommandPermission.USER_META_SET_TEMP, CommandPermission.GROUP_META_SET_TEMP, Predicates.inRange(0, 2));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -62,7 +62,7 @@ import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class MetaSetTempChatMeta extends SharedSubCommand {
|
||||
public class MetaSetTempChatMeta extends GenericChildCommand {
|
||||
private final ChatMetaType type;
|
||||
|
||||
public MetaSetTempChatMeta(LocaleManager locale, ChatMetaType type) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -50,7 +50,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaUnset extends SharedSubCommand {
|
||||
public class MetaUnset extends GenericChildCommand {
|
||||
public MetaUnset(LocaleManager locale) {
|
||||
super(CommandSpec.META_UNSET.localize(locale), "unset", CommandPermission.USER_META_UNSET, CommandPermission.GROUP_META_UNSET, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.meta;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -50,7 +50,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetaUnsetTemp extends SharedSubCommand {
|
||||
public class MetaUnsetTemp extends GenericChildCommand {
|
||||
public MetaUnsetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.META_UNSETTEMP.localize(locale), "unsettemp", CommandPermission.USER_META_UNSET_TEMP, CommandPermission.GROUP_META_UNSET_TEMP, Predicates.is(0));
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ package me.lucko.luckperms.common.commands.generic.other;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -39,6 +39,7 @@ import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
@ -49,9 +50,9 @@ import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HolderClear<T extends PermissionHolder> extends SubCommand<T> {
|
||||
public HolderClear(LocaleManager locale, boolean user) {
|
||||
super(CommandSpec.HOLDER_CLEAR.localize(locale), "clear", user ? CommandPermission.USER_CLEAR : CommandPermission.GROUP_CLEAR, Predicates.alwaysFalse());
|
||||
public class HolderClear<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
public HolderClear(LocaleManager locale, HolderType type) {
|
||||
super(CommandSpec.HOLDER_CLEAR.localize(locale), "clear", type == HolderType.USER ? CommandPermission.USER_CLEAR : CommandPermission.GROUP_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,13 +28,14 @@ package me.lucko.luckperms.common.commands.generic.other;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
@ -44,9 +45,9 @@ import me.lucko.luckperms.common.web.WebEditor;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HolderEditor<T extends PermissionHolder> extends SubCommand<T> {
|
||||
public HolderEditor(LocaleManager locale, boolean user) {
|
||||
super(CommandSpec.HOLDER_EDITOR.localize(locale), "editor", user ? CommandPermission.USER_EDITOR : CommandPermission.GROUP_EDITOR, Predicates.alwaysFalse());
|
||||
public class HolderEditor<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
public HolderEditor(LocaleManager locale, HolderType type) {
|
||||
super(CommandSpec.HOLDER_EDITOR.localize(locale), "editor", type == HolderType.USER ? CommandPermission.USER_EDITOR : CommandPermission.GROUP_EDITOR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.other;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
@ -52,9 +52,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T> {
|
||||
public HolderShowTracks(LocaleManager locale, boolean user) {
|
||||
super(CommandSpec.HOLDER_SHOWTRACKS.localize(locale), "showtracks", user ? CommandPermission.USER_SHOW_TRACKS : CommandPermission.GROUP_SHOW_TRACKS, Predicates.alwaysFalse());
|
||||
public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T> {
|
||||
public HolderShowTracks(LocaleManager locale, HolderType type) {
|
||||
super(CommandSpec.HOLDER_SHOWTRACKS.localize(locale), "showtracks", type == HolderType.USER ? CommandPermission.USER_SHOW_TRACKS : CommandPermission.GROUP_SHOW_TRACKS, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,17 +27,18 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedMainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericParentCommand;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class CommandParent<T extends PermissionHolder> extends SharedMainCommand<T> {
|
||||
public CommandParent(LocaleManager locale, boolean user) {
|
||||
super(CommandSpec.PARENT.localize(locale), "Parent", user, ImmutableList.<SharedSubCommand>builder()
|
||||
public class CommandParent<T extends PermissionHolder> extends GenericParentCommand<T> {
|
||||
public CommandParent(LocaleManager locale, HolderType type) {
|
||||
super(CommandSpec.PARENT.localize(locale), "Parent", type, ImmutableList.<GenericChildCommand>builder()
|
||||
.add(new ParentInfo(locale))
|
||||
.add(new ParentSet(locale))
|
||||
.add(new ParentAdd(locale))
|
||||
@ -47,7 +48,7 @@ public class CommandParent<T extends PermissionHolder> extends SharedMainCommand
|
||||
.add(new ParentRemoveTemp(locale))
|
||||
.add(new ParentClear(locale))
|
||||
.add(new ParentClearTrack(locale))
|
||||
.addAll(user ? Collections.singleton(new UserSwitchPrimaryGroup(locale)) : Collections.emptySet())
|
||||
.addAll(type == HolderType.USER ? Collections.singleton(new UserSwitchPrimaryGroup(locale)) : Collections.emptySet())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -52,7 +52,7 @@ import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentAdd extends SharedSubCommand {
|
||||
public class ParentAdd extends GenericChildCommand {
|
||||
public ParentAdd(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_ADD.localize(locale), "add", CommandPermission.USER_PARENT_ADD, CommandPermission.GROUP_PARENT_ADD, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -56,7 +56,7 @@ import net.luckperms.api.model.data.TemporaryNodeMergeStrategy;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
public class ParentAddTemp extends SharedSubCommand {
|
||||
public class ParentAddTemp extends GenericChildCommand {
|
||||
public ParentAddTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_ADD_TEMP.localize(locale), "addtemp", CommandPermission.USER_PARENT_ADD_TEMP, CommandPermission.GROUP_PARENT_ADD_TEMP, Predicates.inRange(0, 1));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -50,7 +50,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentClear extends SharedSubCommand {
|
||||
public class ParentClear extends GenericChildCommand {
|
||||
public ParentClear(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_CLEAR.localize(locale), "clear", CommandPermission.USER_PARENT_CLEAR, CommandPermission.GROUP_PARENT_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -54,7 +54,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentClearTrack extends SharedSubCommand {
|
||||
public class ParentClearTrack extends GenericChildCommand {
|
||||
public ParentClearTrack(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_CLEAR_TRACK.localize(locale), "cleartrack", CommandPermission.USER_PARENT_CLEAR_TRACK, CommandPermission.GROUP_PARENT_CLEAR_TRACK, Predicates.is(0));
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.common.commands.generic.parent;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
@ -60,7 +60,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ParentInfo extends SharedSubCommand {
|
||||
public class ParentInfo extends GenericChildCommand {
|
||||
public ParentInfo(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_INFO.localize(locale), "info", CommandPermission.USER_PARENT_INFO, CommandPermission.GROUP_PARENT_INFO, Predicates.notInRange(0, 2));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -55,7 +55,7 @@ import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentRemove extends SharedSubCommand {
|
||||
public class ParentRemove extends GenericChildCommand {
|
||||
public ParentRemove(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_REMOVE.localize(locale), "remove", CommandPermission.USER_PARENT_REMOVE, CommandPermission.GROUP_PARENT_REMOVE, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -51,7 +51,7 @@ import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentRemoveTemp extends SharedSubCommand {
|
||||
public class ParentRemoveTemp extends GenericChildCommand {
|
||||
public ParentRemoveTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_REMOVE_TEMP.localize(locale), "removetemp", CommandPermission.USER_PARENT_REMOVE_TEMP, CommandPermission.GROUP_PARENT_REMOVE_TEMP, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -54,7 +54,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentSet extends SharedSubCommand {
|
||||
public class ParentSet extends GenericChildCommand {
|
||||
public ParentSet(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_SET.localize(locale), "set", CommandPermission.USER_PARENT_SET, CommandPermission.GROUP_PARENT_SET, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -54,7 +54,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParentSetTrack extends SharedSubCommand {
|
||||
public class ParentSetTrack extends GenericChildCommand {
|
||||
public ParentSetTrack(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_SET_TRACK.localize(locale), "settrack", CommandPermission.USER_PARENT_SET_TRACK, CommandPermission.GROUP_PARENT_SET_TRACK, Predicates.inRange(0, 1));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.generic.parent;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -53,7 +53,7 @@ import net.luckperms.api.node.NodeEqualityPredicate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserSwitchPrimaryGroup extends SharedSubCommand {
|
||||
public class UserSwitchPrimaryGroup extends GenericChildCommand {
|
||||
public UserSwitchPrimaryGroup(LocaleManager locale) {
|
||||
super(CommandSpec.USER_SWITCHPRIMARYGROUP.localize(locale), "switchprimarygroup", CommandPermission.USER_PARENT_SWITCHPRIMARYGROUP, null, Predicates.not(1));
|
||||
}
|
||||
|
@ -27,15 +27,16 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedMainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericParentCommand;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
|
||||
public class CommandPermission<T extends PermissionHolder> extends SharedMainCommand<T> {
|
||||
public CommandPermission(LocaleManager locale, boolean user) {
|
||||
super(CommandSpec.PERMISSION.localize(locale), "Permission", user, ImmutableList.<SharedSubCommand>builder()
|
||||
public class CommandPermission<T extends PermissionHolder> extends GenericParentCommand<T> {
|
||||
public CommandPermission(LocaleManager locale, HolderType type) {
|
||||
super(CommandSpec.PERMISSION.localize(locale), "Permission", type, ImmutableList.<GenericChildCommand>builder()
|
||||
.add(new PermissionInfo(locale))
|
||||
.add(new PermissionSet(locale))
|
||||
.add(new PermissionUnset(locale))
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -50,7 +50,7 @@ import net.luckperms.api.util.Tristate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionCheck extends SharedSubCommand {
|
||||
public class PermissionCheck extends GenericChildCommand {
|
||||
public PermissionCheck(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_CHECK.localize(locale), "check", CommandPermission.USER_PERM_CHECK, CommandPermission.GROUP_PERM_CHECK, Predicates.is(0));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -51,7 +51,7 @@ import net.luckperms.api.util.Tristate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PermissionCheckInherits extends SharedSubCommand {
|
||||
public class PermissionCheckInherits extends GenericChildCommand {
|
||||
public PermissionCheckInherits(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_CHECK_INHERITS.localize(locale), "checkinherits", CommandPermission.USER_PERM_CHECK_INHERITS, CommandPermission.GROUP_PERM_CHECK_INHERITS, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -50,7 +50,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionClear extends SharedSubCommand {
|
||||
public class PermissionClear extends GenericChildCommand {
|
||||
public PermissionClear(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_CLEAR.localize(locale), "clear", CommandPermission.USER_PERM_CLEAR, CommandPermission.GROUP_PERM_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.common.commands.generic.permission;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
@ -60,7 +60,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PermissionInfo extends SharedSubCommand {
|
||||
public class PermissionInfo extends GenericChildCommand {
|
||||
public PermissionInfo(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_INFO.localize(locale), "info", CommandPermission.USER_PERM_INFO, CommandPermission.GROUP_PERM_INFO, Predicates.notInRange(0, 2));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -53,7 +53,7 @@ import net.luckperms.api.node.types.InheritanceNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionSet extends SharedSubCommand {
|
||||
public class PermissionSet extends GenericChildCommand {
|
||||
public PermissionSet(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_SET.localize(locale), "set", CommandPermission.USER_PERM_SET, CommandPermission.GROUP_PERM_SET, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -57,7 +57,7 @@ import net.luckperms.api.node.types.InheritanceNode;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionSetTemp extends SharedSubCommand {
|
||||
public class PermissionSetTemp extends GenericChildCommand {
|
||||
public PermissionSetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_SETTEMP.localize(locale), "settemp", CommandPermission.USER_PERM_SET_TEMP, CommandPermission.GROUP_PERM_SET_TEMP, Predicates.inRange(0, 2));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -53,7 +53,7 @@ import net.luckperms.api.node.types.InheritanceNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionUnset extends SharedSubCommand {
|
||||
public class PermissionUnset extends GenericChildCommand {
|
||||
public PermissionUnset(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_UNSET.localize(locale), "unset", CommandPermission.USER_PERM_UNSET, CommandPermission.GROUP_PERM_UNSET, Predicates.is(0));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.generic.permission;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -53,7 +53,7 @@ import net.luckperms.api.node.types.InheritanceNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionUnsetTemp extends SharedSubCommand {
|
||||
public class PermissionUnsetTemp extends GenericChildCommand {
|
||||
public PermissionUnsetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_UNSETTEMP.localize(locale), "unsettemp", CommandPermission.USER_PERM_UNSET_TEMP, CommandPermission.GROUP_PERM_UNSET_TEMP, Predicates.is(0));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.group;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -45,7 +45,7 @@ import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupClone extends SubCommand<Group> {
|
||||
public class GroupClone extends ChildCommand<Group> {
|
||||
public GroupClone(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_CLONE.localize(locale), "clone", CommandPermission.GROUP_CLONE, Predicates.not(1));
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.common.commands.group;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
@ -45,7 +45,7 @@ import net.luckperms.api.node.types.InheritanceNode;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupInfo extends SubCommand<Group> {
|
||||
public class GroupInfo extends ChildCommand<Group> {
|
||||
public GroupInfo(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_INFO.localize(locale), "info", CommandPermission.GROUP_INFO, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import me.lucko.luckperms.common.bulkupdate.comparison.Constraint;
|
||||
import me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison;
|
||||
import me.lucko.luckperms.common.cache.LoadingMap;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
@ -68,7 +68,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupListMembers extends SubCommand<Group> {
|
||||
public class GroupListMembers extends ChildCommand<Group> {
|
||||
public GroupListMembers(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_LISTMEMBERS.localize(locale), "listmembers", CommandPermission.GROUP_LIST_MEMBERS, Predicates.notInRange(0, 1));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.MainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.commands.generic.meta.CommandMeta;
|
||||
import me.lucko.luckperms.common.commands.generic.other.HolderClear;
|
||||
@ -40,6 +40,7 @@ import me.lucko.luckperms.common.commands.generic.permission.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.util.CaffeineFactory;
|
||||
@ -49,7 +50,7 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class GroupMainCommand extends MainCommand<Group, String> {
|
||||
public class GroupParentCommand extends ParentCommand<Group, String> {
|
||||
|
||||
// we use a lock per unique group
|
||||
// this helps prevent race conditions where commands are being executed concurrently
|
||||
@ -59,18 +60,18 @@ public class GroupMainCommand extends MainCommand<Group, String> {
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build(key -> new ReentrantLock());
|
||||
|
||||
public GroupMainCommand(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP.localize(locale), "Group", 2, ImmutableList.<Command<Group, ?>>builder()
|
||||
public GroupParentCommand(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP.localize(locale), "Group", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.<Command<Group>>builder()
|
||||
.add(new GroupInfo(locale))
|
||||
.add(new CommandPermission<>(locale, false))
|
||||
.add(new CommandParent<>(locale, false))
|
||||
.add(new CommandMeta<>(locale, false))
|
||||
.add(new HolderEditor<>(locale, false))
|
||||
.add(new CommandPermission<>(locale, HolderType.GROUP))
|
||||
.add(new CommandParent<>(locale, HolderType.GROUP))
|
||||
.add(new CommandMeta<>(locale, HolderType.GROUP))
|
||||
.add(new HolderEditor<>(locale, HolderType.GROUP))
|
||||
.add(new GroupListMembers(locale))
|
||||
.add(new GroupSetWeight(locale))
|
||||
.add(new GroupSetDisplayName(locale))
|
||||
.add(new HolderShowTracks<>(locale, false))
|
||||
.add(new HolderClear<>(locale, false))
|
||||
.add(new HolderShowTracks<>(locale, HolderType.GROUP))
|
||||
.add(new HolderClear<>(locale, HolderType.GROUP))
|
||||
.add(new GroupRename(locale))
|
||||
.add(new GroupClone(locale))
|
||||
.build()
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.group;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -45,7 +45,7 @@ import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupRename extends SubCommand<Group> {
|
||||
public class GroupRename extends ChildCommand<Group> {
|
||||
public GroupRename(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_RENAME.localize(locale), "rename", CommandPermission.GROUP_RENAME, Predicates.not(1));
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ package me.lucko.luckperms.common.commands.group;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -52,7 +52,7 @@ import net.luckperms.api.node.types.DisplayNameNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetDisplayName extends SubCommand<Group> {
|
||||
public class GroupSetDisplayName extends ChildCommand<Group> {
|
||||
public GroupSetDisplayName(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_SET_DISPLAY_NAME.localize(locale), "setdisplayname", CommandPermission.GROUP_SET_DISPLAY_NAME, Predicates.is(0));
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ package me.lucko.luckperms.common.commands.group;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
@ -47,7 +47,7 @@ import net.luckperms.api.node.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetWeight extends SubCommand<Group> {
|
||||
public class GroupSetWeight extends ChildCommand<Group> {
|
||||
public GroupSetWeight(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_SETWEIGHT.localize(locale), "setweight", CommandPermission.GROUP_SET_WEIGHT, Predicates.not(1));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.log;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
@ -49,7 +49,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public class LogGroupHistory extends SubCommand<Log> {
|
||||
public class LogGroupHistory extends ChildCommand<Log> {
|
||||
private static final int ENTRIES_PER_PAGE = 10;
|
||||
|
||||
public LogGroupHistory(LocaleManager locale) {
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.log;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -46,7 +46,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogNotify extends SubCommand<Log> {
|
||||
public class LogNotify extends ChildCommand<Log> {
|
||||
private static final String IGNORE_NODE = "luckperms.log.notify.ignoring";
|
||||
|
||||
public LogNotify(LocaleManager locale) {
|
||||
|
@ -29,24 +29,21 @@ import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.MainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LogMainCommand extends MainCommand<Log, Object> {
|
||||
public class LogParentCommand extends ParentCommand<Log, Void> {
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public LogMainCommand(LocaleManager locale) {
|
||||
super(CommandSpec.LOG.localize(locale), "Log", 1, ImmutableList.<Command<Log, ?>>builder()
|
||||
public LogParentCommand(LocaleManager locale) {
|
||||
super(CommandSpec.LOG.localize(locale), "Log", Type.NO_TARGET_ARGUMENT, ImmutableList.<Command<Log>>builder()
|
||||
.add(new LogRecent(locale))
|
||||
.add(new LogSearch(locale))
|
||||
.add(new LogNotify(locale))
|
||||
@ -58,17 +55,12 @@ public class LogMainCommand extends MainCommand<Log, Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReentrantLock getLockForTarget(Object target) {
|
||||
protected ReentrantLock getLockForTarget(Void target) {
|
||||
return this.lock; // all commands target the same log, so we share a lock between all "targets"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Log getTarget(Object target, LuckPermsPlugin plugin, Sender sender) {
|
||||
protected Log getTarget(Void target, LuckPermsPlugin plugin, Sender sender) {
|
||||
Log log = plugin.getStorage().getLog().join();
|
||||
|
||||
if (log == null) {
|
||||
@ -85,33 +77,14 @@ public class LogMainCommand extends MainCommand<Log, Object> {
|
||||
|
||||
@Override
|
||||
protected List<String> getTargets(LuckPermsPlugin plugin) {
|
||||
return null; // only used for tab completion in super, and we override this method
|
||||
// should never be called if we specify Type.NO_TARGET_ARGUMENT in the constructor
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
final List<Command<Log, ?>> subs = getChildren().get().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
protected Void parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
// should never be called if we specify Type.NO_TARGET_ARGUMENT in the constructor
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<Command<Log, ?>> o = subs.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
return o.map(cmd -> cmd.tabComplete(plugin, sender, args.subList(1, args.size()))).orElseGet(Collections::emptyList);
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.log;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -47,7 +47,7 @@ import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogRecent extends SubCommand<Log> {
|
||||
public class LogRecent extends ChildCommand<Log> {
|
||||
private static final int ENTRIES_PER_PAGE = 10;
|
||||
|
||||
public LogRecent(LocaleManager locale) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.log;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -45,7 +45,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public class LogSearch extends SubCommand<Log> {
|
||||
public class LogSearch extends ChildCommand<Log> {
|
||||
private static final int ENTRIES_PER_PAGE = 10;
|
||||
|
||||
public LogSearch(LocaleManager locale) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.log;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
@ -49,7 +49,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public class LogTrackHistory extends SubCommand<Log> {
|
||||
public class LogTrackHistory extends ChildCommand<Log> {
|
||||
private static final int ENTRIES_PER_PAGE = 10;
|
||||
|
||||
public LogTrackHistory(LocaleManager locale) {
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.common.commands.log;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -47,7 +47,7 @@ import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LogUserHistory extends SubCommand<Log> {
|
||||
public class LogUserHistory extends ChildCommand<Log> {
|
||||
private static final int ENTRIES_PER_PAGE = 10;
|
||||
|
||||
public LogUserHistory(LocaleManager locale) {
|
||||
|
@ -28,9 +28,9 @@ package me.lucko.luckperms.common.commands.migration;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.MainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -41,13 +41,11 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
public class MigrationParentCommand extends ParentCommand<Object, Void> {
|
||||
private static final Map<String, String> PLUGINS = ImmutableBiMap.<String, String>builder()
|
||||
// bukkit
|
||||
.put("me.lucko.luckperms.bukkit.migration.MigrationGroupManager", "org.anjocaido.groupmanager.GroupManager")
|
||||
@ -61,22 +59,22 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
.build().inverse();
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private List<Command<Object, ?>> commands = null;
|
||||
private List<Command<Object>> commands = null;
|
||||
private boolean display = true;
|
||||
|
||||
public MigrationMainCommand(LocaleManager locale) {
|
||||
super(CommandSpec.MIGRATION.localize(locale), "Migration", 1, null);
|
||||
public MigrationParentCommand(LocaleManager locale) {
|
||||
super(CommandSpec.MIGRATION.localize(locale), "Migration", Type.NO_TARGET_ARGUMENT, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized @NonNull Optional<List<Command<Object, ?>>> getChildren() {
|
||||
public synchronized @NonNull List<Command<Object>> getChildren() {
|
||||
if (this.commands == null) {
|
||||
this.commands = getAvailableCommands(getSpec().getLocaleManager());
|
||||
|
||||
// Add dummy command to show in the list.
|
||||
if (this.commands.isEmpty()) {
|
||||
this.display = false;
|
||||
this.commands.add(new SubCommand<Object>(CommandSpec.MIGRATION_COMMAND.localize(getSpec().getLocaleManager()), "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) {
|
||||
this.commands.add(new ChildCommand<Object>(CommandSpec.MIGRATION_COMMAND.localize(getSpec().getLocaleManager()), "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
return CommandResult.SUCCESS;
|
||||
@ -84,8 +82,7 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.of(this.commands);
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,21 +97,21 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Command<Object, ?>> getAvailableCommands(LocaleManager locale) {
|
||||
List<Command<Object, ?>> l = new ArrayList<>();
|
||||
private static List<Command<Object>> getAvailableCommands(LocaleManager locale) {
|
||||
List<Command<Object>> available = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, String> plugin : PLUGINS.entrySet()) {
|
||||
try {
|
||||
Class.forName(plugin.getKey());
|
||||
l.add((SubCommand<Object>) Class.forName(plugin.getValue()).getConstructor(LocaleManager.class).newInstance(locale));
|
||||
available.add((ChildCommand<Object>) Class.forName(plugin.getValue()).getConstructor(LocaleManager.class).newInstance(locale));
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
return l;
|
||||
return available;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReentrantLock getLockForTarget(Object target) {
|
||||
protected ReentrantLock getLockForTarget(Void target) {
|
||||
return this.lock; // share a lock between all migration commands
|
||||
}
|
||||
|
||||
@ -122,16 +119,18 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
|
||||
@Override
|
||||
protected List<String> getTargets(LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList(); // only used for tab complete, we're not bothered about it for this command.
|
||||
// should never be called if we specify Type.NO_TARGET_ARGUMENT in the constructor
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
return this; // can't return null, but we don't need a target
|
||||
protected Void parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
// should never be called if we specify Type.NO_TARGET_ARGUMENT in the constructor
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getTarget(Object target, LuckPermsPlugin plugin, Sender sender) {
|
||||
protected Object getTarget(Void target, LuckPermsPlugin plugin, Sender sender) {
|
||||
return this; // can't return null, but we don't need a target
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ import net.luckperms.api.util.Tristate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CheckCommand extends SingleCommand {
|
||||
public CheckCommand(LocaleManager locale) {
|
||||
@ -79,7 +78,7 @@ public class CheckCommand extends SingleCommand {
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList().collect(Collectors.toList())))
|
||||
.at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList()))
|
||||
.at(1, TabCompletions.permissions(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
@ -47,7 +47,7 @@ import net.luckperms.api.model.data.DataMutateResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackAppend extends SubCommand<Track> {
|
||||
public class TrackAppend extends ChildCommand<Track> {
|
||||
public TrackAppend(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_APPEND.localize(locale), "append", CommandPermission.TRACK_APPEND, Predicates.not(1));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -40,7 +40,7 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackClear extends SubCommand<Track> {
|
||||
public class TrackClear extends ChildCommand<Track> {
|
||||
public TrackClear(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_CLEAR.localize(locale), "clear", CommandPermission.TRACK_CLEAR, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -43,7 +43,7 @@ import net.luckperms.api.event.cause.CreationCause;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackClone extends SubCommand<Track> {
|
||||
public class TrackClone extends ChildCommand<Track> {
|
||||
public TrackClone(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_CLONE.localize(locale), "clone", CommandPermission.TRACK_CLONE, Predicates.not(1));
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.common.commands.track;
|
||||
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -39,7 +39,7 @@ import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackInfo extends SubCommand<Track> {
|
||||
public class TrackInfo extends ChildCommand<Track> {
|
||||
public TrackInfo(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_INFO.localize(locale), "info", CommandPermission.TRACK_INFO, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
@ -47,7 +47,7 @@ import net.luckperms.api.model.data.DataMutateResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackInsert extends SubCommand<Track> {
|
||||
public class TrackInsert extends ChildCommand<Track> {
|
||||
public TrackInsert(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_INSERT.localize(locale), "insert", CommandPermission.TRACK_INSERT, Predicates.not(2));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.MainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
@ -43,7 +43,7 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class TrackMainCommand extends MainCommand<Track, String> {
|
||||
public class TrackParentCommand extends ParentCommand<Track, String> {
|
||||
|
||||
// we use a lock per unique track
|
||||
// this helps prevent race conditions where commands are being executed concurrently
|
||||
@ -53,8 +53,8 @@ public class TrackMainCommand extends MainCommand<Track, String> {
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build(key -> new ReentrantLock());
|
||||
|
||||
public TrackMainCommand(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK.localize(locale), "Track", 2, ImmutableList.<Command<Track, ?>>builder()
|
||||
public TrackParentCommand(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK.localize(locale), "Track", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.<Command<Track>>builder()
|
||||
.add(new TrackInfo(locale))
|
||||
.add(new TrackAppend(locale))
|
||||
.add(new TrackInsert(locale))
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
@ -46,7 +46,7 @@ import net.luckperms.api.model.data.DataMutateResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackRemove extends SubCommand<Track> {
|
||||
public class TrackRemove extends ChildCommand<Track> {
|
||||
public TrackRemove(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_REMOVE.localize(locale), "remove", CommandPermission.TRACK_REMOVE, Predicates.not(1));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.track;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
@ -44,7 +44,7 @@ import net.luckperms.api.event.cause.DeletionCause;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackRename extends SubCommand<Track> {
|
||||
public class TrackRename extends ChildCommand<Track> {
|
||||
public TrackRename(LocaleManager locale) {
|
||||
super(CommandSpec.TRACK_RENAME.localize(locale), "rename", CommandPermission.TRACK_RENAME, Predicates.not(1));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.common.commands.user;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
@ -45,7 +45,7 @@ import net.luckperms.api.model.data.DataType;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserClone extends SubCommand<User> {
|
||||
public class UserClone extends ChildCommand<User> {
|
||||
public UserClone(LocaleManager locale) {
|
||||
super(CommandSpec.USER_CLONE.localize(locale), "clone", CommandPermission.USER_CLONE, Predicates.not(1));
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ package me.lucko.luckperms.common.commands.user;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -52,7 +52,7 @@ import net.luckperms.api.track.DemotionResult;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class UserDemote extends SubCommand<User> {
|
||||
public class UserDemote extends ChildCommand<User> {
|
||||
public UserDemote(LocaleManager locale) {
|
||||
super(CommandSpec.USER_DEMOTE.localize(locale), "demote", CommandPermission.USER_DEMOTE, Predicates.is(0));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.common.cacheddata.type.MetaCache;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
@ -52,7 +52,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserInfo extends SubCommand<User> {
|
||||
public class UserInfo extends ChildCommand<User> {
|
||||
public UserInfo(LocaleManager locale) {
|
||||
super(CommandSpec.USER_INFO.localize(locale), "info", CommandPermission.USER_INFO, Predicates.alwaysFalse());
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||
import me.lucko.luckperms.common.command.abstraction.MainCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
|
||||
import me.lucko.luckperms.common.commands.generic.meta.CommandMeta;
|
||||
import me.lucko.luckperms.common.commands.generic.other.HolderClear;
|
||||
import me.lucko.luckperms.common.commands.generic.other.HolderEditor;
|
||||
@ -40,6 +40,7 @@ import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.model.UserIdentifier;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@ -54,7 +55,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserMainCommand extends MainCommand<User, UserIdentifier> {
|
||||
public class UserParentCommand extends ParentCommand<User, UserIdentifier> {
|
||||
|
||||
// we use a lock per unique user
|
||||
// this helps prevent race conditions where commands are being executed concurrently
|
||||
@ -64,17 +65,17 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build(key -> new ReentrantLock());
|
||||
|
||||
public UserMainCommand(LocaleManager locale) {
|
||||
super(CommandSpec.USER.localize(locale), "User", 2, ImmutableList.<Command<User, ?>>builder()
|
||||
public UserParentCommand(LocaleManager locale) {
|
||||
super(CommandSpec.USER.localize(locale), "User", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.<Command<User>>builder()
|
||||
.add(new UserInfo(locale))
|
||||
.add(new CommandPermission<>(locale, true))
|
||||
.add(new CommandParent<>(locale, true))
|
||||
.add(new CommandMeta<>(locale, true))
|
||||
.add(new HolderEditor<>(locale, true))
|
||||
.add(new CommandPermission<>(locale, HolderType.USER))
|
||||
.add(new CommandParent<>(locale, HolderType.USER))
|
||||
.add(new CommandMeta<>(locale, HolderType.USER))
|
||||
.add(new HolderEditor<>(locale, HolderType.USER))
|
||||
.add(new UserPromote(locale))
|
||||
.add(new UserDemote(locale))
|
||||
.add(new HolderShowTracks<>(locale, true))
|
||||
.add(new HolderClear<>(locale, true))
|
||||
.add(new HolderShowTracks<>(locale, HolderType.USER))
|
||||
.add(new HolderClear<>(locale, HolderType.USER))
|
||||
.add(new UserClone(locale))
|
||||
.build()
|
||||
);
|
@ -27,8 +27,8 @@ package me.lucko.luckperms.common.commands.user;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.LoggedAction;
|
||||
import me.lucko.luckperms.common.command.CommandResult;
|
||||
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
|
||||
import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
@ -52,7 +52,7 @@ import net.luckperms.api.track.PromotionResult;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class UserPromote extends SubCommand<User> {
|
||||
public class UserPromote extends ChildCommand<User> {
|
||||
public UserPromote(LocaleManager locale) {
|
||||
super(CommandSpec.USER_PROMOTE.localize(locale), "promote", CommandPermission.USER_PROMOTE, Predicates.is(0));
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ public abstract class ContextManager<T> {
|
||||
private static String getCalculatorClass(ContextCalculator<?> calculator) {
|
||||
Class<?> calculatorClass;
|
||||
if (calculator instanceof ProxiedContextCalculator) {
|
||||
calculatorClass = ((ProxiedContextCalculator) calculator).getDelegate().getClass();
|
||||
calculatorClass = ((ProxiedContextCalculator<?>) calculator).getDelegate().getClass();
|
||||
} else {
|
||||
calculatorClass = calculator.getClass();
|
||||
}
|
||||
|
@ -26,18 +26,12 @@
|
||||
package me.lucko.luckperms.common.dependencies;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import me.lucko.luckperms.common.dependencies.relocation.Relocation;
|
||||
import me.lucko.luckperms.common.dependencies.relocation.RelocationHelper;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
@ -319,6 +313,7 @@ public enum Dependency {
|
||||
return s.replace("{}", ".");
|
||||
}
|
||||
|
||||
/*
|
||||
public static void main(String[] args) throws Exception {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
@ -346,6 +341,7 @@ public enum Dependency {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public List<URL> getUrls() {
|
||||
return this.urls;
|
||||
|
@ -192,7 +192,7 @@ public class DependencyManager {
|
||||
}
|
||||
|
||||
try {
|
||||
this.plugin.getBootstrap().getPluginClassLoader().loadJar(source.file);
|
||||
this.plugin.getBootstrap().getPluginClassLoader().addJarToClasspath(source.file);
|
||||
this.loaded.put(source.dependency, source.file);
|
||||
} catch (Throwable e) {
|
||||
this.plugin.getLogger().severe("Failed to load dependency jar '" + source.file.getFileName().toString() + "'.");
|
||||
|
@ -32,6 +32,6 @@ import java.nio.file.Path;
|
||||
*/
|
||||
public interface PluginClassLoader {
|
||||
|
||||
void loadJar(Path file);
|
||||
void addJarToClasspath(Path file);
|
||||
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class ReflectionClassLoader implements PluginClassLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadJar(Path file) {
|
||||
public void addJarToClasspath(Path file) {
|
||||
try {
|
||||
ADD_URL_METHOD.invoke(this.classLoader, file.toUri().toURL());
|
||||
} catch (IllegalAccessException | InvocationTargetException | MalformedURLException e) {
|
||||
|
@ -137,7 +137,7 @@ public abstract class AbstractEventBus<P> implements EventBus, AutoCloseable {
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
protected void unregisterHandlers(P plugin) {
|
||||
this.bus.unregister(sub -> ((LuckPermsEventSubscription) sub).getPlugin() == plugin);
|
||||
this.bus.unregister(sub -> ((LuckPermsEventSubscription<?>) sub).getPlugin() == plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,7 +136,7 @@ public class SimpleExtensionManager implements ExtensionManager, AutoCloseable {
|
||||
throw new IllegalArgumentException("class is null");
|
||||
}
|
||||
|
||||
this.plugin.getBootstrap().getPluginClassLoader().loadJar(path);
|
||||
this.plugin.getBootstrap().getPluginClassLoader().addJarToClasspath(path);
|
||||
|
||||
Class<? extends Extension> extensionClass;
|
||||
try {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user