Search in sources :

Example 1 with MetaData

use of me.lucko.luckperms.api.caching.MetaData in project LuckPerms by lucko.

the class HolderSubject method getOption.

@Override
public Optional<String> getOption(ImmutableContextSet contexts, String s) {
    MetaData data = this.parent.getCachedData().getMetaData(this.plugin.getContextManager().formContexts(contexts));
    if (s.equalsIgnoreCase(NodeFactory.PREFIX_KEY)) {
        if (data.getPrefix() != null) {
            return Optional.of(data.getPrefix());
        }
    }
    if (s.equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
        if (data.getSuffix() != null) {
            return Optional.of(data.getSuffix());
        }
    }
    String val = data.getMeta().get(s);
    if (val != null) {
        return Optional.of(val);
    }
    Optional<String> v = getParentCollection().getDefaults().getOption(contexts, s);
    if (v.isPresent()) {
        return v;
    }
    return this.plugin.getService().getRootDefaults().getOption(contexts, s);
}
Also used : MetaData(me.lucko.luckperms.api.caching.MetaData)

Example 2 with MetaData

use of me.lucko.luckperms.api.caching.MetaData in project LuckPerms by lucko.

the class UserInfo method execute.

@SuppressWarnings("unchecked")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Message status = plugin.getBootstrap().isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
    Message.USER_INFO_GENERAL.send(sender, user.getName().orElse("Unknown"), user.getUuid(), user.getUuid().version() == 4 ? "&2mojang" : "&8offline", status.asString(plugin.getLocaleManager()), user.getPrimaryGroup().getValue());
    Set<Node> parents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isPermanent).collect(Collectors.toSet());
    Set<Node> tempParents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isTemporary).collect(Collectors.toSet());
    if (!parents.isEmpty()) {
        Message.INFO_PARENT_HEADER.send(sender);
        for (Node node : parents) {
            Message.EMPTY.send(sender, "&f-    &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
        }
    }
    if (!tempParents.isEmpty()) {
        Message.INFO_TEMP_PARENT_HEADER.send(sender);
        for (Node node : tempParents) {
            Message.EMPTY.send(sender, "&f-    &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
            Message.EMPTY.send(sender, "&f-    &2-    expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()));
        }
    }
    String context = "&bNone";
    String prefix = "&bNone";
    String suffix = "&bNone";
    String meta = "&bNone";
    Contexts contexts = plugin.getContextForUser(user).orElse(null);
    if (contexts != null) {
        ContextSet contextSet = contexts.getContexts();
        if (!contextSet.isEmpty()) {
            context = contextSet.toSet().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
        }
        MetaData data = user.getCachedData().getMetaData(contexts);
        if (data.getPrefix() != null) {
            prefix = "&f\"" + data.getPrefix() + "&f\"";
        }
        if (data.getSuffix() != null) {
            suffix = "&f\"" + data.getSuffix() + "&f\"";
        }
        ListMultimap<String, String> metaMap = data.getMetaMultimap();
        if (!metaMap.isEmpty()) {
            meta = metaMap.entries().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
        }
    }
    Message.USER_INFO_DATA.send(sender, MessageUtils.formatBoolean(contexts != null), context, prefix, suffix, meta);
    return CommandResult.SUCCESS;
}
Also used : ContextSet(me.lucko.luckperms.api.context.ContextSet) Message(me.lucko.luckperms.common.locale.message.Message) MetaData(me.lucko.luckperms.api.caching.MetaData) Node(me.lucko.luckperms.api.Node) Contexts(me.lucko.luckperms.api.Contexts)

Aggregations

MetaData (me.lucko.luckperms.api.caching.MetaData)2 Contexts (me.lucko.luckperms.api.Contexts)1 Node (me.lucko.luckperms.api.Node)1 ContextSet (me.lucko.luckperms.api.context.ContextSet)1 Message (me.lucko.luckperms.common.locale.message.Message)1