diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java index 48d5ac670..6bd129ea4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java @@ -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 arguments = stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); - - onCommand(lpSender, label, arguments); + Sender wrapped = this.plugin.getSenderFactory().wrap(sender); + List arguments = ArgumentTokenizer.EXECUTE.tokenizeInput(args); + executeCommand(wrapped, label, arguments); return true; } @Override public List onTabComplete(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, @NonNull String[] args) { - Sender lpSender = this.plugin.getSenderFactory().wrap(sender); - List arguments = stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); - - return onTabComplete(lpSender, arguments); + Sender wrapped = this.plugin.getSenderFactory().wrap(sender); + List arguments = ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args); + return tabCompleteCommand(wrapped, arguments); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/LuckPermsDefaultsMap.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/LuckPermsDefaultsMap.java index e94c6a7fb..b1d9b93d4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/LuckPermsDefaultsMap.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/server/LuckPermsDefaultsMap.java @@ -113,12 +113,9 @@ public final class LuckPermsDefaultsMap implements Map> } // return wrappers around this map impl - @Override - public @NonNull Collection> values() { return this.values; } - @Override - public @NonNull Set>> entrySet() { return this.entrySet; } - @Override - public @NonNull Set keySet() { return KEY_SET; } + @Override public @NonNull Collection> values() { return this.values; } + @Override public @NonNull Set>> entrySet() { return this.entrySet; } + @Override public @NonNull Set keySet() { return KEY_SET; } // return accurate results for the Map spec @Override public int size() { return 2; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index 0e8a385ef..b416a1ae4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -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 { +public class MigrationBPermissions extends ChildCommand { private static final Field UCONFIG_FIELD; static { try { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index 2029ceb8b..42a5fa883 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -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 { +public class MigrationGroupManager extends ChildCommand { public MigrationGroupManager(LocaleManager locale) { super(CommandSpec.MIGRATION_GROUPMANAGER.localize(locale), "groupmanager", CommandPermission.MIGRATION, Predicates.is(0)); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java index 8d72585c3..3b92cbbc2 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java @@ -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 { +public class MigrationPermissionsBukkit extends ChildCommand { public MigrationPermissionsBukkit(LocaleManager locale) { super(CommandSpec.MIGRATION_COMMAND.localize(locale), "permissionsbukkit", CommandPermission.MIGRATION, Predicates.alwaysFalse()); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index b65e68fc4..d2fe14c9f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -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 { +public class MigrationPermissionsEx extends ChildCommand { private static final Method GET_DATA_METHOD; private static final Field TIMED_PERMISSIONS_FIELD; private static final Field TIMED_PERMISSIONS_TIME_FIELD; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index 51834b2eb..775398750 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -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 { +public class MigrationPowerfulPerms extends ChildCommand { public MigrationPowerfulPerms(LocaleManager locale) { super(CommandSpec.MIGRATION_POWERFULPERMS.localize(locale), "powerfulperms", CommandPermission.MIGRATION, Predicates.not(5)); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index a9c790093..32f5d7f7c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -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 { +public class MigrationZPermissions extends ChildCommand { public MigrationZPermissions(LocaleManager locale) { super(CommandSpec.MIGRATION_COMMAND.localize(locale), "zpermissions", CommandPermission.MIGRATION, Predicates.alwaysFalse()); } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommandExecutor.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommandExecutor.java index d6d08ae7c..e27db32eb 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommandExecutor.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommandExecutor.java @@ -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 arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); - - this.manager.onCommand(lpSender, "lpb", arguments); + Sender wrapped = this.plugin.getSenderFactory().wrap(sender); + List arguments = ArgumentTokenizer.EXECUTE.tokenizeInput(args); + this.manager.executeCommand(wrapped, "lpb", arguments); } @Override public Iterable onTabComplete(CommandSender sender, String[] args) { - Sender lpSender = this.plugin.getSenderFactory().wrap(sender); - List 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 arguments = ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args); + return this.manager.tabCompleteCommand(wrapped, arguments); } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index 0adcf965e..302210b54 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -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 { +public class MigrationBungeePerms extends ChildCommand { public MigrationBungeePerms(LocaleManager locale) { super(CommandSpec.MIGRATION_COMMAND.localize(locale), "bungeeperms", CommandPermission.MIGRATION, Predicates.alwaysFalse()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiActionLog.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiActionLog.java index e365fe5b9..8a45b019e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiActionLog.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiActionLog.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java index 1465f26dc..ad10a72c9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java @@ -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; } diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/LegacyImporter.java b/common/src/main/java/me/lucko/luckperms/common/backup/LegacyImporter.java index 4c979b51e..2f0d34c83 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/LegacyImporter.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/LegacyImporter.java @@ -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 args = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(getCommand())); + List 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); diff --git a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java index e0a29c6d3..1afa7e959 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java @@ -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> mainCommands; + private final Map> mainCommands; public CommandManager(LuckPermsPlugin plugin) { this.plugin = plugin; LocaleManager locale = plugin.getLocaleManager(); this.tabCompletions = new TabCompletions(plugin); - this.mainCommands = ImmutableList.>builder() - .add(new UserMainCommand(locale)) - .add(new GroupMainCommand(locale)) - .add(new TrackMainCommand(locale)) + this.mainCommands = ImmutableList.>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 onCommand(Sender sender, String label, List args) { - return onCommand(sender, label, args, this.executor); + public CompletableFuture executeCommand(Sender sender, String label, List args) { + return executeCommand(sender, label, args, this.executor); } - public CompletableFuture onCommand(Sender sender, String label, List args, Executor executor) { + public CompletableFuture executeCommand(Sender sender, String label, List 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 args) { - List arguments = new ArrayList<>(args); + private CommandResult execute(Sender sender, String label, List 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 groups = this.plugin.getGroupManager().getAll().values(); - if (groups.size() <= 1 && groups.stream().allMatch(g -> g.getOwnNodes(QueryOptions.nonContextual()).isEmpty())) { - Message.FIRST_TIME_SETUP.send(sender, label, sender.getName()); - } else { - Message.NO_PERMISSION_FOR_SUBCOMMANDS.send(sender); - } - return CommandResult.NO_PERMISSION; } + + Collection groups = this.plugin.getGroupManager().getAll().values(); + 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> 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 onTabComplete(Sender sender, List args) { - List arguments = new ArrayList<>(args); - + public List tabCompleteCommand(Sender sender, List arguments) { // we rewrite tab completions too! handleRewrites(arguments, false); - final List mains = this.mainCommands.stream() + final List> 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 o = 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); + 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() + .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 stripQuotes(List input) { - input = new ArrayList<>(input); - ListIterator 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; - } - } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/ChildCommand.java similarity index 93% rename from common/src/main/java/me/lucko/luckperms/common/command/abstraction/SubCommand.java rename to common/src/main/java/me/lucko/luckperms/common/command/abstraction/ChildCommand.java index 557c0e7cf..7aff2d6b6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/ChildCommand.java @@ -36,9 +36,9 @@ import java.util.function.Predicate; /** * Abstract SubCommand class */ -public abstract class SubCommand extends Command { +public abstract class ChildCommand extends Command { - public SubCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate argumentCheck) { + public ChildCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate argumentCheck) { super(spec, name, permission, argumentCheck); } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/Command.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/Command.java index 47ccd7d4d..b9859e467 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/Command.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/Command.java @@ -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 the argument type required by the command - * @param the type of any child commands */ -public abstract class Command { +public abstract class Command { /** * The commands specification. @@ -72,25 +69,11 @@ public abstract class Command { */ private final @NonNull Predicate argumentCheck; - /** - * Child commands. Nullable. - */ - private final @Nullable List> children; - - public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @Nullable CommandPermission permission, @NonNull Predicate argumentCheck, @Nullable List> children) { + public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @Nullable CommandPermission permission, @NonNull Predicate 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 argumentCheck) { - this(spec, name, permission, argumentCheck, null); - } - - public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @NonNull Predicate argumentCheck) { - this(spec, name, null, argumentCheck, null); } /** @@ -132,15 +115,6 @@ public abstract class Command { return this.argumentCheck; } - /** - * Gets the commands children - * - * @return any child commands - */ - public @NonNull Optional>> getChildren() { - return Optional.ofNullable(this.children); - } - /** * Gets the commands description. * diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/CommandException.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/CommandException.java index 263be0f16..a658e8abb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/CommandException.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/CommandException.java @@ -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); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedSubCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/GenericChildCommand.java similarity index 87% rename from common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedSubCommand.java rename to common/src/main/java/me/lucko/luckperms/common/command/abstraction/GenericChildCommand.java index 4e67e4b07..6868b83f0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedSubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/GenericChildCommand.java @@ -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 argumentCheck; - public SharedSubCommand(LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission, Predicate argumentCheck) { + public GenericChildCommand(LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission, Predicate 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() { diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/GenericParentCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/GenericParentCommand.java new file mode 100644 index 000000000..b3621b020 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/GenericParentCommand.java @@ -0,0 +1,144 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 + */ +public class GenericParentCommand extends ChildCommand { + + private final List children; + + private final HolderType type; + + public GenericParentCommand(LocalizedCommandSpec spec, String name, HolderType type, List children) { + super(spec, name, null, Predicates.alwaysFalse()); + this.children = children; + this.type = type; + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List 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 tabComplete(LuckPermsPlugin plugin, Sender sender, List 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 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 " + getName().toLowerCase(), label)); + break; + case GROUP: + Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s 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); + } + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/MainCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/MainCommand.java deleted file mode 100644 index c68e3b213..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/MainCommand.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * 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 extends Command { - - // 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 sub-command.... - private final int minArgs; - - public MainCommand(LocalizedCommandSpec spec, String name, int minArgs, List> children) { - super(spec, name, null, Predicates.alwaysFalse(), children); - this.minArgs = minArgs; - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List args, String label) { - if (args.size() < this.minArgs) { - sendUsage(sender, label); - return CommandResult.INVALID_ARGS; - } - - Optional> 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 sub = o.get(); - if (!sub.isAuthorized(sender)) { - Message.COMMAND_NO_PERMISSION.send(sender); - return CommandResult.NO_PERMISSION; - } - - List 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 tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - final List 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> 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> 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 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 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>> getChildren() { - return super.getChildren(); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/ParentCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/ParentCommand.java new file mode 100644 index 000000000..8b4045884 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/ParentCommand.java @@ -0,0 +1,208 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 extends Command { + + /** Child sub commands */ + private final List> children; + /** The type of parent command */ + private final Type type; + + public ParentCommand(LocalizedCommandSpec spec, String name, Type type, List> children) { + super(spec, name, null, Predicates.alwaysFalse()); + this.children = children; + this.type = type; + } + + public @NonNull List> getChildren() { + return this.children; + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void ignored, List 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 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 tabComplete(LuckPermsPlugin plugin, Sender sender, List 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> 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 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 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; + } + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedMainCommand.java deleted file mode 100644 index d985a1ecd..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedMainCommand.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * 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 - */ -public class SharedMainCommand extends SubCommand { - - private final List 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 secondaryCommands) { - super(spec, name, null, Predicates.alwaysFalse()); - this.secondaryCommands = secondaryCommands; - this.user = user; - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List args, String label) { - if (args.isEmpty()) { - sendUsageDetailed(sender, this.user, label); - return CommandResult.INVALID_ARGS; - } - - Optional 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 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 tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - final List 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 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 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 " + getName().toLowerCase(), label)); - } else { - Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s 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; - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java index ddfb4229a..23c981b54 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java @@ -39,10 +39,10 @@ import java.util.function.Predicate; /** * Represents a single "main" command (one without any children) */ -public abstract class SingleCommand extends Command { +public abstract class SingleCommand extends Command { public SingleCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate argumentCheck) { - super(spec, name, permission, argumentCheck, null); + super(spec, name, permission, argumentCheck); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java index 23745f331..149a1d6f6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java @@ -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 strings) { - return partial -> strings.stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList()); + return startsWith(strings::stream); } - static CompletionSupplier startsWith(Supplier> stringsSupplier) { - return partial -> stringsSupplier.get().stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList()); + static CompletionSupplier startsWith(Supplier> stringsSupplier) { + return partial -> stringsSupplier.get().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList()); } List supplyCompletions(String partial); diff --git a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java index 7acea9b13..b114c04fe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java @@ -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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java b/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java index 565af41e1..2e79eea46 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentParser.java @@ -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 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; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentTokenizer.java b/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentTokenizer.java new file mode 100644 index 000000000..ce213a7f7 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/command/utils/ArgumentTokenizer.java @@ -0,0 +1,85 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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. + * + *

