mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-13 11:41:22 +01:00
Add tab completion
This commit is contained in:
parent
874a90253b
commit
d33a3ffcea
@ -5,19 +5,32 @@ import me.lucko.luckperms.commands.Sender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class CommandManagerBukkit extends CommandManager implements CommandExecutor {
|
||||
class CommandManagerBukkit extends CommandManager implements CommandExecutor, TabExecutor {
|
||||
CommandManagerBukkit(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
|
||||
return onCommand(new Sender() {
|
||||
return onCommand(makeSender(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return onTabComplete(makeSender(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
private static Sender makeSender(CommandSender sender) {
|
||||
return new Sender() {
|
||||
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final CommandSender c = cs.get();
|
||||
@ -31,6 +44,6 @@ class CommandManagerBukkit extends CommandManager implements CommandExecutor {
|
||||
final CommandSender c = cs.get();
|
||||
return c != null && c.hasPermission(node);
|
||||
}
|
||||
}, Arrays.asList(args));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,15 @@ import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.vaulthooks.VaultHook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
@ -45,6 +48,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
CommandManagerBukkit commandManager = new CommandManagerBukkit(this);
|
||||
PluginCommand main = getServer().getPluginCommand("luckperms");
|
||||
main.setExecutor(commandManager);
|
||||
main.setTabCompleter(commandManager);
|
||||
main.setAliases(Arrays.asList("perms", "lp", "permissions", "p", "perm"));
|
||||
|
||||
final String storageMethod = configuration.getStorageMethod();
|
||||
@ -123,6 +127,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
return getServer().getOnlinePlayers().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayerList() {
|
||||
return getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new UpdateTask(this));
|
||||
|
@ -13,10 +13,13 @@ import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.BungeeUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
@ -88,6 +91,11 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
return getProxy().getOnlineCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayerList() {
|
||||
return getProxy().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
doAsync(new UpdateTask(this));
|
||||
|
@ -5,11 +5,12 @@ import me.lucko.luckperms.commands.Sender;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
|
||||
class MainCommand extends Command {
|
||||
class MainCommand extends Command implements TabExecutor {
|
||||
private final CommandManager manager;
|
||||
|
||||
public MainCommand(CommandManager manager) {
|
||||
@ -20,8 +21,18 @@ class MainCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
|
||||
manager.onCommand(new Sender() {
|
||||
manager.onCommand(makeSender(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return manager.onTabComplete(makeSender(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
private static Sender makeSender(CommandSender sender) {
|
||||
return new Sender() {
|
||||
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final CommandSender c = cs.get();
|
||||
@ -35,6 +46,6 @@ class MainCommand extends Command {
|
||||
final CommandSender c = cs.get();
|
||||
return c != null && c.hasPermission(node);
|
||||
}
|
||||
}, Arrays.asList(args));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -65,6 +66,12 @@ public interface LuckPermsPlugin {
|
||||
*/
|
||||
int getPlayerCount();
|
||||
|
||||
/**
|
||||
* Gets the usernames of the users online on the platform
|
||||
* @return a {@link List} of usernames
|
||||
*/
|
||||
List<String> getPlayerList();
|
||||
|
||||
/**
|
||||
* Runs an update task
|
||||
*/
|
||||
|
@ -20,9 +20,11 @@ import me.lucko.luckperms.commands.user.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
@ -123,6 +125,31 @@ public class CommandManager {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public List<String> onTabComplete(Sender sender, List<String> args) {
|
||||
final List<MainCommand> mains = mainCommands.stream().filter(m -> m.canUse(sender)).collect(Collectors.toList());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return mains.stream().map(MainCommand::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return mains.stream().map(MainCommand::getName).map(String::toLowerCase).filter(s -> s.startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<MainCommand> o = mains.stream().filter(m -> m.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny();
|
||||
if (!o.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return o.get().onTabComplete(sender, args.subList(1, args.size()), plugin);
|
||||
}
|
||||
|
||||
private void registerMainCommand(MainCommand command) {
|
||||
plugin.getLogger().log(Level.INFO, "[CommandManager] Registered main command '" + command.getName() + "'");
|
||||
mainCommands.add(command);
|
||||
|
@ -5,7 +5,9 @@ import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@ -17,6 +19,7 @@ public abstract class MainCommand {
|
||||
private final int requiredArgsLength;
|
||||
|
||||
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, List<String> args);
|
||||
protected abstract List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin);
|
||||
public abstract List<? extends SubCommand> getSubCommands();
|
||||
|
||||
protected void sendUsage(Sender sender) {
|
||||
@ -41,4 +44,23 @@ public abstract class MainCommand {
|
||||
protected boolean canUse(Sender sender) {
|
||||
return getSubCommands().stream().filter(sc -> sc.isAuthorized(sender)).count() != 0;
|
||||
}
|
||||
|
||||
protected List<String> onAbstractTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<SubCommand> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
|
||||
if (args.size() == 2) {
|
||||
if (args.get(1).equalsIgnoreCase("")) {
|
||||
return subs.stream().map(SubCommand::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return subs.stream().map(SubCommand::getName).map(String::toLowerCase)
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<SubCommand> o = subs.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
|
||||
if (!o.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return o.get().onTabComplete(sender, args.subList(2, args.size()), plugin);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,15 @@ package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public abstract class SubCommand {
|
||||
@ -12,6 +19,34 @@ public abstract class SubCommand {
|
||||
private final String usage;
|
||||
private final Permission permission;
|
||||
|
||||
protected static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()), args);
|
||||
}
|
||||
|
||||
protected static List<String> getTrackTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getTrackManager().getTracks().keySet()), args);
|
||||
}
|
||||
|
||||
private static List<String> getTabComplete(List<String> options, List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return options;
|
||||
}
|
||||
|
||||
return options.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected static List<String> getBoolTabComplete(List<String> args) {
|
||||
if (args.size() == 2) {
|
||||
return Arrays.asList("true", "false");
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return permission.isAuthorized(sender);
|
||||
}
|
||||
@ -20,5 +55,9 @@ public abstract class SubCommand {
|
||||
Util.sendPluginMessage(sender, "&e-> &d" + getUsage());
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public abstract boolean isArgLengthInvalid(int argLength);
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ public class Util {
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
public static boolean startsWithIgnoreCase(String s, String startsWith) {
|
||||
return s.toLowerCase().startsWith(startsWith);
|
||||
}
|
||||
|
||||
public static void sendBoolean(Sender sender, String node, boolean b) {
|
||||
if (b) {
|
||||
sender.sendMessage(Util.color("&b" + node + ": &atrue"));
|
||||
|
@ -8,7 +8,7 @@ import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CreateGroupCommand extends MainCommand {
|
||||
@ -51,9 +51,14 @@ public class CreateGroupCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,9 @@ import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeleteGroupCommand extends MainCommand {
|
||||
public DeleteGroupCommand() {
|
||||
@ -52,9 +54,24 @@ public class DeleteGroupCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> groups = new ArrayList<>(plugin.getGroupManager().getGroups().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return groups;
|
||||
}
|
||||
|
||||
return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import me.lucko.luckperms.groups.Group;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupMainCommand extends MainCommand {
|
||||
|
||||
@ -66,6 +67,21 @@ public class GroupMainCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> groups = new ArrayList<>(plugin.getGroupManager().getGroups().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return groups;
|
||||
}
|
||||
|
||||
return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return onAbstractTabComplete(sender, args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
|
@ -9,6 +9,7 @@ import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ListGroupsCommand extends MainCommand {
|
||||
@ -27,9 +28,14 @@ public class ListGroupsCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,6 +42,11 @@ public class GroupSetInheritCommand extends GroupSubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1 && argLength != 2;
|
||||
|
@ -55,6 +55,11 @@ public class GroupSetPermissionCommand extends GroupSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 2 && argLength != 3;
|
||||
|
@ -36,6 +36,11 @@ public class GroupUnsetInheritCommand extends GroupSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1 && argLength != 2;
|
||||
|
@ -7,7 +7,7 @@ import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DebugCommand extends MainCommand {
|
||||
@ -22,9 +22,14 @@ public class DebugCommand extends MainCommand {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,7 @@ import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class InfoCommand extends MainCommand {
|
||||
@ -20,9 +20,14 @@ public class InfoCommand extends MainCommand {
|
||||
Message.INFO.send(sender, plugin.getVersion(), plugin.getDatastore().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,7 @@ import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SyncCommand extends MainCommand {
|
||||
@ -21,9 +21,14 @@ public class SyncCommand extends MainCommand {
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,7 +8,7 @@ import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CreateTrackCommand extends MainCommand {
|
||||
@ -51,9 +51,14 @@ public class CreateTrackCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,9 @@ import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeleteTrackCommand extends MainCommand {
|
||||
public DeleteTrackCommand() {
|
||||
@ -47,9 +49,24 @@ public class DeleteTrackCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> tracks = new ArrayList<>(plugin.getTrackManager().getTracks().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
return tracks.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,6 +9,7 @@ import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ListTracksCommand extends MainCommand {
|
||||
@ -27,9 +28,14 @@ public class ListTracksCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import me.lucko.luckperms.tracks.Track;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TrackMainCommand extends MainCommand {
|
||||
|
||||
@ -66,6 +67,21 @@ public class TrackMainCommand extends MainCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> tracks = new ArrayList<>(plugin.getTrackManager().getTracks().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
return tracks.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return onAbstractTabComplete(sender, args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
|
@ -43,6 +43,11 @@ public class TrackAppendCommand extends TrackSubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1;
|
||||
|
@ -53,6 +53,11 @@ public class TrackInsertCommand extends TrackSubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 2;
|
||||
|
@ -27,6 +27,11 @@ public class TrackRemoveCommand extends TrackSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1;
|
||||
|
@ -12,8 +12,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserMainCommand extends MainCommand{
|
||||
public class UserMainCommand extends MainCommand {
|
||||
|
||||
private final List<UserSubCommand> subCommands = new ArrayList<>();
|
||||
|
||||
@ -75,6 +76,21 @@ public class UserMainCommand extends MainCommand{
|
||||
Message.USER_INVALID_ENTRY.send(sender, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> onlinePlayers = plugin.getPlayerList();
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return onlinePlayers;
|
||||
}
|
||||
|
||||
return onlinePlayers.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return onAbstractTabComplete(sender, args, plugin);
|
||||
}
|
||||
|
||||
private void runSub(LuckPermsPlugin plugin, Sender sender, UUID uuid, UserSubCommand command, List<String> strippedArgs) {
|
||||
plugin.getDatastore().loadUser(uuid, success -> {
|
||||
if (!success) {
|
||||
|
@ -48,6 +48,11 @@ public class UserAddGroupCommand extends UserSubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return (argLength != 1 && argLength != 2);
|
||||
|
@ -79,6 +79,11 @@ public class UserDemoteCommand extends UserSubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1;
|
||||
|
@ -79,6 +79,11 @@ public class UserPromoteCommand extends UserSubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1;
|
||||
|
@ -41,6 +41,11 @@ public class UserRemoveGroupCommand extends UserSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return (argLength != 1 && argLength != 2);
|
||||
|
@ -55,6 +55,11 @@ public class UserSetPermissionCommand extends UserSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 2 && argLength != 3;
|
||||
|
@ -40,6 +40,11 @@ public class UserSetPrimaryGroupCommand extends UserSubCommand {
|
||||
saveUser(user, sender, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1;
|
||||
|
@ -45,6 +45,11 @@ public class UserShowPosCommand extends UserSubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength != 1;
|
||||
|
@ -29,7 +29,7 @@ public enum Message {
|
||||
USER_NOT_FOUND("&eUser could not be found.", true),
|
||||
USER_SAVE_SUCCESS("&7(User data was saved to the datastore)", true),
|
||||
USER_SAVE_ERROR("There was an error whilst saving the user.", true),
|
||||
USER_ATTEMPTING_LOOKUP("&7(Attempting UUID lookup, since you specified a user)", true),
|
||||
USER_ATTEMPTING_LOOKUP("&7(Attempting UUID lookup, since you specified a username)", true),
|
||||
|
||||
GROUP_NOT_FOUND("&eGroup could not be found.", true),
|
||||
GROUP_SAVE_SUCCESS("&7(Group data was saved to the datastore)", true),
|
||||
|
Loading…
Reference in New Issue
Block a user