Search in sources :

Example 16 with Tristate

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

the class BungeePermissionCheckListener method onOtherPermissionCheck.

@EventHandler(priority = EventPriority.HIGHEST)
public void onOtherPermissionCheck(PermissionCheckEvent e) {
    if (e.getSender() instanceof ProxiedPlayer) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    String permission = e.getPermission();
    Tristate result = Tristate.fromBoolean(e.hasPermission());
    String name = "internal/" + e.getSender().getName();
    this.plugin.getVerboseHandler().offerCheckData(CheckOrigin.PLATFORM_PERMISSION_CHECK, name, ContextSet.empty(), permission, result);
    this.plugin.getPermissionVault().offer(permission);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Tristate(me.lucko.luckperms.api.Tristate) EventHandler(net.md_5.bungee.event.EventHandler)

Example 17 with Tristate

use of me.lucko.luckperms.api.Tristate 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 18 with Tristate

use of me.lucko.luckperms.api.Tristate 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 19 with Tristate

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

the class DefaultsProcessor method hasPermission.

@Override
public Tristate hasPermission(String permission) {
    Tristate t = getTypeDefaults().getPermissionValue(this.contexts, permission);
    if (t != Tristate.UNDEFINED) {
        return t;
    }
    t = this.service.getRootDefaults().getPermissionValue(this.contexts, permission);
    if (t != Tristate.UNDEFINED) {
        return t;
    }
    return Tristate.UNDEFINED;
}
Also used : Tristate(me.lucko.luckperms.api.Tristate)

Example 20 with Tristate

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

the class DefaultsProcessor method hasPermission.

@Override
public Tristate hasPermission(String permission) {
    Tristate t = this.plugin.getDefaultPermissionMap().lookupDefaultPermission(permission, this.isOp);
    if (t != Tristate.UNDEFINED) {
        return t;
    }
    PermissionDefault def = PermissionDefault.fromPermission(this.plugin.getPermissionMap().get(permission));
    return def == null ? Tristate.UNDEFINED : Tristate.fromBoolean(def.getValue(this.isOp));
}
Also used : PermissionDefault(me.lucko.luckperms.nukkit.model.PermissionDefault) Tristate(me.lucko.luckperms.api.Tristate)

Aggregations

Tristate (me.lucko.luckperms.api.Tristate)20 User (me.lucko.luckperms.common.model.User)6 Contexts (me.lucko.luckperms.api.Contexts)4 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)4 EventHandler (net.md_5.bungee.event.EventHandler)4 Group (me.lucko.luckperms.common.model.Group)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Nonnull (javax.annotation.Nonnull)2 PermissionCache (me.lucko.luckperms.common.caching.type.PermissionCache)2 Track (me.lucko.luckperms.common.model.Track)2 LPPermissionDescription (me.lucko.luckperms.sponge.service.model.LPPermissionDescription)2 LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)2 LPSubjectCollection (me.lucko.luckperms.sponge.service.model.LPSubjectCollection)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 UUID (java.util.UUID)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 ScriptEngine (javax.script.ScriptEngine)1