Add some missing tab completions, remove /lp log export command

This commit is contained in:
Luck 2017-06-09 22:17:37 +01:00
parent 5c5d1e8d0a
commit b4a2da0ea8
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
16 changed files with 86 additions and 171 deletions

View File

@ -197,9 +197,12 @@ public class CommandManager {
@SuppressWarnings("unchecked")
public List<String> onTabComplete(Sender sender, List<String> args) {
List<String> arguments = new ArrayList<>(args);
// we rewrite tab completions too!
handleRewrites(arguments);
final List<Command> mains = mainCommands.stream()
.filter(Command::shouldDisplay)
.filter(m -> m.isAuthorized(sender))
.collect(Collectors.toList());
@ -239,12 +242,9 @@ public class CommandManager {
private void sendCommandUsage(Sender sender, String label) {
Util.sendPluginMessage(sender, "&2Running &bLuckPerms v" + plugin.getVersion() + "&2.");
mainCommands.stream()
.filter(Command::shouldDisplay)
.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(c('3')).then().text(String.format(c.getUsage(), label)).color(c('a'))

View File

@ -159,7 +159,7 @@ public abstract class SubCommand<T> extends Command<T, Void> {
return Collections.emptyList();
}
private static List<String> getTabComplete(List<String> options, List<String> args) {
public static List<String> getTabComplete(List<String> options, List<String> args) {
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return options;

View File

@ -46,6 +46,8 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getTrackTabComplete;
public class ParentClearTrack extends SharedSubCommand {
public ParentClearTrack() {
super("cleartrack", "Clears all parents on a given track", Permission.USER_PARENT_CLEAR_TRACK, Permission.GROUP_PARENT_CLEAR_TRACK, Predicates.is(0),
@ -108,4 +110,9 @@ public class ParentClearTrack extends SharedSubCommand {
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getTrackTabComplete(args, plugin);
}
}

View File

@ -46,6 +46,7 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getGroupTabComplete;
import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getTrackTabComplete;
public class ParentSetTrack extends SharedSubCommand {
@ -129,6 +130,11 @@ public class ParentSetTrack extends SharedSubCommand {
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getTrackTabComplete(args, plugin);
if (args.size() == 0 || args.size() == 1) {
return getTrackTabComplete(args, plugin);
}
args.remove(0);
return getGroupTabComplete(args, plugin);
}
}

View File

@ -45,6 +45,8 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getPermissionTabComplete;
public class PermissionUnset extends SharedSubCommand {
public PermissionUnset() {
super("unset", "Unsets a permission for the object", Permission.USER_PERM_UNSET, Permission.GROUP_PERM_UNSET,
@ -84,4 +86,9 @@ public class PermissionUnset extends SharedSubCommand {
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionVault());
}
}

View File

@ -45,6 +45,8 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.stream.Collectors;
import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getPermissionTabComplete;
public class PermissionUnsetTemp extends SharedSubCommand {
public PermissionUnsetTemp() {
super("unsettemp", "Unsets a temporary permission for the object", Permission.USER_PERM_UNSETTEMP,
@ -77,4 +79,9 @@ public class PermissionUnsetTemp extends SharedSubCommand {
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionVault());
}
}

View File

@ -29,6 +29,7 @@ import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.constants.Message;
@ -90,17 +91,6 @@ public class DeleteGroup extends SingleCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
final List<String> groups = new ArrayList<>(plugin.getGroupManager().getAll().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();
return SubCommand.getGroupTabComplete(args, plugin);
}
}

View File

@ -29,7 +29,6 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.commands.abstraction.Command;
import me.lucko.luckperms.common.commands.abstraction.MainCommand;
import me.lucko.luckperms.common.commands.impl.log.subcommands.LogExport;
import me.lucko.luckperms.common.commands.impl.log.subcommands.LogGroupHistory;
import me.lucko.luckperms.common.commands.impl.log.subcommands.LogNotify;
import me.lucko.luckperms.common.commands.impl.log.subcommands.LogRecent;
@ -52,7 +51,6 @@ public class LogMainCommand extends MainCommand<Log> {
.add(new LogRecent())
.add(new LogSearch())
.add(new LogNotify())
.add(new LogExport())
.add(new LogUserHistory())
.add(new LogGroupHistory())
.add(new LogTrackHistory())

View File

@ -1,135 +0,0 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.impl.log.subcommands;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.data.Log;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
public class LogExport extends SubCommand<Log> {
public LogExport() {
super("export", "Export the log to a file", Permission.LOG_EXPORT, Predicates.not(1),
Arg.list(Arg.create("file", true, "the name of the file"))
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
File f = new File(plugin.getDataDirectory(), args.get(0));
if (f.exists()) {
Message.LOG_EXPORT_ALREADY_EXISTS.send(sender, f.getAbsolutePath());
return CommandResult.INVALID_ARGS;
}
if (log.getContent().isEmpty()) {
Message.LOG_EXPORT_EMPTY.send(sender);
return CommandResult.STATE_ERROR;
}
try {
f.createNewFile();
} catch (IOException e) {
Message.LOG_EXPORT_FAILURE.send(sender);
e.printStackTrace();
return CommandResult.FAILURE;
}
if (!Files.isWritable(f.toPath())) {
Message.LOG_EXPORT_NOT_WRITABLE.send(sender, f.getAbsolutePath());
return CommandResult.FAILURE;
}
List<String> data = new ArrayList<>();
StringBuilder b = new StringBuilder();
for (LogEntry e : log.getContent()) {
b.setLength(0);
b.append("/luckperms ");
if (e.getType() == 'U') {
b.append("user ").append(e.getActed().toString()).append(" ").append(e.getAction());
}
group:
if (e.getType() == 'G') {
if (e.getAction().equalsIgnoreCase("create")) {
b.append("creategroup ").append(e.getActedName());
break group;
}
if (e.getAction().equalsIgnoreCase("delete")) {
b.append("deletegroup ").append(e.getActedName());
break group;
}
b.append("group ").append(e.getActedName()).append(" ").append(e.getAction());
}
track:
if (e.getType() == 'T') {
if (e.getAction().equalsIgnoreCase("create")) {
b.append("createtrack ").append(e.getActedName());
break track;
}
if (e.getAction().equalsIgnoreCase("delete")) {
b.append("deletetrack ").append(e.getActedName());
break track;
}
b.append("track ").append(e.getActedName()).append(" ").append(e.getAction());
}
data.add(b.toString());
}
try {
Files.write(f.toPath(), data, Charset.defaultCharset());
Message.LOG_EXPORT_SUCCESS.send(sender, f.getAbsolutePath());
return CommandResult.SUCCESS;
} catch (IOException e) {
e.printStackTrace();
Message.LOG_EXPORT_FAILURE.send(sender);
return CommandResult.FAILURE;
}
}
}

View File

@ -98,4 +98,9 @@ public class LogGroupHistory extends SubCommand<Log> {
return CommandResult.SUCCESS;
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
}
}

View File

@ -98,4 +98,9 @@ public class LogTrackHistory extends SubCommand<Log> {
return CommandResult.SUCCESS;
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getTrackTabComplete(args, plugin);
}
}

View File

@ -30,6 +30,7 @@ import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Message;
@ -40,6 +41,7 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class CheckCommand extends SingleCommand {
public CheckCommand() {
@ -74,4 +76,18 @@ public class CheckCommand extends SingleCommand {
Message.CHECK_RESULT.send(sender, user.getFriendlyName(), permission, Util.formatTristate(tristate));
return CommandResult.SUCCESS;
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.isEmpty()) {
return plugin.getPlayerList();
}
if (args.size() == 1) {
return plugin.getPlayerList().stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
args.remove(0);
return SubCommand.getPermissionTabComplete(args, plugin.getPermissionVault());
}
}

View File

@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util;
@ -112,6 +113,11 @@ public class SearchCommand extends SingleCommand {
return CommandResult.SUCCESS;
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return SubCommand.getPermissionTabComplete(args, plugin.getPermissionVault());
}
private static Map.Entry<FancyMessage, String> searchUserResultToMessage(List<HeldPermission<UUID>> results, Function<UUID, String> uuidLookup, String label, int pageNumber) {
if (results.isEmpty()) {
return Maps.immutableEntry(new FancyMessage("None").color(ChatColor.getByChar('3')), null);

View File

@ -25,6 +25,8 @@
package me.lucko.luckperms.common.commands.impl.misc;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
@ -39,8 +41,10 @@ import io.github.mkremins.fanciful.ChatColor;
import io.github.mkremins.fanciful.FancyMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class VerboseCommand extends SingleCommand {
public VerboseCommand() {
@ -123,4 +127,17 @@ public class VerboseCommand extends SingleCommand {
sendUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.isEmpty()) {
return ImmutableList.of("on", "record", "off", "paste");
}
if (args.size() == 1) {
return Stream.of("on", "record", "off", "paste").filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
return Collections.emptyList();
}
}

View File

@ -29,6 +29,7 @@ import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
@ -38,9 +39,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class DeleteTrack extends SingleCommand {
public DeleteTrack() {
@ -83,18 +82,6 @@ public class DeleteTrack extends SingleCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
final List<String> tracks = new ArrayList<>(plugin.getTrackManager().getAll().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();
return SubCommand.getTrackTabComplete(args, plugin);
}
}

View File

@ -150,7 +150,6 @@ public enum Permission {
LOG_TRACK_HISTORY(list("trackhistory"), Type.LOG),
LOG_SEARCH(list("search"), Type.LOG),
LOG_NOTIFY(list("notify"), Type.LOG),
LOG_EXPORT(list("export"), Type.LOG),
SPONGE_PERMISSION_INFO(list("permission.info"), Type.SPONGE),
SPONGE_PERMISSION_SET(list("permission.set"), Type.SPONGE),