From b36a33f0158abbf6838d960fc2bbe2b52a461064 Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 14 Nov 2016 20:40:33 +0000 Subject: [PATCH] Make meta info command show where meta was inherited from --- .../commands/generic/meta/MetaInfo.java | 35 +++++++++++-------- .../luckperms/common/commands/utils/Util.java | 4 +-- .../luckperms/common/constants/Message.java | 8 ++--- default-lang.yml | 8 ++--- .../sponge/commands/SpongeMainCommand.java | 3 +- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java index 012faab4..5b360de1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java @@ -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 args) throws CommandException { - SortedSet> prefixes = new TreeSet<>(Util.META_COMPARATOR.reversed()); - SortedSet> suffixes = new TreeSet<>(Util.META_COMPARATOR.reversed()); - Set meta = new HashSet<>(); + SortedSet> prefixes = new TreeSet<>(Util.META_COMPARATOR.reversed()); + SortedSet> suffixes = new TreeSet<>(Util.META_COMPARATOR.reversed()); + Set 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 e : prefixes) { + for (Map.Entry 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 e : suffixes) { + for (Map.Entry 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(); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java index f593edcd..b5b1fef7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java @@ -240,10 +240,10 @@ public class Util { } public static final MetaComparator META_COMPARATOR = new MetaComparator(); - public class MetaComparator implements Comparator> { + public class MetaComparator implements Comparator> { @Override - public int compare(Map.Entry o1, Map.Entry o2) { + public int compare(Map.Entry o1, Map.Entry o2) { int result = Integer.compare(o1.getKey(), o2.getKey()); return result != 0 ? result : 1; } diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index 65da2b98..f32b1d49 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -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), diff --git a/default-lang.yml b/default-lang.yml index 315594f0..71729490 100644 --- a/default-lang.yml +++ b/default-lang.yml @@ -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." diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java index 0c0f6145..26b643ba 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java @@ -120,9 +120,10 @@ public class SpongeMainCommand extends BaseCommand { 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; }