Search in sources :

Example 61 with User

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

the class LPPermissionAttachment method setPermissionInternal.

private void setPermissionInternal(String name, boolean value) {
    if (!this.permissible.getPlugin().getConfiguration().get(ConfigKeys.APPLY_NUKKIT_ATTACHMENT_PERMISSIONS)) {
        return;
    }
    // construct a node for the permission being set
    // we use the servers static context to *try* to ensure that the node will apply
    Node node = NodeFactory.builder(name).setValue(value).withExtraContext(this.permissible.getPlugin().getContextManager().getStaticContext()).build();
    // convert the constructed node to a transient node instance to refer back to this attachment
    ImmutableTransientNode<LPPermissionAttachment> transientNode = ImmutableTransientNode.of(node, this);
    // set the transient node
    User user = this.permissible.getUser();
    if (user.setTransientPermission(transientNode).asBoolean()) {
        user.reloadCachedData();
    }
}
Also used : User(me.lucko.luckperms.common.model.User) ImmutableTransientNode(me.lucko.luckperms.common.node.ImmutableTransientNode) Node(me.lucko.luckperms.api.Node)

Example 62 with User

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

the class LPNukkitPlugin method performFinalSetup.

@Override
protected void performFinalSetup() {
    // register permissions
    try {
        PluginManager pm = this.bootstrap.getServer().getPluginManager();
        PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE;
        for (CommandPermission p : CommandPermission.values()) {
            pm.addPermission(new Permission(p.getPermission(), null, permDefault.toString()));
        }
    } catch (Exception e) {
    // this throws an exception if the plugin is /reloaded, grr
    }
    if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
        Config ops = this.bootstrap.getServer().getOps();
        ops.getKeys(false).forEach(ops::remove);
    }
    // replace the temporary executor when the Nukkit one starts
    this.bootstrap.getServer().getScheduler().scheduleTask(this.bootstrap, () -> this.bootstrap.getScheduler().setUseFallback(false), true);
    // Load any online users (in the case of a reload)
    for (Player player : this.bootstrap.getServer().getOnlinePlayers().values()) {
        this.bootstrap.getScheduler().doAsync(() -> {
            try {
                User user = this.connectionListener.loadUser(player.getUniqueId(), player.getName());
                if (user != null) {
                    this.bootstrap.getScheduler().doSync(() -> {
                        try {
                            LPPermissible lpPermissible = new LPPermissible(player, user, this);
                            PermissibleInjector.inject(player, lpPermissible);
                        } catch (Throwable t) {
                            t.printStackTrace();
                        }
                    });
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager) LPPermissible(me.lucko.luckperms.nukkit.model.permissible.LPPermissible) Player(cn.nukkit.Player) User(me.lucko.luckperms.common.model.User) PermissionDefault(me.lucko.luckperms.nukkit.model.PermissionDefault) Config(cn.nukkit.utils.Config) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Permission(cn.nukkit.permission.Permission) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission)

Example 63 with User

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

the class LPNukkitPlugin method removePlatformHooks.

@Override
protected void removePlatformHooks() {
    // uninject from players
    for (Player player : this.bootstrap.getServer().getOnlinePlayers().values()) {
        try {
            PermissibleInjector.unInject(player, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
            player.setOp(false);
        }
        final User user = getUserManager().getIfLoaded(player.getUniqueId());
        if (user != null) {
            user.getCachedData().invalidateCaches();
            getUserManager().unload(user);
        }
    }
    // uninject custom maps
    InjectorSubscriptionMap.uninject();
    InjectorPermissionMap.uninject();
    InjectorDefaultsMap.uninject();
}
Also used : Player(cn.nukkit.Player) User(me.lucko.luckperms.common.model.User)

Example 64 with User

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

the class HolderSubjectData method setOption.

@Override
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
    Objects.requireNonNull(contexts, "contexts");
    Objects.requireNonNull(key, "key");
    Objects.requireNonNull(value, "value");
    Node node;
    if (key.equalsIgnoreCase(NodeFactory.PREFIX_KEY) || key.equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
        // special handling.
        ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
        // remove all prefixes/suffixes from the user
        List<Node> toRemove = streamNodes().filter(type::matches).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
        toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
        MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, this.service.getPlugin().getContextManager().formContexts(contexts));
        int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
        priority += 10;
        node = NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(contexts).build();
    } else {
        // standard remove
        List<Node> toRemove = streamNodes().filter(n -> n.isMeta() && n.getMeta().getKey().equals(key)).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
        toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
        node = NodeFactory.buildMetaNode(key, value).withExtraContext(contexts).build();
    }
    this.type.run(() -> this.holder.setPermission(node), () -> this.holder.setTransientPermission(node));
    return objectSave(this.holder).thenApply(v -> true);
}
Also used : DataMutateResult(me.lucko.luckperms.api.DataMutateResult) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) Tristate(me.lucko.luckperms.api.Tristate) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PermissionService(org.spongepowered.api.service.permission.PermissionService) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SubjectData(org.spongepowered.api.service.permission.SubjectData) ProxyFactory(me.lucko.luckperms.sponge.service.proxy.ProxyFactory) ImmutableMap(com.google.common.collect.ImmutableMap) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Collection(java.util.Collection) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) List(java.util.List) Stream(java.util.stream.Stream) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) NodeMapType(me.lucko.luckperms.common.model.NodeMapType) 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) ChatMetaType(me.lucko.luckperms.api.ChatMetaType)

