Search in sources :

Example 6 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class PermissionInfo method makeFancy.

private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> " + (node.getValuePrimitive() ? "¥a" : "¥c") + node.getPermission(), " ", "¥7Click to remove this node from " + holder.getFriendlyName()), '¥'));
    String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
    ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
    return component -> {
        component.hoverEvent(hoverEvent);
        component.clickEvent(clickEvent);
    };
}
Also used : NodeWithContextComparator(me.lucko.luckperms.common.node.NodeWithContextComparator) TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) HoverEvent(net.kyori.text.event.HoverEvent) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) DateUtil(me.lucko.luckperms.common.utils.DateUtil) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ClickEvent(net.kyori.text.event.ClickEvent) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) SharedSubCommand(me.lucko.luckperms.common.command.abstraction.SharedSubCommand) CollationKeyCache(me.lucko.luckperms.common.utils.CollationKeyCache) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) CommandManager(me.lucko.luckperms.common.command.CommandManager) SortType(me.lucko.luckperms.common.command.utils.SortType) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) Iterators(me.lucko.luckperms.common.utils.Iterators) TextComponent(net.kyori.text.TextComponent) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) SortMode(me.lucko.luckperms.common.command.utils.SortMode) BuildableComponent(net.kyori.text.BuildableComponent) Node(me.lucko.luckperms.api.Node) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Comparator(java.util.Comparator) Collections(java.util.Collections) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Example 7 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class ParentInfo method makeFancy.

private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> &f" + node.getGroupName(), " ", "&7Click to remove this parent from " + holder.getFriendlyName()), CommandManager.AMPERSAND_CHAR));
    String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
    ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
    return component -> {
        component.hoverEvent(hoverEvent);
        component.clickEvent(clickEvent);
    };
}
Also used : NodeWithContextComparator(me.lucko.luckperms.common.node.NodeWithContextComparator) TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) HoverEvent(net.kyori.text.event.HoverEvent) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) DateUtil(me.lucko.luckperms.common.utils.DateUtil) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ClickEvent(net.kyori.text.event.ClickEvent) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) SharedSubCommand(me.lucko.luckperms.common.command.abstraction.SharedSubCommand) CollationKeyCache(me.lucko.luckperms.common.utils.CollationKeyCache) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) CommandManager(me.lucko.luckperms.common.command.CommandManager) SortType(me.lucko.luckperms.common.command.utils.SortType) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) Iterators(me.lucko.luckperms.common.utils.Iterators) TextComponent(net.kyori.text.TextComponent) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) SortMode(me.lucko.luckperms.common.command.utils.SortMode) BuildableComponent(net.kyori.text.BuildableComponent) Node(me.lucko.luckperms.api.Node) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Comparator(java.util.Comparator) Collections(java.util.Collections) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Example 8 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class AssignmentExpression method parse.

public boolean parse(PermissionHolder holder, Tristate tristate) throws IllegalArgumentException {
    ScriptEngine engine = Scripting.getScriptEngine();
    if (engine == null) {
        throw new NullPointerException("script engine");
    }
    Predicate<Node> checker = node -> holder.hasPermission(node, StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY) == tristate;
    String exp = this.expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining()).replace("&", "&&").replace("|", "||");
    try {
        String result = engine.eval(exp).toString();
        if (!result.equals("true") && !result.equals("false")) {
            throw new IllegalArgumentException();
        }
        return Boolean.parseBoolean(result);
    } catch (Throwable t) {
        throw new IllegalArgumentException(exp, t);
    }
}
Also used : LegacyNodeFactory(me.lucko.luckperms.common.node.LegacyNodeFactory) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Scripting(me.lucko.luckperms.common.utils.Scripting) Predicate(java.util.function.Predicate) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Tristate(me.lucko.luckperms.api.Tristate) ScriptEngine(javax.script.ScriptEngine) Node(me.lucko.luckperms.api.Node) Collectors(java.util.stream.Collectors) StandardNodeEquality(me.lucko.luckperms.api.StandardNodeEquality) Node(me.lucko.luckperms.api.Node) ScriptEngine(javax.script.ScriptEngine)

