cn.nukkit.permission.PermissionAttachment Java Examples

The following examples show how to use cn.nukkit.permission.PermissionAttachment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public void removeAttachment(PermissionAttachment attachment) {
    Objects.requireNonNull(attachment, "attachment");

    LuckPermsPermissionAttachment luckPermsAttachment;

    if (!(attachment instanceof LuckPermsPermissionAttachment)) {
        // try to find a match
        LuckPermsPermissionAttachment match = this.hookedAttachments.stream().filter(at -> at.getSource() == attachment).findFirst().orElse(null);
        if (match != null) {
            luckPermsAttachment = match;
        } else {
            throw new IllegalArgumentException("Given attachment is not a LPPermissionAttachment.");
        }
    } else {
        luckPermsAttachment = (LuckPermsPermissionAttachment) attachment;
    }

    if (luckPermsAttachment.getPermissible() != this) {
        throw new IllegalArgumentException("Attachment does not belong to this permissible.");
    }

    luckPermsAttachment.remove();
}
 
Example #2
Source File: PermissibleInjector.java    From LuckPerms with MIT License 5 votes vote down vote up
/**
 * Injects a {@link LuckPermsPermissible} 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, LuckPermsPermissible 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 LuckPermsPermissible) {
        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);
}
 
Example #3
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String permission) {
    Objects.requireNonNull(plugin, "plugin");
    Objects.requireNonNull(permission, "permission");

    PermissionAttachment attachment = addAttachment(plugin);
    attachment.setPermission(permission, true);
    return attachment;
}
 
Example #4
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String permission, Boolean value) {
    Objects.requireNonNull(plugin, "plugin");
    Objects.requireNonNull(permission, "permission");
    Objects.requireNonNull(value, "value");

    PermissionAttachment attachment = addAttachment(plugin);
    attachment.setPermission(permission, value);
    return attachment;
}
 
Example #5
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public boolean add(PermissionAttachment attachment) {
    if (LuckPermsPermissible.this.hookedAttachments.stream().anyMatch(at -> at.getSource() == attachment)) {
        return false;
    }

    new LuckPermsPermissionAttachment(LuckPermsPermissible.this, attachment).hook();
    return true;
}
 
Example #6
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public boolean addAll(@NonNull Collection<? extends PermissionAttachment> c) {
    boolean modified = false;
    for (PermissionAttachment e : c) {
        if (add(e)) {
            modified = true;
        }
    }
    return modified;
}
 
Example #7
Source File: LuckPermsPermissionAttachment.java    From LuckPerms with MIT License 5 votes vote down vote up
public LuckPermsPermissionAttachment(LuckPermsPermissible permissible, PermissionAttachment source) {
    super(source.getPlugin(), null);
    this.permissible = permissible;
    this.owner = source.getPlugin();

    // copy
    this.perms.putAll(source.getPermissions());
    this.source = source;

    injectFakeMap();
}
 
Example #8
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name) {
    return this.addAttachment(plugin, name, null);
}
 
Example #9
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
    return this.addAttachment(plugin, null);
}
 
Example #10
Source File: LuckPermsPermissionAttachment.java    From LuckPerms with MIT License 4 votes vote down vote up
PermissionAttachment getSource() {
    return this.source;
}
 
Example #11
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) {
    return this.perm.addAttachment(plugin, name, value);
}
 
Example #12
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public boolean remove(Object o) {
    removeAttachment((PermissionAttachment) o);
    return true;
}
 
Example #13
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public @NonNull <T> T[] toArray(@NonNull T[] a) {
    return ImmutableList.<PermissionAttachment>copyOf(LuckPermsPermissible.this.hookedAttachments).toArray(a);
}
 
Example #14
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public @NonNull Object[] toArray() {
    return ImmutableList.<PermissionAttachment>copyOf(LuckPermsPermissible.this.hookedAttachments).toArray();
}
 
Example #15
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public Iterator<PermissionAttachment> iterator() {
    return ImmutableList.<PermissionAttachment>copyOf(LuckPermsPermissible.this.hookedAttachments).iterator();
}
 
Example #16
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public boolean contains(Object o) {
    PermissionAttachment attachment = (PermissionAttachment) o;
    return LuckPermsPermissible.this.hookedAttachments.stream().anyMatch(at -> at.getSource() == attachment);
}
 
Example #17
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void removeAttachment(PermissionAttachment attachment) {
    this.perm.removeAttachment(attachment);
}
 
Example #18
Source File: BlockEntityCommandBlock.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
    return this.perm.addAttachment(plugin);
}
 
Example #19
Source File: ConsoleCommandSender.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
    return this.perm.addAttachment(plugin);
}
 
Example #20
Source File: ConsoleCommandSender.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name) {
    return this.perm.addAttachment(plugin, name);
}
 
Example #21
Source File: ConsoleCommandSender.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) {
    return this.perm.addAttachment(plugin, name, value);
}
 
Example #22
Source File: ConsoleCommandSender.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void removeAttachment(PermissionAttachment attachment) {
    this.perm.removeAttachment(attachment);
}
 
Example #23
Source File: NukkitCMDSender.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void removeAttachment(PermissionAttachment attachment) {
    cs.removeAttachment(attachment);
}
 
Example #24
Source File: BlockEntityCommandBlock.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name) {
    return this.perm.addAttachment(plugin, name);
}
 
Example #25
Source File: BlockEntityCommandBlock.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) {
    return this.perm.addAttachment(plugin, name, value);
}
 
Example #26
Source File: BlockEntityCommandBlock.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void removeAttachment(PermissionAttachment attachment) {
    this.perm.removeAttachment(attachment);
}
 
Example #27
Source File: ConsoleCommandSender.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
    return this.perm.addAttachment(plugin);
}
 
Example #28
Source File: ConsoleCommandSender.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name) {
    return this.perm.addAttachment(plugin, name);
}
 
Example #29
Source File: ConsoleCommandSender.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) {
    return this.perm.addAttachment(plugin, name, value);
}
 
Example #30
Source File: ConsoleCommandSender.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void removeAttachment(PermissionAttachment attachment) {
    this.perm.removeAttachment(attachment);
}