Make meta info command show where meta was inherited from

This commit is contained in:
Luck 2016-11-14 20:40:33 +00:00
parent d95891256b
commit b36a33f015
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 33 additions and 25 deletions

View File

@ -23,7 +23,7 @@
package me.lucko.luckperms.common.commands.generic.meta; package me.lucko.luckperms.common.commands.generic.meta;
import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
@ -44,12 +44,12 @@ public class MetaInfo extends SharedSubCommand {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) throws CommandException {
SortedSet<Map.Entry<Integer, Node>> prefixes = new TreeSet<>(Util.META_COMPARATOR.reversed()); SortedSet<Map.Entry<Integer, LocalizedNode>> prefixes = new TreeSet<>(Util.META_COMPARATOR.reversed());
SortedSet<Map.Entry<Integer, Node>> suffixes = new TreeSet<>(Util.META_COMPARATOR.reversed()); SortedSet<Map.Entry<Integer, LocalizedNode>> suffixes = new TreeSet<>(Util.META_COMPARATOR.reversed());
Set<Node> meta = new HashSet<>(); Set<LocalizedNode> meta = new HashSet<>();
// Collect data // Collect data
for (Node node : holder.getAllNodes(null, Contexts.allowAll())) { for (LocalizedNode node : holder.getAllNodes(null, Contexts.allowAll())) {
if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) { if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) {
continue; continue;
} }
@ -67,12 +67,13 @@ public class MetaInfo extends SharedSubCommand {
Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName()); Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
} else { } else {
Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName()); Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
for (Map.Entry<Integer, Node> e : prefixes) { for (Map.Entry<Integer, LocalizedNode> e : prefixes) {
String location = processLocation(e.getValue(), holder);
if (e.getValue().isServerSpecific() || e.getValue().isWorldSpecific() || !e.getValue().getContexts().isEmpty()) { if (e.getValue().isServerSpecific() || e.getValue().isWorldSpecific() || !e.getValue().getContexts().isEmpty()) {
String context = Util.getNodeContextDescription(e.getValue()); String context = Util.getNodeContextDescription(e.getValue());
Message.CHAT_META_ENTRY_WITH_CONTEXT.send(sender, e.getKey(), e.getValue().getPrefix().getValue(), context); Message.CHAT_META_ENTRY_WITH_CONTEXT.send(sender, e.getKey(), e.getValue().getPrefix().getValue(), location, context);
} else { } else {
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue().getPrefix().getValue()); Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue().getPrefix().getValue(), location);
} }
} }
} }
@ -81,12 +82,13 @@ public class MetaInfo extends SharedSubCommand {
Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName()); Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
} else { } else {
Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName()); Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
for (Map.Entry<Integer, Node> e : suffixes) { for (Map.Entry<Integer, LocalizedNode> e : suffixes) {
String location = processLocation(e.getValue(), holder);
if (e.getValue().isServerSpecific() || e.getValue().isWorldSpecific() || !e.getValue().getContexts().isEmpty()) { if (e.getValue().isServerSpecific() || e.getValue().isWorldSpecific() || !e.getValue().getContexts().isEmpty()) {
String context = Util.getNodeContextDescription(e.getValue()); String context = Util.getNodeContextDescription(e.getValue());
Message.CHAT_META_ENTRY_WITH_CONTEXT.send(sender, e.getKey(), e.getValue().getSuffix().getValue(), context); Message.CHAT_META_ENTRY_WITH_CONTEXT.send(sender, e.getKey(), e.getValue().getSuffix().getValue(), location, context);
} else { } else {
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue().getSuffix().getValue()); Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue().getSuffix().getValue(), location);
} }
} }
} }
@ -95,16 +97,21 @@ public class MetaInfo extends SharedSubCommand {
Message.META_NONE.send(sender, holder.getFriendlyName()); Message.META_NONE.send(sender, holder.getFriendlyName());
} else { } else {
Message.META_HEADER.send(sender, holder.getFriendlyName()); Message.META_HEADER.send(sender, holder.getFriendlyName());
for (Node m : meta) { for (LocalizedNode m : meta) {
String location = processLocation(m, holder);
if (m.isServerSpecific() || m.isWorldSpecific() || !m.getContexts().isEmpty()) { if (m.isServerSpecific() || m.isWorldSpecific() || !m.getContexts().isEmpty()) {
String context = Util.getNodeContextDescription(m); String context = Util.getNodeContextDescription(m);
Message.META_ENTRY_WITH_CONTEXT.send(sender, m.getMeta().getKey(), m.getMeta().getValue(), context); Message.META_ENTRY_WITH_CONTEXT.send(sender, m.getMeta().getKey(), m.getMeta().getValue(), location, context);
} else { } else {
Message.META_ENTRY.send(sender, m.getMeta().getKey(), m.getMeta().getValue()); Message.META_ENTRY.send(sender, m.getMeta().getKey(), m.getMeta().getValue(), location);
} }
} }
} }
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
private static String processLocation(LocalizedNode node, PermissionHolder holder) {
return node.getLocation().equalsIgnoreCase(holder.getObjectName()) ? "self" : node.getLocation();
}
} }

View File

