Search in sources :

Example 16 with Contexts

use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.

the class BungeePermissionCheckListener method onPlayerTristateCheck.

@EventHandler
public void onPlayerTristateCheck(TristateCheckEvent e) {
    if (!(e.getSender() instanceof ProxiedPlayer)) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
    User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
    if (user == null) {
        e.setResult(Tristate.UNDEFINED);
        return;
    }
    Contexts contexts = this.plugin.getContextManager().getApplicableContexts(player);
    Tristate result = user.getCachedData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_LOOKUP_CHECK);
    if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
        // just use the result provided by the proxy when the event was created
        return;
    }
    e.setResult(result);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) User(me.lucko.luckperms.common.model.User) Tristate(me.lucko.luckperms.api.Tristate) Contexts(me.lucko.luckperms.api.Contexts) EventHandler(net.md_5.bungee.event.EventHandler)

Example 17 with Contexts

use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.

the class BungeePermissionCheckListener method onPlayerPermissionCheck.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
    if (!(e.getSender() instanceof ProxiedPlayer)) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
    User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
    if (user == null) {
        e.setHasPermission(false);
        return;
    }
    Contexts contexts = this.plugin.getContextManager().getApplicableContexts(player);
    Tristate result = user.getCachedData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
    if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
        // just use the result provided by the proxy when the event was created
        return;
    }
    e.setHasPermission(result.asBoolean());
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) User(me.lucko.luckperms.common.model.User) Tristate(me.lucko.luckperms.api.Tristate) Contexts(me.lucko.luckperms.api.Contexts) EventHandler(net.md_5.bungee.event.EventHandler)

Example 18 with Contexts

use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.

the class CalculatedSubject method getOption.

@Override
public Optional<String> getOption(ImmutableContextSet contexts, String key) {
    Contexts lookupContexts = Contexts.of(contexts, Contexts.global().getSettings());
    Map<String, String> meta = this.cachedData.getMetaData(lookupContexts).getMeta();
    return Optional.ofNullable(meta.get(key));
}
Also used : Contexts(me.lucko.luckperms.api.Contexts)

Aggregations

Contexts (me.lucko.luckperms.api.Contexts)18 MetaCache (me.lucko.luckperms.common.caching.type.MetaCache)8 User (me.lucko.luckperms.common.model.User)8 Group (me.lucko.luckperms.common.model.Group)7 Tristate (me.lucko.luckperms.api.Tristate)5 PermissionCache (me.lucko.luckperms.common.caching.type.PermissionCache)5 Objects (java.util.Objects)3 Node (me.lucko.luckperms.api.Node)3 MetaContexts (me.lucko.luckperms.api.caching.MetaContexts)3 CacheLoader (com.github.benmanes.caffeine.cache.CacheLoader)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)2 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TimeUnit (java.util.concurrent.TimeUnit)2 Nonnull (javax.annotation.Nonnull)2 ChatMetaType (me.lucko.luckperms.api.ChatMetaType)2