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;
}
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);
}
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;
}
Aggregations