Example 9 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class EditorCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    Type type = Type.ALL;
    // parse type
    String typeString = ArgumentParser.parseStringOrElse(0, args, null);
    if (typeString != null) {
        try {
            type = Type.valueOf(typeString.toUpperCase());
        } catch (IllegalArgumentException e) {
        // ignored
        }
    }
    // collect holders
    List<PermissionHolder> holders = new ArrayList<>();
    if (type.includingGroups) {
        plugin.getGroupManager().getAll().values().stream().sorted((o1, o2) -> {
            int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
            return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
        }).forEach(holders::add);
    }
    if (type.includingUsers) {
        plugin.getUserManager().getAll().values().stream().sorted((o1, o2) -> o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName())).forEach(holders::add);
    }
    // remove holders which the sender doesn't have perms to view
    holders.removeIf(holder -> ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder));
    // they don't have perms to view any of them
    if (holders.isEmpty()) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Message.EDITOR_START.send(sender);
    // form the payload data
    JsonObject payload = WebEditor.formPayload(holders, sender, label, plugin);
    // upload the payload data to gist
    String pasteId = StandardPastebin.BYTEBIN.postJson(payload, true).id();
    if (pasteId == null) {
        Message.EDITOR_UPLOAD_FAILURE.send(sender);
        return CommandResult.STATE_ERROR;
    }
    // form a url for the editor
    String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "?" + pasteId;
    Message.EDITOR_URL.send(sender);
    Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : JsonObject(com.google.gson.JsonObject) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) Sender(me.lucko.luckperms.common.sender.Sender) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) CommandResult(me.lucko.luckperms.common.command.CommandResult) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) TextColor(net.kyori.text.format.TextColor) List(java.util.List) Component(net.kyori.text.Component) ClickEvent(net.kyori.text.event.ClickEvent) Message(me.lucko.luckperms.common.locale.message.Message) WebEditor(me.lucko.luckperms.common.web.WebEditor) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component)

Example 10 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class VaultChatHook method setChatMeta.

private void setChatMeta(PermissionHolder holder, ChatMetaType type, String value, String world) {
    if (log()) {
        logMsg("#setChatMeta: %s - %s - %s - %s", holder.getFriendlyName(), type, value, world);
    }
    this.permissionHook.getExecutor().execute(() -> {
        // remove all prefixes/suffixes directly set on the user/group
        holder.removeIf(type::matches);
        if (value == null) {
            this.permissionHook.holderSave(holder);
            return;
        }
        // find the max inherited priority & add 10
        MetaAccumulator metaAccumulator = holder.accumulateMeta(null, createContextForWorldSet(world));
        int priority = (type == ChatMetaType.PREFIX ? metaAccumulator.getPrefixes() : metaAccumulator.getSuffixes()).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10;
        Node.Builder chatMetaNode = NodeFactory.buildChatMetaNode(type, priority, value);
        chatMetaNode.setServer(this.permissionHook.getVaultServer());
        chatMetaNode.setWorld(world);
        holder.setPermission(chatMetaNode.build());
        this.permissionHook.holderSave(holder);
    });
}
Also used : CommandManager(me.lucko.luckperms.common.command.CommandManager) Contexts(me.lucko.luckperms.api.Contexts) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) UUID(java.util.UUID) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) Objects(java.util.Objects) Strings(com.google.common.base.Strings) LPBukkitPlugin(me.lucko.luckperms.bukkit.LPBukkitPlugin) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) Chat(net.milkbowl.vault.chat.Chat) User(me.lucko.luckperms.common.model.User) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) Node(me.lucko.luckperms.api.Node)

Aggregations

PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)10 List (java.util.List)6 Node (me.lucko.luckperms.api.Node)5 CommandManager (me.lucko.luckperms.common.command.CommandManager)5 CommandResult (me.lucko.luckperms.common.command.CommandResult)5 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)5 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)5 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)5 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)5 Message (me.lucko.luckperms.common.locale.message.Message)5 Group (me.lucko.luckperms.common.model.Group)5 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)5 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)5 Sender (me.lucko.luckperms.common.sender.Sender)5 Predicates (me.lucko.luckperms.common.utils.Predicates)5 TextComponent (net.kyori.text.TextComponent)5 ClickEvent (net.kyori.text.event.ClickEvent)5 HoverEvent (net.kyori.text.event.HoverEvent)5 Comparator (java.util.Comparator)4 Consumer (java.util.function.Consumer)4