Remove console only commands - closes #137
This commit is contained in:
@@ -35,4 +35,8 @@ public abstract class BaseCommand<T, S> extends Command<T, S> {
|
||||
|
||||
public abstract String getUsage();
|
||||
|
||||
public boolean shouldDisplay() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -214,6 +214,10 @@ public class CommandManager {
|
||||
mainCommands.stream()
|
||||
.filter(c -> c.isAuthorized(sender))
|
||||
.forEach(c -> {
|
||||
if (!c.shouldDisplay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
String permission = (String) c.getPermission().map(p -> ((Permission) p).getExample()).orElse("None");
|
||||
FancyMessage msg = new FancyMessage("> ").color(ChatColor.getByChar('3')).then().text(String.format(c.getUsage(), label)).color(ChatColor.getByChar('a'))
|
||||
|
||||
@@ -149,12 +149,6 @@ public abstract class MainCommand<T> extends BaseCommand<Void, T> {
|
||||
|
||||
@Override
|
||||
public void sendUsage(Sender sender, String label) {
|
||||
/*
|
||||
if (getSubCommands().isEmpty()) {
|
||||
Util.sendPluginMessage(sender, "&3> &a" + String.format(getUsage(), label));
|
||||
return;
|
||||
*/
|
||||
|
||||
List<Command> subs = getSubCommands().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
+18
-10
@@ -29,8 +29,8 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.MainCommand;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.constants.Constants;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -95,6 +95,7 @@ public class MigrationMainCommand extends MainCommand<Object> {
|
||||
}
|
||||
|
||||
private List<Command<Object, ?>> commands = null;
|
||||
private boolean display = true;
|
||||
|
||||
public MigrationMainCommand() {
|
||||
super("Migration", "Migration commands", "/%s migration", 1, null);
|
||||
@@ -106,6 +107,17 @@ public class MigrationMainCommand extends MainCommand<Object> {
|
||||
public synchronized Optional<List<Command<Object, ?>>> getChildren() {
|
||||
if (commands == null) {
|
||||
commands = getAvailableCommands();
|
||||
|
||||
// Add dummy command to show in the list.
|
||||
if (commands.isEmpty()) {
|
||||
display = false;
|
||||
commands.add(new SubCommand<Object>("No available plugins to migrate from", "No available plugins to migrate from.", Permission.MIGRATION, Predicates.alwaysFalse(), null) {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.of(commands);
|
||||
@@ -118,17 +130,13 @@ public class MigrationMainCommand extends MainCommand<Object> {
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return sender.getUuid().equals(Constants.CONSOLE_UUID);
|
||||
return sender.hasPermission(Permission.MIGRATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) throws CommandException {
|
||||
if (!sender.getUuid().equals(Constants.CONSOLE_UUID)) {
|
||||
Message.MIGRATION_NOT_CONSOLE.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
return super.execute(plugin, sender, v, args, label);
|
||||
public boolean shouldDisplay() {
|
||||
getSubCommands();
|
||||
return display;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,14 +22,12 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.misc;
|
||||
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SingleCommand;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.constants.Constants;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
@@ -46,6 +44,7 @@ import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ExportCommand extends SingleCommand {
|
||||
private static void write(BufferedWriter writer, String s) {
|
||||
@@ -102,7 +101,7 @@ public class ExportCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
public ExportCommand() {
|
||||
super("Export", "Export data to a file", "/%s export <file>", Permission.MIGRATION, Predicates.not(1),
|
||||
super("Export", "Export data to a file", "/%s export <file>", Permission.EXPORT, Predicates.not(1),
|
||||
Arg.list(
|
||||
Arg.create("file", true, "the file to export to")
|
||||
)
|
||||
@@ -111,12 +110,7 @@ public class ExportCommand extends SingleCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
final Logger log = plugin.getLog();
|
||||
|
||||
if (!sender.getUuid().equals(Constants.CONSOLE_UUID)) {
|
||||
Message.MIGRATION_NOT_CONSOLE.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
Consumer<String> log = s -> Message.EXPORT_LOG.send(sender, s);
|
||||
|
||||
File f = new File(plugin.getMainDir(), args.get(0));
|
||||
if (f.exists()) {
|
||||
@@ -138,10 +132,10 @@ public class ExportCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
try (FileWriter fWriter = new FileWriter(f, true); BufferedWriter writer = new BufferedWriter(fWriter)) {
|
||||
log.info("Export: Starting export process.");
|
||||
log.accept("Starting export process.");
|
||||
|
||||
// Export Groups
|
||||
log.info("Export: Exporting all groups.");
|
||||
log.accept("Exporting all groups.");
|
||||
|
||||
// Create the groups first
|
||||
for (Group group : plugin.getGroupManager().getAll().values()) {
|
||||
@@ -155,10 +149,10 @@ public class ExportCommand extends SingleCommand {
|
||||
write(writer, nodeToString(node, group.getName(), true));
|
||||
}
|
||||
}
|
||||
log.info("Export: Exported " + groupCount + " groups.");
|
||||
log.accept("Exported " + groupCount + " groups.");
|
||||
|
||||
// Export tracks
|
||||
log.info("Export: Exporting all tracks.");
|
||||
log.accept("Exporting all tracks.");
|
||||
|
||||
// Create the tracks first
|
||||
for (Track track : plugin.getTrackManager().getAll().values()) {
|
||||
@@ -172,13 +166,13 @@ public class ExportCommand extends SingleCommand {
|
||||
write(writer, "/luckperms track " + track.getName() + " append " + group);
|
||||
}
|
||||
}
|
||||
log.info("Export: Exported " + trackCount + " tracks.");
|
||||
log.accept("Exported " + trackCount + " tracks.");
|
||||
|
||||
// Export users
|
||||
log.info("Export: Exporting all users. Finding a list of unique users to export.");
|
||||
log.accept("Exporting all users. Finding a list of unique users to export.");
|
||||
Storage ds = plugin.getStorage();
|
||||
Set<UUID> users = ds.getUniqueUsers().join();
|
||||
log.info("Export: Found " + users.size() + " unique users to export.");
|
||||
log.accept("Found " + users.size() + " unique users to export.");
|
||||
|
||||
int userCount = 0;
|
||||
for (UUID uuid : users) {
|
||||
@@ -206,7 +200,7 @@ public class ExportCommand extends SingleCommand {
|
||||
|
||||
plugin.getUserManager().cleanup(user);
|
||||
}
|
||||
log.info("Export: Exported " + userCount + " users.");
|
||||
log.accept("Exported " + userCount + " users.");
|
||||
|
||||
try {
|
||||
writer.flush();
|
||||
@@ -222,9 +216,4 @@ public class ExportCommand extends SingleCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return sender.getUuid().equals(Constants.CONSOLE_UUID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ public enum Message {
|
||||
OP_DISABLED("&bThe vanilla OP system is disabled on this server.", false),
|
||||
OP_DISABLED_SPONGE("&2Server Operator status has no effect when a permission plugin is installed. Please edit user data directly.", true),
|
||||
LOG("&3LOG &3&l> {0}", true),
|
||||
EXPORT_LOG("&3EXPORT &3&l> &f{0}", true),
|
||||
MIGRATION_LOG("&3MIGRATION &3&l> &f{0}", true),
|
||||
|
||||
COMMAND_NOT_RECOGNISED("Command not recognised.", true),
|
||||
COMMAND_NO_PERMISSION("You do not have permission to use this command!", true),
|
||||
@@ -413,9 +415,7 @@ public enum Message {
|
||||
),
|
||||
|
||||
IMPORT_END_ERROR_CONTENT("&b(Import) &b-> &c{0}", true),
|
||||
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true),
|
||||
|
||||
MIGRATION_NOT_CONSOLE("Migration must be performed from the Console.", true);
|
||||
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true);
|
||||
|
||||
private static String format(String s, Object... objects) {
|
||||
for (int i = 0, objsLength = objects.length; i < objsLength; i++) {
|
||||
|
||||
@@ -40,6 +40,8 @@ public enum Permission {
|
||||
SEARCH(list("search"), Type.NONE),
|
||||
VERBOSE(list("verbose"), Type.NONE),
|
||||
IMPORT(list("import"), Type.NONE),
|
||||
EXPORT(list("export"), Type.NONE),
|
||||
MIGRATION(list("migration"), Type.NONE),
|
||||
|
||||
CREATE_GROUP(list("creategroup"), Type.NONE),
|
||||
DELETE_GROUP(list("deletegroup"), Type.NONE),
|
||||
@@ -148,9 +150,7 @@ public enum Permission {
|
||||
SPONGE_OPTION_INFO(list("option.info"), Type.SPONGE),
|
||||
SPONGE_OPTION_SET(list("option.set"), Type.SPONGE),
|
||||
SPONGE_OPTION_UNSET(list("option.unset"), Type.SPONGE),
|
||||
SPONGE_OPTION_CLEAR(list("option.clear"), Type.SPONGE),
|
||||
|
||||
MIGRATION(list("migration"), Type.NONE);
|
||||
SPONGE_OPTION_CLEAR(list("option.clear"), Type.SPONGE);
|
||||
|
||||
private static final String IDENTIFIER = "luckperms.";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user