Search in sources :

Example 1 with Permission

use of cn.nukkit.permission.Permission in project LuckPerms by lucko.

the class InjectorDefaultsMap method inject.

private LPDefaultsMap inject() throws Exception {
    Objects.requireNonNull(OP_DEFAULT_PERMISSIONS_FIELD, "OP_DEFAULT_PERMISSIONS_FIELD");
    Objects.requireNonNull(NON_OP_DEFAULT_PERMISSIONS_FIELD, "NON_OP_DEFAULT_PERMISSIONS_FIELD");
    PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
    Object opMap = OP_DEFAULT_PERMISSIONS_FIELD.get(pluginManager);
    Object nonOpMap = NON_OP_DEFAULT_PERMISSIONS_FIELD.get(pluginManager);
    if (opMap instanceof LPDefaultsMap.DefaultPermissionSet && ((LPDefaultsMap.DefaultPermissionSet) opMap).parent.plugin == this.plugin) {
        if (nonOpMap instanceof LPDefaultsMap.DefaultPermissionSet && ((LPDefaultsMap.DefaultPermissionSet) nonOpMap).parent.plugin == this.plugin) {
            return null;
        }
    }
    // noinspection unchecked
    Map<String, Permission> castedOpMap = (Map<String, Permission>) opMap;
    // noinspection unchecked
    Map<String, Permission> castedNonOpMap = (Map<String, Permission>) nonOpMap;
    // make a new map & inject it
    LPDefaultsMap newMap = new LPDefaultsMap(this.plugin, ImmutableMap.of(true, castedOpMap, false, castedNonOpMap));
    OP_DEFAULT_PERMISSIONS_FIELD.set(pluginManager, newMap.getOpPermissions());
    NON_OP_DEFAULT_PERMISSIONS_FIELD.set(pluginManager, newMap.getNonOpPermissions());
    return newMap;
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager) Permission(cn.nukkit.permission.Permission) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Permission

use of cn.nukkit.permission.Permission in project LuckPerms by lucko.

the class LPPermissionMap method resolveChildren.

private void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
    // the first time this method is called for a given permission, the children map will contain only the permission itself.
    for (Map.Entry<String, Boolean> e : children.entrySet()) {
        if (accumulator.containsKey(e.getKey())) {
            // Prevent infinite loops
            continue;
        }
        // xor the value using the parent (nukkit logic, not mine)
        boolean value = e.getValue() ^ invert;
        accumulator.put(e.getKey().toLowerCase(), value);
        // lookup any deeper children & resolve if present
        Permission perm = this.delegate.get(e.getKey());
        if (perm != null) {
            resolveChildren(accumulator, perm.getChildren(), !value);
        }
    }
}
Also used : Permission(cn.nukkit.permission.Permission) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ForwardingMap(com.google.common.collect.ForwardingMap) Map(java.util.Map)

Example 3 with Permission

use of cn.nukkit.permission.Permission in project LuckPerms by lucko.

the class LPPermissionMap method putIfAbsent.

@Override
public Permission putIfAbsent(String key, Permission value) {
    this.plugin.getPermissionVault().offer(key);
    Permission ret = super.putIfAbsent(key, value);
    update();
    return ret;
}
Also used : Permission(cn.nukkit.permission.Permission)

Example 4 with Permission

use of cn.nukkit.permission.Permission in project LuckPerms by lucko.

the class InjectorPermissionMap method inject.

private LPPermissionMap inject() throws Exception {
    Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
    PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
    Object map = PERMISSIONS_FIELD.get(pluginManager);
    if (map instanceof LPPermissionMap && ((LPPermissionMap) map).plugin == this.plugin) {
        return null;
    }
    // noinspection unchecked
    Map<String, Permission> castedMap = (Map<String, Permission>) map;
    // make a new map & inject it
    LPPermissionMap newMap = new LPPermissionMap(this.plugin, castedMap);
    PERMISSIONS_FIELD.set(pluginManager, newMap);
    return newMap;
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager) Permission(cn.nukkit.permission.Permission) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with Permission

use of cn.nukkit.permission.Permission in project LuckPerms by lucko.

the class LPDefaultsMap method refreshOp.

/**
 * Refreshes the op data in this provider.
 */
private void refreshOp() {
    Map<String, Boolean> builder = new HashMap<>();
    for (Permission perm : getOpPermissions().values()) {
        String name = perm.getName().toLowerCase();
        builder.put(name, true);
        for (Map.Entry<String, Boolean> child : this.plugin.getPermissionMap().getChildPermissions(name, true).entrySet()) {
            builder.putIfAbsent(child.getKey(), child.getValue());
        }
    }
    this.resolvedOpDefaults = ImmutableMap.copyOf(builder);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Permission(cn.nukkit.permission.Permission) ForwardingMap(com.google.common.collect.ForwardingMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

Permission (cn.nukkit.permission.Permission)9 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 PluginManager (cn.nukkit.plugin.PluginManager)3 ForwardingMap (com.google.common.collect.ForwardingMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Player (cn.nukkit.Player)1 Config (cn.nukkit.utils.Config)1 MainLogger (cn.nukkit.utils.MainLogger)1 PluginException (cn.nukkit.utils.PluginException)1 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)1 User (me.lucko.luckperms.common.model.User)1 PermissionDefault (me.lucko.luckperms.nukkit.model.PermissionDefault)1 LPPermissible (me.lucko.luckperms.nukkit.model.permissible.LPPermissible)1