Example 65 with User

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

the class HolderSubjectData method objectSave.

private CompletableFuture<Void> objectSave(PermissionHolder t) {
    // handle transient first
    if (this.type == NodeMapType.TRANSIENT) {
        // don't bother saving to primary storage. just refresh
        if (t.getType().isUser()) {
            User user = ((User) t);
            return user.getRefreshBuffer().request();
        } else {
            return this.service.getPlugin().getUpdateTaskBuffer().request();
        }
    }
    // handle enduring
    if (t.getType().isUser()) {
        User user = ((User) t);
        CompletableFuture<Void> fut = new CompletableFuture<>();
        this.service.getPlugin().getStorage().saveUser(user).whenCompleteAsync((v, ex) -> {
            if (ex != null) {
                fut.complete(null);
            }
            user.getRefreshBuffer().request().thenAccept(fut::complete);
        }, this.service.getPlugin().getBootstrap().getScheduler().async());
        return fut;
    } else {
        Group group = ((Group) t);
        CompletableFuture<Void> fut = new CompletableFuture<>();
        this.service.getPlugin().getStorage().saveGroup(group).whenCompleteAsync((v, ex) -> {
            if (ex != null) {
                fut.complete(null);
            }
            this.service.getPlugin().getUpdateTaskBuffer().request().thenAccept(fut::complete);
        }, this.service.getPlugin().getBootstrap().getScheduler().async());
        return fut;
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) CompletableFuture(java.util.concurrent.CompletableFuture) User(me.lucko.luckperms.common.model.User)

Aggregations

User (me.lucko.luckperms.common.model.User)67 Group (me.lucko.luckperms.common.model.Group)20 UUID (java.util.UUID)16 Node (me.lucko.luckperms.api.Node)14 Contexts (me.lucko.luckperms.api.Contexts)10 List (java.util.List)9 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)9 Tristate (me.lucko.luckperms.api.Tristate)8 Track (me.lucko.luckperms.common.model.Track)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)7 ProgressLogger (me.lucko.luckperms.common.logging.ProgressLogger)7 Sender (me.lucko.luckperms.common.sender.Sender)7 Map (java.util.Map)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)6 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)5 CommandResult (me.lucko.luckperms.common.command.CommandResult)5 SubCommand (me.lucko.luckperms.common.command.abstraction.SubCommand)5