Search in sources :

Example 1 with PermissionAttachment

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

the class LPPermissible method addAttachment.

@Override
public PermissionAttachment addAttachment(Plugin plugin, String permission, Boolean value) {
    if (plugin == null) {
        throw new NullPointerException("plugin");
    }
    if (permission == null) {
        throw new NullPointerException("permission");
    }
    PermissionAttachment ret = addAttachment(plugin);
    ret.setPermission(permission, value);
    return ret;
}
Also used : PermissionAttachment(cn.nukkit.permission.PermissionAttachment)

Example 2 with PermissionAttachment

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

the class PermissibleInjector method inject.

/**
 * Injects a {@link LPPermissible} into a {@link Player}.
 *
 * @param player the player to inject into
 * @param newPermissible the permissible to inject
 * @throws Exception propagates any exceptions which were thrown during injection
 */
public static void inject(Player player, LPPermissible newPermissible) throws Exception {
    // get the existing PermissibleBase held by the player
    PermissibleBase oldPermissible = (PermissibleBase) PLAYER_PERMISSIBLE_FIELD.get(player);
    // seems we have already injected into this player.
    if (oldPermissible instanceof LPPermissible) {
        throw new IllegalStateException("LPPermissible already injected into player " + player.toString());
    }
    // Move attachments over from the old permissible
    // noinspection unchecked
    Set<PermissionAttachment> attachments = (Set<PermissionAttachment>) PERMISSIBLE_BASE_ATTACHMENTS_FIELD.get(oldPermissible);
    newPermissible.convertAndAddAttachments(attachments);
    attachments.clear();
    oldPermissible.clearPermissions();
    // Setup the new permissible
    newPermissible.getActive().set(true);
    newPermissible.setOldPermissible(oldPermissible);
    // inject the new instance
    PLAYER_PERMISSIBLE_FIELD.set(player, newPermissible);
}
Also used : DummyPermissibleBase(me.lucko.luckperms.nukkit.model.dummy.DummyPermissibleBase) PermissibleBase(cn.nukkit.permission.PermissibleBase) Set(java.util.Set) PermissionAttachment(cn.nukkit.permission.PermissionAttachment)

Example 3 with PermissionAttachment

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

the class LPPermissible method addAttachment.

@Override
public PermissionAttachment addAttachment(Plugin plugin, String permission) {
    if (plugin == null) {
        throw new NullPointerException("plugin");
    }
    if (permission == null) {
        throw new NullPointerException("permission");
    }
    PermissionAttachment ret = addAttachment(plugin);
    ret.setPermission(permission, true);
    return ret;
}
Also used : PermissionAttachment(cn.nukkit.permission.PermissionAttachment)

Aggregations

PermissionAttachment (cn.nukkit.permission.PermissionAttachment)3 PermissibleBase (cn.nukkit.permission.PermissibleBase)1 Set (java.util.Set)1 DummyPermissibleBase (me.lucko.luckperms.nukkit.model.dummy.DummyPermissibleBase)1