Splits on whitespace, except when surrounded by quotes.

+ */ +public enum ArgumentTokenizer { + + EXECUTE { + @Override + public List tokenizeInput(String[] args) { + return stripQuotes(EXECUTE_ARGUMENT_SPLITTER.split(ARGUMENT_JOINER.join(args))); + } + + @Override + public List tokenizeInput(String args) { + return stripQuotes(EXECUTE_ARGUMENT_SPLITTER.split(args)); + } + }, + TAB_COMPLETE { + @Override + public List tokenizeInput(String[] args) { + return stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.split(ARGUMENT_JOINER.join(args))); + } + + @Override + public List 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 tokenizeInput(String[] args); + + public abstract List tokenizeInput(String args); + + private static List stripQuotes(Iterable input) { + List 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; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java b/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java index cd9ce0588..32ea2e005 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java @@ -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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java index 540fe969b..67d6e2bc2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java @@ -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 extends SharedMainCommand { - public CommandMeta(LocaleManager locale, boolean user) { - super(CommandSpec.META.localize(locale), "Meta", user, ImmutableList.builder() +public class CommandMeta extends GenericParentCommand { + public CommandMeta(LocaleManager locale, HolderType type) { + super(CommandSpec.META.localize(locale), "Meta", type, ImmutableList.builder() .add(new MetaInfo(locale)) .add(new MetaSet(locale)) .add(new MetaUnset(locale)) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java index f71bce3ff..f5477995b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java index ef7e03f50..578761353 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java index ec57555e5..66405e3cf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java @@ -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()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java index 13c8fe4e4..ee9fe408f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java index 1e2f48b42..6084651e3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java index a837aaa94..b26ecbed0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java index 1c9402512..34dd1a454 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java index 35ee172c2..83b5e3ac9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java index 0853b5e65..914129c4c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java index 438e6c006..5b785c234 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java index 8ba196cb3..c867bf60b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java index d2526cf37..c5d25f169 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java index f950551e1..a22db7e00 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java @@ -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 extends SubCommand { - 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 extends ChildCommand { + 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java index 9db6e57c5..1ff1915b4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java @@ -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 extends SubCommand { - 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 extends ChildCommand { + 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java index b1f3f57ab..0dbc4fd30 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java @@ -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 extends SubCommand { - 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 extends ChildCommand { + 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java index 2a6fe85b4..e700952b9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java @@ -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 extends SharedMainCommand { - public CommandParent(LocaleManager locale, boolean user) { - super(CommandSpec.PARENT.localize(locale), "Parent", user, ImmutableList.builder() +public class CommandParent extends GenericParentCommand { + public CommandParent(LocaleManager locale, HolderType type) { + super(CommandSpec.PARENT.localize(locale), "Parent", type, ImmutableList.builder() .add(new ParentInfo(locale)) .add(new ParentSet(locale)) .add(new ParentAdd(locale)) @@ -47,7 +48,7 @@ public class CommandParent 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()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java index ed8820930..95a5a8091 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java index 91d3bdf02..282a91ef0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java index ff4af2f88..8ce3f2d6e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java @@ -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()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java index b758e99b5..121c5268d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java index 9abeb9c13..5e6ce483d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java index 61ac02251..7b7cd7add 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java index 9da0fee38..7a7cfbd4c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java index f90821c80..74831a7ff 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java index 03dd923e0..b20d6409f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java index 60014e5f3..c80dd62c8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java index d4b478c06..e0539d725 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java @@ -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 extends SharedMainCommand { - public CommandPermission(LocaleManager locale, boolean user) { - super(CommandSpec.PERMISSION.localize(locale), "Permission", user, ImmutableList.builder() +public class CommandPermission extends GenericParentCommand { + public CommandPermission(LocaleManager locale, HolderType type) { + super(CommandSpec.PERMISSION.localize(locale), "Permission", type, ImmutableList.builder() .add(new PermissionInfo(locale)) .add(new PermissionSet(locale)) .add(new PermissionUnset(locale)) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java index 90f75b455..657a507d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java index 0ac1b21fb..a87d65ea8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java index 13e86fd1f..6ba7dbc2f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java @@ -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()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java index 773cdd252..1f1774b7e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java index a5b07c659..b817a892e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java index bcd582eb0..ed4fcb7ba 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java index efed1cdc6..279de99f8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java index ea3acd7ea..53179d4b0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java @@ -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)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java index 958e42a15..6c77e99f8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupClone.java @@ -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 { +public class GroupClone extends ChildCommand { public GroupClone(LocaleManager locale) { super(CommandSpec.GROUP_CLONE.localize(locale), "clone", CommandPermission.GROUP_CLONE, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java index 58d21b34c..4a6e17ef7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java @@ -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 { +public class GroupInfo extends ChildCommand { public GroupInfo(LocaleManager locale) { super(CommandSpec.GROUP_INFO.localize(locale), "info", CommandPermission.GROUP_INFO, Predicates.alwaysFalse()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java index db1fd6505..96130f006 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java @@ -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 { +public class GroupListMembers extends ChildCommand { public GroupListMembers(LocaleManager locale) { super(CommandSpec.GROUP_LISTMEMBERS.localize(locale), "listmembers", CommandPermission.GROUP_LIST_MEMBERS, Predicates.notInRange(0, 1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupParentCommand.java similarity index 83% rename from common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java rename to common/src/main/java/me/lucko/luckperms/common/commands/group/GroupParentCommand.java index 1a61ab2a8..852188226 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupParentCommand.java @@ -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 { +public class GroupParentCommand extends ParentCommand { // 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 { .expireAfterAccess(1, TimeUnit.HOURS) .build(key -> new ReentrantLock()); - public GroupMainCommand(LocaleManager locale) { - super(CommandSpec.GROUP.localize(locale), "Group", 2, ImmutableList.>builder() + public GroupParentCommand(LocaleManager locale) { + super(CommandSpec.GROUP.localize(locale), "Group", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.>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() diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java index 6334aa3be..fac75daf7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupRename.java @@ -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 { +public class GroupRename extends ChildCommand { public GroupRename(LocaleManager locale) { super(CommandSpec.GROUP_RENAME.localize(locale), "rename", CommandPermission.GROUP_RENAME, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java index 4a4160492..5e11296f8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java @@ -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 { +public class GroupSetDisplayName extends ChildCommand { public GroupSetDisplayName(LocaleManager locale) { super(CommandSpec.GROUP_SET_DISPLAY_NAME.localize(locale), "setdisplayname", CommandPermission.GROUP_SET_DISPLAY_NAME, Predicates.is(0)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java index 2c91ed0a9..985b9961e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetWeight.java @@ -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 { +public class GroupSetWeight extends ChildCommand { public GroupSetWeight(LocaleManager locale) { super(CommandSpec.GROUP_SETWEIGHT.localize(locale), "setweight", CommandPermission.GROUP_SET_WEIGHT, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java index d364962d0..ed9c14e92 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java @@ -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 { +public class LogGroupHistory extends ChildCommand { private static final int ENTRIES_PER_PAGE = 10; public LogGroupHistory(LocaleManager locale) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java index b0d658152..e190b2a06 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogNotify.java @@ -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 { +public class LogNotify extends ChildCommand { private static final String IGNORE_NODE = "luckperms.log.notify.ignoring"; public LogNotify(LocaleManager locale) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogParentCommand.java similarity index 59% rename from common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java rename to common/src/main/java/me/lucko/luckperms/common/commands/log/LogParentCommand.java index 4314dc2c8..24d768dbe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogParentCommand.java @@ -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 { +public class LogParentCommand extends ParentCommand { private final ReentrantLock lock = new ReentrantLock(); - public LogMainCommand(LocaleManager locale) { - super(CommandSpec.LOG.localize(locale), "Log", 1, ImmutableList.>builder() + public LogParentCommand(LocaleManager locale) { + super(CommandSpec.LOG.localize(locale), "Log", Type.NO_TARGET_ARGUMENT, ImmutableList.>builder() .add(new LogRecent(locale)) .add(new LogSearch(locale)) .add(new LogNotify(locale)) @@ -58,17 +55,12 @@ public class LogMainCommand extends MainCommand { } @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 { @Override protected List 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 tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - final List> 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()); - } - - return subs.stream() - .map(m -> m.getName().toLowerCase()) - .filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())) - .collect(Collectors.toList()); - } - - Optional> 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); + 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(); } + } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogRecent.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogRecent.java index 2cd902faf..b4f8eb449 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogRecent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogRecent.java @@ -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 { +public class LogRecent extends ChildCommand { private static final int ENTRIES_PER_PAGE = 10; public LogRecent(LocaleManager locale) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogSearch.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogSearch.java index 8f3bbcf6c..3bf48e07e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogSearch.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogSearch.java @@ -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 { +public class LogSearch extends ChildCommand { private static final int ENTRIES_PER_PAGE = 10; public LogSearch(LocaleManager locale) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java index 7ba7e63c7..16ac6aa04 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java @@ -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 { +public class LogTrackHistory extends ChildCommand { private static final int ENTRIES_PER_PAGE = 10; public LogTrackHistory(LocaleManager locale) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogUserHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogUserHistory.java index e3bf2d5e4..4e29d59ee 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogUserHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogUserHistory.java @@ -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 { +public class LogUserHistory extends ChildCommand { private static final int ENTRIES_PER_PAGE = 10; public LogUserHistory(LocaleManager locale) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationParentCommand.java similarity index 76% rename from common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java rename to common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationParentCommand.java index 546d03a52..7f70ef106 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationParentCommand.java @@ -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 { +public class MigrationParentCommand extends ParentCommand { private static final Map PLUGINS = ImmutableBiMap.builder() // bukkit .put("me.lucko.luckperms.bukkit.migration.MigrationGroupManager", "org.anjocaido.groupmanager.GroupManager") @@ -61,22 +59,22 @@ public class MigrationMainCommand extends MainCommand { .build().inverse(); private final ReentrantLock lock = new ReentrantLock(); - private List> commands = null; + private List> 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>> getChildren() { + public synchronized @NonNull List> 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(CommandSpec.MIGRATION_COMMAND.localize(getSpec().getLocaleManager()), "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) { + this.commands.add(new ChildCommand(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 args, String label) { return CommandResult.SUCCESS; @@ -84,8 +82,7 @@ public class MigrationMainCommand extends MainCommand { }); } } - - return Optional.of(this.commands); + return this.commands; } @Override @@ -100,21 +97,21 @@ public class MigrationMainCommand extends MainCommand { } @SuppressWarnings("unchecked") - private static List> getAvailableCommands(LocaleManager locale) { - List> l = new ArrayList<>(); + private static List> getAvailableCommands(LocaleManager locale) { + List> available = new ArrayList<>(); for (Map.Entry plugin : PLUGINS.entrySet()) { try { Class.forName(plugin.getKey()); - l.add((SubCommand) Class.forName(plugin.getValue()).getConstructor(LocaleManager.class).newInstance(locale)); + available.add((ChildCommand) 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 { @Override protected List 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 } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java index 1d4814091..0f9f54284 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java @@ -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 tabComplete(LuckPermsPlugin plugin, Sender sender, List 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); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java index 4e3700388..87011aacc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java @@ -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 { +public class TrackAppend extends ChildCommand { public TrackAppend(LocaleManager locale) { super(CommandSpec.TRACK_APPEND.localize(locale), "append", CommandPermission.TRACK_APPEND, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClear.java index 6a66eeb59..e9e0b781d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClear.java @@ -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 { +public class TrackClear extends ChildCommand { public TrackClear(LocaleManager locale) { super(CommandSpec.TRACK_CLEAR.localize(locale), "clear", CommandPermission.TRACK_CLEAR, Predicates.alwaysFalse()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java index a4dcf0a96..757d1b243 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackClone.java @@ -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 { +public class TrackClone extends ChildCommand { public TrackClone(LocaleManager locale) { super(CommandSpec.TRACK_CLONE.localize(locale), "clone", CommandPermission.TRACK_CLONE, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInfo.java index c89df68c8..081151234 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInfo.java @@ -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 { +public class TrackInfo extends ChildCommand { public TrackInfo(LocaleManager locale) { super(CommandSpec.TRACK_INFO.localize(locale), "info", CommandPermission.TRACK_INFO, Predicates.alwaysFalse()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java index 1f656f87d..38c70bc27 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java @@ -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 { +public class TrackInsert extends ChildCommand { public TrackInsert(LocaleManager locale) { super(CommandSpec.TRACK_INSERT.localize(locale), "insert", CommandPermission.TRACK_INSERT, Predicates.not(2)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackParentCommand.java similarity index 91% rename from common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java rename to common/src/main/java/me/lucko/luckperms/common/commands/track/TrackParentCommand.java index 2101bf970..3da3564dc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackParentCommand.java @@ -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 { +public class TrackParentCommand extends ParentCommand { // 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 { .expireAfterAccess(1, TimeUnit.HOURS) .build(key -> new ReentrantLock()); - public TrackMainCommand(LocaleManager locale) { - super(CommandSpec.TRACK.localize(locale), "Track", 2, ImmutableList.>builder() + public TrackParentCommand(LocaleManager locale) { + super(CommandSpec.TRACK.localize(locale), "Track", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.>builder() .add(new TrackInfo(locale)) .add(new TrackAppend(locale)) .add(new TrackInsert(locale)) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java index 258432113..cd012e978 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java @@ -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 { +public class TrackRemove extends ChildCommand { public TrackRemove(LocaleManager locale) { super(CommandSpec.TRACK_REMOVE.localize(locale), "remove", CommandPermission.TRACK_REMOVE, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java index cfbcb900e..372f4209e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRename.java @@ -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 { +public class TrackRename extends ChildCommand { public TrackRename(LocaleManager locale) { super(CommandSpec.TRACK_RENAME.localize(locale), "rename", CommandPermission.TRACK_RENAME, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java index 531614737..06edb94ea 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java @@ -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 { +public class UserClone extends ChildCommand { public UserClone(LocaleManager locale) { super(CommandSpec.USER_CLONE.localize(locale), "clone", CommandPermission.USER_CLONE, Predicates.not(1)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java index 30290b193..0b1f5aff4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java @@ -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 { +public class UserDemote extends ChildCommand { public UserDemote(LocaleManager locale) { super(CommandSpec.USER_DEMOTE.localize(locale), "demote", CommandPermission.USER_DEMOTE, Predicates.is(0)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java index 5b6abe9bc..34a7b3880 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java @@ -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 { +public class UserInfo extends ChildCommand { public UserInfo(LocaleManager locale) { super(CommandSpec.USER_INFO.localize(locale), "info", CommandPermission.USER_INFO, Predicates.alwaysFalse()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserParentCommand.java similarity index 88% rename from common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java rename to common/src/main/java/me/lucko/luckperms/common/commands/user/UserParentCommand.java index f3e985812..5989490a0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserParentCommand.java @@ -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 { +public class UserParentCommand extends ParentCommand { // 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 { .expireAfterAccess(1, TimeUnit.HOURS) .build(key -> new ReentrantLock()); - public UserMainCommand(LocaleManager locale) { - super(CommandSpec.USER.localize(locale), "User", 2, ImmutableList.>builder() + public UserParentCommand(LocaleManager locale) { + super(CommandSpec.USER.localize(locale), "User", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.>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() ); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java index df8186837..371160373 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java @@ -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 { +public class UserPromote extends ChildCommand { public UserPromote(LocaleManager locale) { super(CommandSpec.USER_PROMOTE.localize(locale), "promote", CommandPermission.USER_PROMOTE, Predicates.is(0)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java index ae124df2e..24ffb939c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java @@ -161,7 +161,7 @@ public abstract class ContextManager { 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(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java index 2168b54c9..1027b6a23 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java @@ -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 getUrls() { return this.urls; diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java index f695fcfe0..60d559127 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java @@ -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() + "'."); diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/PluginClassLoader.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/PluginClassLoader.java index 86bc9012a..7665b0829 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/PluginClassLoader.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/PluginClassLoader.java @@ -32,6 +32,6 @@ import java.nio.file.Path; */ public interface PluginClassLoader { - void loadJar(Path file); + void addJarToClasspath(Path file); } diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/ReflectionClassLoader.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/ReflectionClassLoader.java index 5515300ff..9d2ec2836 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/ReflectionClassLoader.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/ReflectionClassLoader.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java b/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java index e55539e91..8876763f0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java +++ b/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java @@ -137,7 +137,7 @@ public abstract class AbstractEventBus

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 diff --git a/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java b/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java index 79b07a53e..bd9cb150e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/extension/SimpleExtensionManager.java @@ -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 extensionClass; try { diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java index 7a7200781..e23176d9b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java @@ -95,10 +95,10 @@ public class LocaleManager { // might be the entries for command specifications - take care for malformed entries of differing types. if (entry.getKey().equals("command-specs") && entry.getValue() instanceof Map) { - Map commandKeys = (Map) entry.getValue(); + Map commandKeys = (Map) entry.getValue(); // key is the command id, value is a map of the commands attributes - for (Map.Entry commandKey : commandKeys.entrySet()) { + for (Map.Entry commandKey : commandKeys.entrySet()) { // just try catch, can't be bothered with safe casting every single value. try { diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java b/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java index 0e0ab1166..2be663abf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/command/CommandSpec.java @@ -633,10 +633,7 @@ public enum CommandSpec { return new LocalizedCommandSpec(this, localeManager); } - /** - * Prints this CommandSpec enum in a yml format, for reading by the {@link me.lucko.luckperms.common.locale.LocaleManager} - * @param args not needed - */ + /* public static void main(String[] args) { System.out.println("command-specs:"); @@ -660,5 +657,6 @@ public enum CommandSpec { } } } + */ } diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java b/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java index 5898048a1..c34fbfbda 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java @@ -255,7 +255,7 @@ public enum Message { LIST_TRACKS_EMPTY("&b{}&a is not on any tracks.", true), CONTEXT_PAIR_INLINE("&3{}=&b{}", false), - CONTEXT_PAIR__GLOBAL_INLINE("&eglobal", false), + CONTEXT_PAIR_GLOBAL_INLINE("&eglobal", false), CONTEXT_PAIR_SEP("&a, ", false), CONTEXT_PAIR("&8(&7{}=&f{}&8)", false), @@ -493,14 +493,14 @@ public enum Message { } private String getTranslatedMessage(@Nullable LocaleManager localeManager) { - String prefix = null; + String message = null; if (localeManager != null) { - prefix = localeManager.getTranslation(this); + message = localeManager.getTranslation(this); } - if (prefix == null) { - prefix = this.getMessage(); + if (message == null) { + message = this.getMessage(); } - return prefix; + return message; } private String format(@Nullable LocaleManager localeManager, Object... objects) { @@ -553,10 +553,7 @@ public enum Message { return new String(b); } - /** - * Prints this Message enum in a yml format, for reading by the locale manager - * @param args not needed - */ + /* public static void main(String[] args) { for (Message message : values()) { String key = message.name().replace('_', '-').toLowerCase(); @@ -575,5 +572,6 @@ public enum Message { } } } + */ } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java b/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java index f9ef9762b..d81c6bdf5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java @@ -345,6 +345,7 @@ public final class NodeMap { } private static final class ImmutableSetMultimapCache extends Cache> { + @SuppressWarnings("rawtypes") private static final Constructor IMMUTABLE_SET_MULTIMAP_CONSTRUCTOR; static { try { diff --git a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java index 58080a562..dd667e305 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java @@ -138,7 +138,7 @@ public abstract class AbstractNode, B extends NodeBui public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Node)) return false; - return Equality.KEY_VALUE_EXPIRY_CONTEXTS.equals(this, ((AbstractNode) o)); + return Equality.KEY_VALUE_EXPIRY_CONTEXTS.equals(this, ((AbstractNode) o)); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/node/model/HeldNodeImpl.java b/common/src/main/java/me/lucko/luckperms/common/node/model/HeldNodeImpl.java index 8aa393f7f..a8870c1f1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/model/HeldNodeImpl.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/model/HeldNodeImpl.java @@ -58,7 +58,7 @@ public final class HeldNodeImpl> implements HeldNode public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof HeldNodeImpl)) return false; - final HeldNodeImpl other = (HeldNodeImpl) o; + final HeldNodeImpl other = (HeldNodeImpl) o; return this.getHolder().equals(other.getHolder()) && this.getNode().equals(other.getNode()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java index 5ec15c58e..16266c8ce 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java @@ -261,7 +261,7 @@ public interface LuckPermsPlugin { */ Sender getConsoleSender(); - default List> getExtraCommands() { + default List> getExtraCommands() { return Collections.emptyList(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/sender/AbstractSender.java b/common/src/main/java/me/lucko/luckperms/common/sender/AbstractSender.java index 32d880d3a..ce58b7d65 100644 --- a/common/src/main/java/me/lucko/luckperms/common/sender/AbstractSender.java +++ b/common/src/main/java/me/lucko/luckperms/common/sender/AbstractSender.java @@ -134,7 +134,7 @@ public final class AbstractSender implements Sender { public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof AbstractSender)) return false; - final AbstractSender that = (AbstractSender) o; + final AbstractSender that = (AbstractSender) o; return this.getUniqueId().equals(that.getUniqueId()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileWatcher.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileWatcher.java index 7c0ec6638..25adc0320 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileWatcher.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileWatcher.java @@ -44,7 +44,8 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; public class FileWatcher { - private static final WatchEvent.Kind[] KINDS = new WatchEvent.Kind[]{ + @SuppressWarnings("unchecked") + private static final WatchEvent.Kind[] KINDS = new WatchEvent.Kind[]{ StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY diff --git a/common/src/main/java/me/lucko/luckperms/common/util/ImmutableCollectors.java b/common/src/main/java/me/lucko/luckperms/common/util/ImmutableCollectors.java index 99c0b6627..e685465c6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/util/ImmutableCollectors.java +++ b/common/src/main/java/me/lucko/luckperms/common/util/ImmutableCollectors.java @@ -53,13 +53,13 @@ public final class ImmutableCollectors { ImmutableSet.Builder::build ); + @SuppressWarnings({"unchecked", "rawtypes"}) public static Collector, ImmutableList> toList() { - //noinspection unchecked return (Collector) LIST; } + @SuppressWarnings({"unchecked", "rawtypes"}) public static Collector, ImmutableSet> toSet() { - //noinspection unchecked return (Collector) SET; } diff --git a/common/src/main/java/me/lucko/luckperms/common/util/Predicates.java b/common/src/main/java/me/lucko/luckperms/common/util/Predicates.java index 3129c7522..76fdb0137 100644 --- a/common/src/main/java/me/lucko/luckperms/common/util/Predicates.java +++ b/common/src/main/java/me/lucko/luckperms/common/util/Predicates.java @@ -37,6 +37,7 @@ import java.util.function.Predicate; public final class Predicates { private Predicates() {} + @SuppressWarnings("rawtypes") private static final Predicate FALSE = new Predicate() { @Override public boolean test(Object o) { return false; } @Override @@ -46,6 +47,7 @@ public final class Predicates { @Override public @NonNull Predicate negate() { return TRUE; } }; + @SuppressWarnings("rawtypes") private static final Predicate TRUE = new Predicate() { @Override public boolean test(Object o) { return true; } @Override @@ -56,13 +58,13 @@ public final class Predicates { public @NonNull Predicate negate() { return FALSE; } }; + @SuppressWarnings("unchecked") public static Predicate alwaysFalse() { - //noinspection unchecked return FALSE; } + @SuppressWarnings("unchecked") public static Predicate alwaysTrue() { - //noinspection unchecked return TRUE; } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java index 8e271f0db..53f1d0818 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitPlugin.java @@ -126,7 +126,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin { @Override protected void registerCommands() { this.commandManager = new NukkitCommandExecutor(this); - PluginCommand cmd = (PluginCommand) this.bootstrap.getServer().getPluginCommand("luckperms"); + PluginCommand cmd = (PluginCommand) this.bootstrap.getServer().getPluginCommand("luckperms"); cmd.setExecutor(this.commandManager); } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitCommandExecutor.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitCommandExecutor.java index 84e94b187..03058dbf3 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitCommandExecutor.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitCommandExecutor.java @@ -26,14 +26,14 @@ package me.lucko.luckperms.nukkit; import me.lucko.luckperms.common.command.CommandManager; +import me.lucko.luckperms.common.command.utils.ArgumentTokenizer; import me.lucko.luckperms.common.sender.Sender; import cn.nukkit.command.Command; import cn.nukkit.command.CommandExecutor; import cn.nukkit.command.CommandSender; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.List; public class NukkitCommandExecutor extends CommandManager implements CommandExecutor { private final LPNukkitPlugin plugin; @@ -45,9 +45,9 @@ public class NukkitCommandExecutor extends CommandManager implements CommandExec @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Sender lpSender = this.plugin.getSenderFactory().wrap(sender); - - onCommand(lpSender, label, new ArrayList<>(Arrays.asList(args))); + Sender wrapped = this.plugin.getSenderFactory().wrap(sender); + List arguments = ArgumentTokenizer.EXECUTE.tokenizeInput(args); + executeCommand(wrapped, label, arguments); return true; } } diff --git a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectCollectionProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectCollectionProxy.java index b9628cdab..b3133a715 100644 --- a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectCollectionProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectCollectionProxy.java @@ -68,6 +68,7 @@ public final class SubjectCollectionProxy implements SubjectCollection, ProxiedS return this.handle.hasRegistered(s).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull Iterable getAllSubjects() { // this will lazily load all subjects. it will initially just get the identifiers of each subject, and will initialize dummy @@ -80,6 +81,7 @@ public final class SubjectCollectionProxy implements SubjectCollection, ProxiedS ).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull Map getAllWithPermission(@NonNull String s) { // again, these methods will lazily load subjects. @@ -92,6 +94,7 @@ public final class SubjectCollectionProxy implements SubjectCollection, ProxiedS ).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull Map getAllWithPermission(@NonNull Set set, @NonNull String s) { return (Map) this.handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s) diff --git a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectDataProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectDataProxy.java index 67b69409c..8ab169cf9 100644 --- a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectDataProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectDataProxy.java @@ -62,6 +62,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData); } + @SuppressWarnings("rawtypes") @Override public @NonNull Map, Map> getAllPermissions() { return (Map) handle().thenApply(handle -> handle.getAllPermissions().entrySet().stream() @@ -98,6 +99,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject return true; } + @SuppressWarnings("rawtypes") @Override public @NonNull Map, List> getAllParents() { return (Map) handle().thenApply(handle -> handle.getAllParents().entrySet().stream() @@ -110,6 +112,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject )).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull List getParents(@NonNull Set contexts) { return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream() @@ -147,6 +150,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject return true; } + @SuppressWarnings("rawtypes") @Override public @NonNull Map, Map> getAllOptions() { return (Map) handle().thenApply(handle -> handle.getAllOptions().entrySet().stream() diff --git a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java index 5cbbb7bf5..b08a990eb 100644 --- a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java @@ -129,6 +129,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi )).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull List getParents() { return (List) handle().thenApply(handle -> handle.getParents(getActiveContextSet()).stream() @@ -136,6 +137,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi .collect(ImmutableCollectors.toList())).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull List getParents(@NonNull Set contexts) { return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream() diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionDescriptionProxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionDescriptionProxy.java index f9ad286b9..e9ea3fee7 100644 --- a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionDescriptionProxy.java +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionDescriptionProxy.java @@ -75,7 +75,7 @@ public final class PermissionDescriptionProxy implements PermissionDescription, } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "rawtypes"}) public @NonNull CompletableFuture> findAssignedSubjects(@NonNull String s) { return (CompletableFuture) this.handle.findAssignedSubjects(s); } diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectCollectionProxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectCollectionProxy.java index 5ed8e1af1..660be87ea 100644 --- a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectCollectionProxy.java +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectCollectionProxy.java @@ -88,6 +88,7 @@ public final class SubjectCollectionProxy implements SubjectCollection, ProxiedS return this.handle.getLoadedSubjects().stream().map(LPSubject::sponge).collect(ImmutableCollectors.toSet()); } + @SuppressWarnings("rawtypes") @Override public @NonNull CompletableFuture> getAllIdentifiers() { return (CompletableFuture) this.handle.getAllIdentifiers(); @@ -103,11 +104,13 @@ public final class SubjectCollectionProxy implements SubjectCollection, ProxiedS return this.handle.getService().getReferenceFactory().obtain(getIdentifier(), subjectIdentifier); } + @SuppressWarnings("rawtypes") @Override public @NonNull CompletableFuture> getAllWithPermission(@NonNull String s) { return (CompletableFuture) this.handle.getAllWithPermission(s); } + @SuppressWarnings("rawtypes") @Override public @NonNull CompletableFuture> getAllWithPermission(@NonNull Set set, @NonNull String s) { return (CompletableFuture) this.handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s); diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectDataProxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectDataProxy.java index 6b837bba1..588454ab9 100644 --- a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectDataProxy.java +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectDataProxy.java @@ -62,6 +62,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData); } + @SuppressWarnings("rawtypes") @Override public @NonNull Map, Map> getAllPermissions() { return (Map) handle().thenApply(handle -> handle.getAllPermissions().entrySet().stream() @@ -95,6 +96,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject return handle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts))); } + @SuppressWarnings("rawtypes") @Override public @NonNull Map, List> getAllParents() { return (Map) handle().thenApply(handle -> handle.getAllParents().entrySet().stream() @@ -104,6 +106,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject ))).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull List getParents(@NonNull Set contexts) { return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join(); @@ -129,6 +132,7 @@ public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject return handle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts))); } + @SuppressWarnings("rawtypes") @Override public @NonNull Map, Map> getAllOptions() { return (Map) handle().thenApply(handle -> handle.getAllOptions().entrySet().stream() diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java index c190d0e7f..b81138bc6 100644 --- a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java @@ -128,11 +128,13 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi return handle().thenApply(handle -> handle.isChildOf(CompatibilityUtil.convertContexts(contexts), this.service.getReferenceFactory().obtain(parent))).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull List getParents() { return (List) handle().thenApply(handle -> handle.getParents(getActiveContextSet())).join(); } + @SuppressWarnings("rawtypes") @Override public @NonNull List getParents(@NonNull Set contexts) { return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index 38697bab1..fd7b19d32 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -43,7 +43,7 @@ import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.util.MoreFiles; import me.lucko.luckperms.sponge.calculator.SpongeCalculatorFactory; -import me.lucko.luckperms.sponge.commands.SpongeMainCommand; +import me.lucko.luckperms.sponge.commands.SpongeParentCommand; import me.lucko.luckperms.sponge.context.SpongeContextManager; import me.lucko.luckperms.sponge.context.WorldCalculator; import me.lucko.luckperms.sponge.listeners.SpongeConnectionListener; @@ -280,8 +280,8 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin { } @Override - public List> getExtraCommands() { - return Collections.singletonList(new SpongeMainCommand(this)); + public List> getExtraCommands() { + return Collections.singletonList(new SpongeParentCommand(this)); } public SpongeSenderFactory getSenderFactory() { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java index b1f62a1fb..a930f3366 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java @@ -25,9 +25,8 @@ package me.lucko.luckperms.sponge; -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.checkerframework.checker.nullness.qual.NonNull; @@ -46,9 +45,6 @@ import java.util.ListIterator; import java.util.Optional; public class SpongeCommandExecutor extends CommandManager implements CommandCallable { - 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 final LPSpongePlugin plugin; public SpongeCommandExecutor(LPSpongePlugin plugin) { @@ -57,20 +53,18 @@ public class SpongeCommandExecutor extends CommandManager implements CommandCall } @Override - public @NonNull CommandResult process(@NonNull CommandSource source, @NonNull String s) { - Sender lpSender = this.plugin.getSenderFactory().wrap(source); - List arguments = processSelectors(source, CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(s))); - - onCommand(lpSender, "lp", arguments); + public @NonNull CommandResult process(@NonNull CommandSource source, @NonNull String args) { + Sender wrapped = this.plugin.getSenderFactory().wrap(source); + List arguments = processSelectors(source, ArgumentTokenizer.EXECUTE.tokenizeInput(args)); + executeCommand(wrapped, "lp", arguments); return CommandResult.success(); } @Override - public @NonNull List getSuggestions(@NonNull CommandSource source, @NonNull String s, @Nullable Location location) { - Sender lpSender = this.plugin.getSenderFactory().wrap(source); - List arguments = processSelectors(source, CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(s))); - - return onTabComplete(lpSender, arguments); + public @NonNull List getSuggestions(@NonNull CommandSource source, @NonNull String args, @Nullable Location location) { + Sender wrapped = this.plugin.getSenderFactory().wrap(source); + List arguments = processSelectors(source, ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args)); + return tabCompleteCommand(wrapped, arguments); } @Override diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java index 319b981cd..406996bd0 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.sponge.commands; 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; @@ -41,7 +41,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; -public class OptionClear extends SubCommand { +public class OptionClear extends ChildCommand { public OptionClear(LocaleManager locale) { super(CommandSpec.SPONGE_OPTION_CLEAR.localize(locale), "clear", CommandPermission.SPONGE_OPTION_CLEAR, Predicates.alwaysFalse()); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java index 0a01f5da5..bfb579d72 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java @@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands; import com.google.common.collect.ImmutableMap; 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; @@ -44,7 +44,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; import java.util.Map; -public class OptionInfo extends SubCommand { +public class OptionInfo extends ChildCommand { public OptionInfo(LocaleManager locale) { super(CommandSpec.SPONGE_OPTION_INFO.localize(locale), "info", CommandPermission.SPONGE_OPTION_INFO, Predicates.alwaysFalse()); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java index 714e982eb..57010eb3b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.sponge.commands; 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; @@ -41,7 +41,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; -public class OptionSet extends SubCommand { +public class OptionSet extends ChildCommand { public OptionSet(LocaleManager locale) { super(CommandSpec.SPONGE_OPTION_SET.localize(locale), "set", CommandPermission.SPONGE_OPTION_SET, Predicates.inRange(0, 1)); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java index d9678806b..307bab45a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.sponge.commands; 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; @@ -41,7 +41,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; -public class OptionUnset extends SubCommand { +public class OptionUnset extends ChildCommand { public OptionUnset(LocaleManager locale) { super(CommandSpec.SPONGE_OPTION_UNSET.localize(locale), "unset", CommandPermission.SPONGE_OPTION_UNSET, Predicates.is(0)); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java index 4f504913d..d2d4b8f8c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.sponge.commands; 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; @@ -46,7 +46,7 @@ import org.spongepowered.api.Sponge; import java.util.List; -public class ParentAdd extends SubCommand { +public class ParentAdd extends ChildCommand { public ParentAdd(LocaleManager locale) { super(CommandSpec.SPONGE_PARENT_ADD.localize(locale), "add", CommandPermission.SPONGE_PARENT_ADD, Predicates.inRange(0, 1)); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java index bd5420c53..ff2fef933 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.sponge.commands; 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; @@ -41,7 +41,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; -public class ParentClear extends SubCommand { +public class ParentClear extends ChildCommand { public ParentClear(LocaleManager locale) { super(CommandSpec.SPONGE_PARENT_CLEAR.localize(locale), "clear", CommandPermission.SPONGE_PARENT_CLEAR, Predicates.alwaysFalse()); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java index 4eaaf8717..3d51a7fc3 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java @@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands; import com.google.common.collect.ImmutableList; 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; @@ -45,7 +45,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; import java.util.Map; -public class ParentInfo extends SubCommand { +public class ParentInfo extends ChildCommand { public ParentInfo(LocaleManager locale) { super(CommandSpec.SPONGE_PARENT_INFO.localize(locale), "info", CommandPermission.SPONGE_PARENT_INFO, Predicates.alwaysFalse()); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java index 7bfe241ae..0ec6e1bf6 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.sponge.commands; 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; @@ -46,7 +46,7 @@ import org.spongepowered.api.Sponge; import java.util.List; -public class ParentRemove extends SubCommand { +public class ParentRemove extends ChildCommand { public ParentRemove(LocaleManager locale) { super(CommandSpec.SPONGE_PARENT_REMOVE.localize(locale), "remove", CommandPermission.SPONGE_PARENT_REMOVE, Predicates.inRange(0, 1)); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java index c0d92ec37..b48b728de 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.sponge.commands; 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; @@ -41,7 +41,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; -public class PermissionClear extends SubCommand { +public class PermissionClear extends ChildCommand { public PermissionClear(LocaleManager locale) { super(CommandSpec.SPONGE_PERMISSION_CLEAR.localize(locale), "clear", CommandPermission.SPONGE_PERMISSION_CLEAR, Predicates.alwaysFalse()); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java index eabc84d14..e1db58a5b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java @@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.commands; import com.google.common.collect.ImmutableMap; 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; @@ -44,7 +44,7 @@ import net.luckperms.api.context.ImmutableContextSet; import java.util.List; import java.util.Map; -public class PermissionInfo extends SubCommand { +public class PermissionInfo extends ChildCommand { public PermissionInfo(LocaleManager locale) { super(CommandSpec.SPONGE_PERMISSION_INFO.localize(locale), "info", CommandPermission.SPONGE_PERMISSION_INFO, Predicates.alwaysFalse()); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java index cd5d10bd0..3508bb3d3 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java @@ -26,8 +26,8 @@ package me.lucko.luckperms.sponge.commands; 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.CommandPermission; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.locale.LocaleManager; @@ -43,7 +43,7 @@ import net.luckperms.api.util.Tristate; import java.util.List; -public class PermissionSet extends SubCommand { +public class PermissionSet extends ChildCommand { public PermissionSet(LocaleManager locale) { super(CommandSpec.SPONGE_PERMISSION_SET.localize(locale), "set", CommandPermission.SPONGE_PERMISSION_SET, Predicates.inRange(0, 1)); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeParentCommand.java similarity index 80% rename from sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java rename to sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeParentCommand.java index 26924881d..f1c4e0f3a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeParentCommand.java @@ -28,8 +28,8 @@ package me.lucko.luckperms.sponge.commands; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import me.lucko.luckperms.common.command.CommandManager; 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.CommandException; import me.lucko.luckperms.common.command.utils.MessageUtils; @@ -38,7 +38,6 @@ 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 me.lucko.luckperms.common.util.ImmutableCollectors; import me.lucko.luckperms.common.util.Predicates; import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.service.LuckPermsService; @@ -46,40 +45,36 @@ import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubjectCollection; import me.lucko.luckperms.sponge.service.model.LPSubjectData; -import org.checkerframework.checker.nullness.qual.NonNull; - -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.stream.Collectors; -public class SpongeMainCommand extends Command { +public class SpongeParentCommand extends Command { private final LPSpongePlugin plugin; - private final Map>> subCommands; + private final Map>> children; - public SpongeMainCommand(LPSpongePlugin plugin) { + public SpongeParentCommand(LPSpongePlugin plugin) { super(CommandSpec.SPONGE.localize(plugin.getLocaleManager()), "Sponge", null, Predicates.alwaysFalse()); LocaleManager locale = plugin.getLocaleManager(); - this.subCommands = ImmutableMap.>>builder() - .put("permission", ImmutableList.>builder() + this.children = ImmutableMap.>>builder() + .put("permission", ImmutableList.>builder() .add(new PermissionInfo(locale)) .add(new PermissionSet(locale)) .add(new PermissionClear(locale)) .build() ) - .put("parent", ImmutableList.>builder() + .put("parent", ImmutableList.>builder() .add(new ParentInfo(locale)) .add(new ParentAdd(locale)) .add(new ParentRemove(locale)) .add(new ParentClear(locale)) .build() ) - .put("option", ImmutableList.>builder() + .put("option", ImmutableList.>builder() .add(new OptionInfo(locale)) .add(new OptionSet(locale)) .add(new OptionUnset(locale)) @@ -153,27 +148,22 @@ public class SpongeMainCommand extends Command { } String cmd = args.get(3); - Optional> o = this.subCommands.get(type).stream() + ChildCommand sub = this.children.get(type).stream() .filter(s -> s.getName().equalsIgnoreCase(cmd)) - .findAny(); + .findAny() + .orElse(null); - if (!o.isPresent()) { + if (sub == null) { sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } - final Command sub = o.get(); if (!sub.isAuthorized(sender)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } - List strippedArgs = new ArrayList<>(); - if (args.size() > 4) { - strippedArgs.addAll(args.subList(4, args.size())); - } - - if (sub.getArgumentCheck().test(strippedArgs.size())) { + if (sub.getArgumentCheck().test(args.size() - 4)) { sub.sendDetailedUsage(sender, label); return CommandResult.INVALID_ARGS; } @@ -188,9 +178,9 @@ public class SpongeMainCommand extends Command { CommandResult result; try { - result = sub.execute(plugin, sender, subjectData, strippedArgs, label); + result = sub.execute(plugin, sender, subjectData, args.subList(4, args.size()), label); } catch (CommandException e) { - result = CommandManager.handleException(e, sender, label, sub); + result = e.handle(sender, label, sub); } return result; } @@ -204,13 +194,13 @@ public class SpongeMainCommand extends Command { public void sendDetailedUsage(Sender sender, String label) { Message.BLANK.send(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s sponge [-transient]", label) + " ...)"); for (String s : Arrays.asList("Permission", "Parent", "Option")) { - List subs = this.subCommands.get(s.toLowerCase()).stream() + List> subs = this.children.get(s.toLowerCase()).stream() .filter(sub -> sub.isAuthorized(sender)) .collect(Collectors.toList()); if (!subs.isEmpty()) { Message.BLANK.send(sender, "&3>> &b" + s); - for (Command sub : subs) { + for (Command sub : subs) { sub.sendUsage(sender, label); } } @@ -219,15 +209,7 @@ public class SpongeMainCommand extends Command { @Override public boolean isAuthorized(Sender sender) { - return getSubCommands().stream().anyMatch(sc -> sc.isAuthorized(sender)); + return this.children.values().stream().flatMap(List::stream).anyMatch(sc -> sc.isAuthorized(sender)); } - public List> getSubCommands() { - return this.subCommands.values().stream().flatMap(List::stream).collect(ImmutableCollectors.toList()); - } - - @Override - public @NonNull Optional>> getChildren() { - return Optional.of(getSubCommands()); - } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/SimplePermissionDescription.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/SimplePermissionDescription.java index 231d651c3..a297af14f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/SimplePermissionDescription.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/SimplePermissionDescription.java @@ -81,7 +81,7 @@ public final class SimplePermissionDescription implements LPPermissionDescriptio return Optional.ofNullable(this.owner); } - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public CompletableFuture> findAssignedSubjects(String id) { LPSubjectCollection collection = this.service.getCollection(id); diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityBootstrap.java b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityBootstrap.java index ed5ea3f93..ffeba5fc1 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityBootstrap.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityBootstrap.java @@ -160,7 +160,7 @@ public class LPVelocityBootstrap implements LuckPermsBootstrap { return this.loadLatch; } - // getters for the injected sponge instances + // getters for the injected velocity instances public ProxyServer getProxy() { return this.proxy; diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java index 88c5ef276..3b1c11c07 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java @@ -72,7 +72,7 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin { private VelocitySenderFactory senderFactory; private VelocityConnectionListener connectionListener; - private CommandManager commandManager; + private VelocityCommandExecutor commandManager; private StandardUserManager userManager; private StandardGroupManager groupManager; private StandardTrackManager trackManager; @@ -126,8 +126,8 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin { @Override protected void registerCommands() { - this.commandManager = new CommandManager(this); - this.bootstrap.getProxy().getCommandManager().register(new VelocityCommandExecutor(this, this.commandManager), "luckpermsvelocity", "lpv", "vperm", "vperms", "vpermission", "vpermissions"); + this.commandManager = new VelocityCommandExecutor(this); + this.bootstrap.getProxy().getCommandManager().register(this.commandManager, "luckpermsvelocity", "lpv", "vperm", "vperms", "vpermission", "vpermissions"); } @Override diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java index 3ef4b6a95..620a9538d 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java @@ -37,7 +37,7 @@ public class VelocityClassLoader implements PluginClassLoader { } @Override - public void loadJar(Path file) { + public void addJarToClasspath(Path file) { this.bootstrap.getProxy().getPluginManager().addToClasspath(this.bootstrap, file); } } diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityCommandExecutor.java b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityCommandExecutor.java index 5722251ec..106805370 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityCommandExecutor.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityCommandExecutor.java @@ -25,44 +25,36 @@ package me.lucko.luckperms.velocity; -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; import com.velocitypowered.api.command.Command; import com.velocitypowered.api.command.CommandSource; import me.lucko.luckperms.common.command.CommandManager; +import me.lucko.luckperms.common.command.utils.ArgumentTokenizer; import me.lucko.luckperms.common.sender.Sender; import org.checkerframework.checker.nullness.qual.NonNull; import java.util.List; -public class VelocityCommandExecutor implements Command { - 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(' '); - +public class VelocityCommandExecutor extends CommandManager implements Command { private final LPVelocityPlugin plugin; - private final CommandManager manager; - public VelocityCommandExecutor(LPVelocityPlugin plugin, CommandManager manager) { + public VelocityCommandExecutor(LPVelocityPlugin plugin) { + super(plugin); this.plugin = plugin; - this.manager = manager; } @Override public void execute(@NonNull CommandSource source, @NonNull String[] args) { - Sender lpSender = this.plugin.getSenderFactory().wrap(source); - List arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); - - this.manager.onCommand(lpSender, "lpv", arguments); + Sender wrapped = this.plugin.getSenderFactory().wrap(source); + List arguments = ArgumentTokenizer.EXECUTE.tokenizeInput(args); + executeCommand(wrapped, "lpv", arguments); } @Override public List suggest(@NonNull CommandSource source, @NonNull String[] args) { - Sender lpSender = this.plugin.getSenderFactory().wrap(source); - List arguments = CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); - - return this.manager.onTabComplete(lpSender, arguments); + Sender wrapped = this.plugin.getSenderFactory().wrap(source); + List arguments = ArgumentTokenizer.TAB_COMPLETE.tokenizeInput(args); + return tabCompleteCommand(wrapped, arguments); } }