@ -240,10 +240,10 @@ public class Util {
} }
public static final MetaComparator META_COMPARATOR = new MetaComparator(); public static final MetaComparator META_COMPARATOR = new MetaComparator();
public class MetaComparator implements Comparator<Map.Entry<Integer, Node>> { public class MetaComparator implements Comparator<Map.Entry<Integer, ? extends Node>> {
@Override @Override
public int compare(Map.Entry<Integer, Node> o1, Map.Entry<Integer, Node> o2) { public int compare(Map.Entry<Integer, ? extends Node> o1, Map.Entry<Integer, ? extends Node> o2) {
int result = Integer.compare(o1.getKey(), o2.getKey()); int result = Integer.compare(o1.getKey(), o2.getKey());
return result != 0 ? result : 1; return result != 0 ? result : 1;
} }

View File

@ -199,10 +199,10 @@ public enum Message {
CHAT_META_PREFIX_HEADER("&b{0}'s Prefixes", true), CHAT_META_PREFIX_HEADER("&b{0}'s Prefixes", true),
CHAT_META_SUFFIX_HEADER("&b{0}'s Suffixes", true), CHAT_META_SUFFIX_HEADER("&b{0}'s Suffixes", true),
META_HEADER("&b{0}'s Meta", true), META_HEADER("&b{0}'s Meta", true),
CHAT_META_ENTRY("&b-> {0} &f- &f\"{1}&f\"", true), CHAT_META_ENTRY("&b-> {0} &f- &f\"{1}&f\" &8(&7inherited from &a{2}&8)", true),
CHAT_META_ENTRY_WITH_CONTEXT("&b-> {0} &f- &f\"{1}&f\"{2}", true), CHAT_META_ENTRY_WITH_CONTEXT("&b-> {0} &f- &f\"{1}&f\" &8(&7inherited from &a{2}&8){3}", true),
META_ENTRY("&b-> &a{0} &f= &f\"{1}&f\"", true), META_ENTRY("&b-> &a{0} &f= &f\"{1}&f\" &8(&7inherited from &a{2}&8)", true),
META_ENTRY_WITH_CONTEXT("&b-> &a{0} &f= &f\"{1}&f\"{2}", true), META_ENTRY_WITH_CONTEXT("&b-> &a{0} &f= &f\"{1}&f\" &8(&7inherited from &a{2}&8){3}", true),
CHAT_META_PREFIX_NONE("&b{0} has no prefixes.", true), CHAT_META_PREFIX_NONE("&b{0} has no prefixes.", true),
CHAT_META_SUFFIX_NONE("&b{0} has no suffixes.", true), CHAT_META_SUFFIX_NONE("&b{0} has no suffixes.", true),
META_NONE("&b{0} has no meta.", true), META_NONE("&b{0} has no meta.", true),

View File

@ -154,10 +154,10 @@ past-date-error: "You cannot set a date in the past!"
chat-meta-prefix-header: "&b{0}'s Prefixes" chat-meta-prefix-header: "&b{0}'s Prefixes"
chat-meta-suffix-header: "&b{0}'s Suffixes" chat-meta-suffix-header: "&b{0}'s Suffixes"
meta-header: "&b{0}'s Meta" meta-header: "&b{0}'s Meta"
chat-meta-entry: "&b-> {0} &f- &f\"{1}&f\"" chat-meta-entry: "&b-> {0} &f- &f\"{1}&f\" &8(&7inherited from &a{2}&8)"
chat-meta-entry-with-context: "&b-> {0} &f- &f\"{1}&f\"{2}" chat-meta-entry-with-context: "&b-> {0} &f- &f\"{1}&f\" &8(&7inherited from &a{2}&8){3}"
meta-entry: "&b-> &a{0} &f= &f\"{1}&f\"" meta-entry: "&b-> &a{0} &f= &f\"{1}&f\" &8(&7inherited from &a{2}&8)"
meta-entry-with-context: "&b-> &a{0} &f= &f\"{1}&f\"{2}" meta-entry-with-context: "&b-> &a{0} &f= &f\"{1}&f\" &8(&7inherited from &a{2}&8){3}"
chat-meta-prefix-none: "&b{0} has no prefixes." chat-meta-prefix-none: "&b{0} has no prefixes."
chat-meta-suffix-none: "&b{0} has no suffixes." chat-meta-suffix-none: "&b{0} has no suffixes."
meta-none: "&b{0} has no meta." meta-none: "&b{0} has no meta."

View File

@ -120,9 +120,10 @@ public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
int overflow = extra.size(); int overflow = extra.size();
extra.clear(); extra.clear();
Util.sendPluginMessage(sender, "&aCurrent Subjects:\n" + Util.listToCommaSep(subjects) + "&b ... and &a" + overflow + " &bmore."); Util.sendPluginMessage(sender, "&aCurrent Subjects:\n" + Util.listToCommaSep(subjects) + "&b ... and &a" + overflow + " &bmore.");
} else {
Util.sendPluginMessage(sender, "&aCurrent Subjects:\n" + Util.listToCommaSep(subjects));
} }
Util.sendPluginMessage(sender, "&aCurrent Subjects:\n" + Util.listToCommaSep(subjects));
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }