Search in sources :

Example 16 with MutableContextSet

use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class MetaUnsetTemp method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    String key = args.get(0);
    MutableContextSet context = args.getContextOrDefault(1, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
        Message.UNSET_META_TEMP_SUCCESS.send(sender, key, target, context);
        LoggedAction.build().source(sender).target(target).description("meta", "unsettemp", key, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.DOESNT_HAVE_TEMP_META.send(sender, target, key, context);
    }
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) NodeType(net.luckperms.api.node.NodeType) Sender(me.lucko.luckperms.common.sender.Sender) TabCompletions(me.lucko.luckperms.common.command.tabcomplete.TabCompletions) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) Message(me.lucko.luckperms.common.locale.Message) GenericChildCommand(me.lucko.luckperms.common.command.abstraction.GenericChildCommand) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) MutableContextSet(net.luckperms.api.context.MutableContextSet) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) DataType(net.luckperms.api.model.data.DataType) MutableContextSet(net.luckperms.api.context.MutableContextSet)

Example 17 with MutableContextSet

use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class SqlStorage method writeNode.

private static void writeNode(Node node, PreparedStatement ps) throws SQLException {
    MutableContextSet contexts = node.getContexts().mutableCopy();
    String server = getFirstContextValue(contexts, DefaultContextKeys.SERVER_KEY);
    String world = getFirstContextValue(contexts, DefaultContextKeys.WORLD_KEY);
    long expiry = node.hasExpiry() ? node.getExpiry().getEpochSecond() : 0L;
    ps.setString(2, node.getKey());
    ps.setBoolean(3, node.getValue());
    ps.setString(4, server);
    ps.setString(5, world);
    ps.setLong(6, expiry);
    ps.setString(7, GsonProvider.normal().toJson(ContextSetJsonSerializer.serialize(contexts)));
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet)

Example 18 with MutableContextSet

use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class LuckPermsVaultPermission method getQueryOptions.

// utility method for getting a contexts instance for a given vault lookup.
QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) {
    ContextSet context;
    Player player = Optional.ofNullable(uuid).flatMap(u -> this.plugin.getBootstrap().getPlayer(u)).orElse(null);
    if (player != null) {
        context = this.plugin.getContextManager().getContext(player);
    } else {
        context = this.plugin.getContextManager().getStaticContext();
    }
    String playerWorld = player == null ? null : player.getWorld().getName();
    // if world is not null, we want to do a lookup in that specific world
    if (world != null && !world.isEmpty() && !world.equalsIgnoreCase(playerWorld)) {
        MutableContextSet mutContext = context.mutableCopy();
        context = mutContext;
        // remove already accumulated worlds
        mutContext.removeAll(DefaultContextKeys.WORLD_KEY);
        // add the vault world
        mutContext.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase(Locale.ROOT));
    }
    // if we're using a special vault server
    if (useVaultServer()) {
        MutableContextSet mutContext = context instanceof MutableContextSet ? (MutableContextSet) context : context.mutableCopy();
        context = mutContext;
        // remove the normal server context from the set
        mutContext.remove(DefaultContextKeys.SERVER_KEY, getServer());
        // add the vault specific server
        if (!getVaultServer().equals("global")) {
            mutContext.add(DefaultContextKeys.SERVER_KEY, getVaultServer());
        }
    }
    boolean op = false;
    if (player != null) {
        op = player.isOp();
    } else if (uuid != null && UniqueIdType.determineType(uuid, this.plugin).getType().equals("npc")) {
        op = this.plugin.getConfiguration().get(ConfigKeys.VAULT_NPC_OP_STATUS);
    }
    QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder();
    builder.context(context);
    builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, isIncludeGlobal());
    if (op) {
        builder.option(BukkitContextManager.OP_OPTION, true);
    }
    return builder.build();
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) ContextSet(net.luckperms.api.context.ContextSet) CheckOrigin(me.lucko.luckperms.common.verbose.event.CheckOrigin) QueryOptions(net.luckperms.api.query.QueryOptions) DefaultContextKeys(net.luckperms.api.context.DefaultContextKeys) Flag(net.luckperms.api.query.Flag) NodeType(net.luckperms.api.node.NodeType) PermissionCache(me.lucko.luckperms.common.cacheddata.type.PermissionCache) Player(org.bukkit.entity.Player) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) BukkitContextManager(me.lucko.luckperms.bukkit.context.BukkitContextManager) MonitoredMetaCache(me.lucko.luckperms.common.cacheddata.type.MonitoredMetaCache) MutableContextSet(net.luckperms.api.context.MutableContextSet) Locale(java.util.Locale) Node(net.luckperms.api.node.Node) HolderType(me.lucko.luckperms.common.model.HolderType) Nullable(org.checkerframework.checker.nullness.qual.Nullable) QueryOptionsImpl(me.lucko.luckperms.common.query.QueryOptionsImpl) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Uuids(me.lucko.luckperms.common.util.Uuids) DirectProcessor(me.lucko.luckperms.common.calculator.processor.DirectProcessor) GroupManager(me.lucko.luckperms.common.model.manager.group.GroupManager) UUID(java.util.UUID) Objects(java.util.Objects) LPBukkitPlugin(me.lucko.luckperms.bukkit.LPBukkitPlugin) NodeBuilders(me.lucko.luckperms.common.node.factory.NodeBuilders) Group(me.lucko.luckperms.common.model.Group) ContextSet(net.luckperms.api.context.ContextSet) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Inheritance(me.lucko.luckperms.common.node.types.Inheritance) User(me.lucko.luckperms.common.model.User) UniqueIdType(me.lucko.luckperms.common.util.UniqueIdType) DataType(net.luckperms.api.model.data.DataType) Permission(net.milkbowl.vault.permission.Permission) Player(org.bukkit.entity.Player) MutableContextSet(net.luckperms.api.context.MutableContextSet) QueryOptions(net.luckperms.api.query.QueryOptions)

