Search in sources :

Example 1 with PluginManager

use of cn.nukkit.plugin.PluginManager in project LuckPerms by lucko.

the class InjectorDefaultsMap method uninject.

public static void uninject() {
    try {
        Objects.requireNonNull(OP_DEFAULT_PERMISSIONS_FIELD, "OP_DEFAULT_PERMISSIONS_FIELD");
        Objects.requireNonNull(NON_OP_DEFAULT_PERMISSIONS_FIELD, "NON_OP_DEFAULT_PERMISSIONS_FIELD");
        PluginManager pluginManager = Server.getInstance().getPluginManager();
        {
            Object map = OP_DEFAULT_PERMISSIONS_FIELD.get(pluginManager);
            if (map instanceof LPDefaultsMap.DefaultPermissionSet) {
                LPDefaultsMap.DefaultPermissionSet lpMap = (LPDefaultsMap.DefaultPermissionSet) map;
                OP_DEFAULT_PERMISSIONS_FIELD.set(pluginManager, new HashMap<>(lpMap));
            }
        }
        {
            Object map = NON_OP_DEFAULT_PERMISSIONS_FIELD.get(pluginManager);
            if (map instanceof LPDefaultsMap.DefaultPermissionSet) {
                LPDefaultsMap.DefaultPermissionSet lpMap = (LPDefaultsMap.DefaultPermissionSet) map;
                NON_OP_DEFAULT_PERMISSIONS_FIELD.set(pluginManager, new HashMap<>(lpMap));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager) HashMap(java.util.HashMap)

Example 2 with PluginManager

use of cn.nukkit.plugin.PluginManager 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 3 with PluginManager

use of cn.nukkit.plugin.PluginManager in project LuckPerms by lucko.

the class InjectorPermissionMap method uninject.

public static void uninject() {
    try {
        Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
        PluginManager pluginManager = Server.getInstance().getPluginManager();
        Object map = PERMISSIONS_FIELD.get(pluginManager);
        if (map instanceof LPPermissionMap) {
            LPPermissionMap lpMap = (LPPermissionMap) map;
            PERMISSIONS_FIELD.set(pluginManager, new HashMap<>(lpMap));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager)

Example 4 with PluginManager

use of cn.nukkit.plugin.PluginManager 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 PluginManager

use of cn.nukkit.plugin.PluginManager in project LuckPerms by lucko.

the class InjectorSubscriptionMap method uninject.

public static void uninject() {
    try {
        Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
        PluginManager pluginManager = Server.getInstance().getPluginManager();
        Object map = PERM_SUBS_FIELD.get(pluginManager);
        if (map instanceof LPSubscriptionMap) {
            LPSubscriptionMap lpMap = (LPSubscriptionMap) map;
            PERM_SUBS_FIELD.set(pluginManager, lpMap.detach());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager)

Aggregations

PluginManager (cn.nukkit.plugin.PluginManager)7 Permission (cn.nukkit.permission.Permission)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Player (cn.nukkit.Player)1 Permissible (cn.nukkit.permission.Permissible)1 Config (cn.nukkit.utils.Config)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Set (java.util.Set)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