Add contextual data section to group info command too

This commit is contained in:
Luck 2020-05-12 18:34:07 +01:00
parent 86eeeb5b94
commit 98eb756951
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 52 additions and 5 deletions

View File

@ -25,6 +25,9 @@
package me.lucko.luckperms.common.commands.group;
import com.google.common.collect.Maps;
import me.lucko.luckperms.common.cacheddata.type.MetaCache;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
@ -38,11 +41,15 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.query.QueryOptions;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class GroupInfo extends ChildCommand<Group> {
@ -87,6 +94,40 @@ public class GroupInfo extends ChildCommand<Group> {
Message.INFO_PARENT_ENTRY_EXPIRY.send(sender, DurationFormatter.LONG.format(node.getExpiryDuration()));
}
}
QueryOptions queryOptions = plugin.getContextManager().getStaticQueryOptions();
String context = "&bNone";
String prefix = "&bNone";
String suffix = "&bNone";
String meta = "&bNone";
ContextSet contextSet = queryOptions.context();
if (!contextSet.isEmpty()) {
context = contextSet.toSet().stream()
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
.collect(Collectors.joining(" "));
}
MetaCache data = group.getCachedData().getMetaData(queryOptions);
String prefixValue = data.getPrefix(MetaCheckEvent.Origin.INTERNAL);
if (prefixValue != null) {
prefix = "&f\"" + prefixValue + "&f\"";
}
String sussexValue = data.getSuffix(MetaCheckEvent.Origin.INTERNAL);
if (sussexValue != null) {
suffix = "&f\"" + sussexValue + "&f\"";
}
Map<String, List<String>> metaMap = data.getMeta(MetaCheckEvent.Origin.INTERNAL);
if (!metaMap.isEmpty()) {
meta = metaMap.entrySet().stream()
.flatMap(entry -> entry.getValue().stream().map(value -> Maps.immutableEntry(entry.getKey(), value)))
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
.collect(Collectors.joining(" "));
}
Message.GROUP_INFO_CONTEXTUAL_DATA.send(sender, context, prefix, suffix, meta);
return CommandResult.SUCCESS;
}
}

View File

@ -136,7 +136,7 @@ public class UserInfo extends ChildCommand<User> {
.collect(Collectors.joining(" "));
}
Message.USER_INFO_DATA.send(sender, active ? "&2active player" : "&8server", context, prefix, suffix, primaryGroup, meta);
Message.USER_INFO_CONTEXTUAL_DATA.send(sender, active ? "&2active player" : "&8server", context, prefix, suffix, primaryGroup, meta);
return CommandResult.SUCCESS;
}
}

View File

@ -360,10 +360,8 @@ public enum Message {
"{PREFIX}&f- &3Status: {}",
false
),
USER_INFO_DATA(
"{PREFIX}&f- &aContextual Data:" + "\n" +
"{PREFIX} &3Type: {}" + "\n" +
USER_INFO_CONTEXTUAL_DATA(
"{PREFIX}&f- &aContextual Data: &7(mode: {}&7)" + "\n" +
"{PREFIX} &3Contexts: {}" + "\n" +
"{PREFIX} &3Prefix: {}" + "\n" +
"{PREFIX} &3Suffix: {}" + "\n" +
@ -408,6 +406,14 @@ public enum Message {
"{PREFIX}&f- &3Weight: &f{}",
false
),
GROUP_INFO_CONTEXTUAL_DATA(
"{PREFIX}&f- &aContextual Data: &7(mode: &8server&7)" + "\n" +
"{PREFIX} &3Prefix: {}" + "\n" +
"{PREFIX} &3Suffix: {}" + "\n" +
"{PREFIX} &3Meta: {}",
false
),
GROUP_SET_WEIGHT("&aSet weight to &b{}&a for group &b{}&a.", true),
GROUP_SET_DISPLAY_NAME_DOESNT_HAVE("&b{}&a doesn't have a display name set.", true),