Example 19 with MutableContextSet

use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class ParentAddTemp method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
    Duration duration = args.getDuration(1);
    TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(2).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
    MutableContextSet context = args.getContextOrDefault(2, plugin);
    Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
    if (group == null) {
        return;
    }
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, group, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (group.getName().equalsIgnoreCase(target.getIdentifier().getName())) {
        Message.ALREADY_TEMP_INHERITS.send(sender, target, group, context);
        return;
    }
    DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).expiry(duration).withContext(context).build(), modifier);
    if (result.getResult().wasSuccessful()) {
        duration = result.getMergedNode().getExpiryDuration();
        Message.SET_TEMP_INHERIT_SUCCESS.send(sender, target, group, duration, context);
        LoggedAction.build().source(sender).target(target).description("parent", "addtemp", group.getName(), duration, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.ALREADY_TEMP_INHERITS.send(sender, target, group, context);
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) TemporaryNodeMergeStrategy(net.luckperms.api.model.data.TemporaryNodeMergeStrategy) MutableContextSet(net.luckperms.api.context.MutableContextSet) Duration(java.time.Duration) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 20 with MutableContextSet

use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class ParentRemove method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST_ALLOW_SPACE);
    MutableContextSet context = args.getContextOrDefault(1, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, groupName, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, groupName)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (target.getType() == HolderType.USER) {
        User user = (User) target;
        boolean shouldPrevent = plugin.getConfiguration().get(ConfigKeys.PREVENT_PRIMARY_GROUP_REMOVAL) && context.isEmpty() && plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD).equals("stored") && user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(groupName);
        if (shouldPrevent) {
            Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
            return;
        }
    }
    DataMutateResult result = target.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).withContext(context).build());
    if (result.wasSuccessful()) {
        Message.UNSET_INHERIT_SUCCESS.send(sender, target, Component.text(groupName), context);
        LoggedAction.build().source(sender).target(target).description("parent", "remove", groupName, context).build().submit(plugin, sender);
        if (target.getType() == HolderType.USER) {
            plugin.getUserManager().giveDefaultIfNeeded((User) target);
        }
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.DOES_NOT_INHERIT.send(sender, target, Component.text(groupName), context);
    }
}
Also used : User(me.lucko.luckperms.common.model.User) MutableContextSet(net.luckperms.api.context.MutableContextSet) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Aggregations

MutableContextSet (net.luckperms.api.context.MutableContextSet)28 DataMutateResult (net.luckperms.api.model.data.DataMutateResult)13 Node (net.luckperms.api.node.Node)8 Duration (java.time.Duration)7 List (java.util.List)6 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)6 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)6 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)6 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)6 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)6 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)6 TabCompletions (me.lucko.luckperms.common.command.tabcomplete.TabCompletions)6 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)6 StorageAssistant (me.lucko.luckperms.common.command.utils.StorageAssistant)6 Message (me.lucko.luckperms.common.locale.Message)6 Group (me.lucko.luckperms.common.model.Group)6 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)6 Sender (me.lucko.luckperms.common.sender.Sender)6 Predicates (me.lucko.luckperms.common.util.Predicates)6 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)5