Allow multiple verbose filters

This commit is contained in:
Luck 2016-11-05 19:01:06 +00:00
parent f72819a664
commit 2dd0858960
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 36 additions and 12 deletions

View File

@ -29,11 +29,13 @@ import me.lucko.luckperms.common.commands.SingleMainCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class VerboseCommand extends SingleMainCommand {
public VerboseCommand() {
super("Verbose", "/%s verbose <true|false> [query]", 1, Permission.VERBOSE);
super("Verbose", "/%s verbose <true|false> [filters]", 1, Permission.VERBOSE);
}
@Override
@ -54,10 +56,15 @@ public class VerboseCommand extends SingleMainCommand {
return CommandResult.SUCCESS;
}
String query = args.size() == 1 ? "" : args.get(1);
plugin.getDebugHandler().register(sender, query);
if (!query.equals("")) {
Message.VERBOSE_ON_QUERY.send(sender, query);
List<String> filters = new ArrayList<>();
if (args.size() != 1) {
filters.addAll(args.subList(1, args.size() + 1));
}
plugin.getDebugHandler().register(sender, filters);
if (!filters.isEmpty()) {
Message.VERBOSE_ON_QUERY.send(sender, filters.stream().collect(Collectors.joining("&7, &f")));
} else {
Message.VERBOSE_ON.send(sender);
}

View File

@ -85,7 +85,7 @@ public enum Message {
* Commands
*/
VERBOSE_ON("&bVerbose checking output set to &aTRUE &bfor all permissions.", true),
VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions starting with &f\"{0}\"&b.", true),
VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}", true),
VERBOSE_OFF("&bVerbose checking output set to &cFALSE&b.", true),
CREATE_SUCCESS("&b{0}&a was successfully created.", true),

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.utils;
import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@ -29,23 +30,39 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.constants.Message;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class DebugHandler {
private final Map<Reciever, String> listeners = new ConcurrentHashMap<>();
private final Map<Reciever, List<String>> listeners = new ConcurrentHashMap<>();
public void printOutput(String checked, String node, Tristate value) {
for (Map.Entry<Reciever, String> e : listeners.entrySet()) {
if (node.toLowerCase().startsWith(e.getValue().toLowerCase())) {
Message.LOG.send(e.getKey().getSender(), "&7Checking &a" + checked + "&7 for: &a" + node + " &f(&7" + value.toString() + "&f)");
for (Map.Entry<Reciever, List<String>> e : listeners.entrySet()) {
List<String> filters = e.getValue();
find:
if (!filters.isEmpty()) {
for (String filter : filters) {
if (node.toLowerCase().startsWith(filter.toLowerCase())) {
break find;
}
if (checked.equalsIgnoreCase(filter)) {
break find;
}
}
continue;
}
Message.LOG.send(e.getKey().getSender(), "&7Checking &a" + checked + "&7 for: &a" + node + " &f(&7" + value.toString() + "&f)");
}
}
public void register(Sender sender, String s) {
listeners.put(new Reciever(sender.getUuid(), sender), s);
public void register(Sender sender, List<String> filters) {
listeners.put(new Reciever(sender.getUuid(), sender), ImmutableList.copyOf(filters));
}
public void unregister(UUID uuid) {