mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Make meta info command show where meta was inherited from
This commit is contained in:
parent
d95891256b
commit
b36a33f015
@ -23,7 +23,7 @@
|
||||
package me.lucko.luckperms.common.commands.generic.meta;
|
||||
|
||||
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.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
@ -44,12 +44,12 @@ public class MetaInfo extends SharedSubCommand {
|
||||
|
||||
@Override
|
||||
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, Node>> suffixes = new TreeSet<>(Util.META_COMPARATOR.reversed());
|
||||
Set<Node> meta = new HashSet<>();
|
||||
SortedSet<Map.Entry<Integer, LocalizedNode>> prefixes = new TreeSet<>(Util.META_COMPARATOR.reversed());
|
||||
SortedSet<Map.Entry<Integer, LocalizedNode>> suffixes = new TreeSet<>(Util.META_COMPARATOR.reversed());
|
||||
Set<LocalizedNode> meta = new HashSet<>();
|
||||
|
||||
// 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()) {
|
||||
continue;
|
||||
}
|
||||
@ -67,12 +67,13 @@ public class MetaInfo extends SharedSubCommand {
|
||||
Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
|
||||
} else {
|
||||
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()) {
|
||||
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 {
|
||||
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());
|
||||
} else {
|
||||
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()) {
|
||||
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 {
|
||||
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());
|
||||
} else {
|
||||
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()) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
private static String processLocation(LocalizedNode node, PermissionHolder holder) {
|
||||
return node.getLocation().equalsIgnoreCase(holder.getObjectName()) ? "self" : node.getLocation();
|
||||
}
|
||||
}
|
||||
|
@ -240,10 +240,10 @@ public class Util {
|
||||
}
|
||||
|
||||
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
|
||||
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());
|
||||
return result != 0 ? result : 1;
|
||||
}
|
||||
|
@ -199,10 +199,10 @@ public enum Message {
|
||||
CHAT_META_PREFIX_HEADER("&b{0}'s Prefixes", true),
|
||||
CHAT_META_SUFFIX_HEADER("&b{0}'s Suffixes", true),
|
||||
META_HEADER("&b{0}'s Meta", true),
|
||||
CHAT_META_ENTRY("&b-> {0} &f- &f\"{1}&f\"", true),
|
||||
CHAT_META_ENTRY_WITH_CONTEXT("&b-> {0} &f- &f\"{1}&f\"{2}", true),
|
||||
META_ENTRY("&b-> &a{0} &f= &f\"{1}&f\"", true),
|
||||
META_ENTRY_WITH_CONTEXT("&b-> &a{0} &f= &f\"{1}&f\"{2}", 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\" &8(&7inherited from &a{2}&8){3}", 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\" &8(&7inherited from &a{2}&8){3}", true),
|
||||
CHAT_META_PREFIX_NONE("&b{0} has no prefixes.", true),
|
||||
CHAT_META_SUFFIX_NONE("&b{0} has no suffixes.", true),
|
||||
META_NONE("&b{0} has no meta.", true),
|
||||
|
@ -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-suffix-header: "&b{0}'s Suffixes"
|
||||
meta-header: "&b{0}'s Meta"
|
||||
chat-meta-entry: "&b-> {0} &f- &f\"{1}&f\""
|
||||
chat-meta-entry-with-context: "&b-> {0} &f- &f\"{1}&f\"{2}"
|
||||
meta-entry: "&b-> &a{0} &f= &f\"{1}&f\""
|
||||
meta-entry-with-context: "&b-> &a{0} &f= &f\"{1}&f\"{2}"
|
||||
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\" &8(&7inherited from &a{2}&8){3}"
|
||||
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\" &8(&7inherited from &a{2}&8){3}"
|
||||
chat-meta-prefix-none: "&b{0} has no prefixes."
|
||||
chat-meta-suffix-none: "&b{0} has no suffixes."
|
||||
meta-none: "&b{0} has no meta."
|
||||
|
@ -120,9 +120,10 @@ public class SpongeMainCommand extends BaseCommand<Void, SubjectData> {
|
||||
int overflow = extra.size();
|
||||
extra.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user