/*
 * This file is part of NucleusFramework for Bukkit, licensed under the MIT License (MIT).
 *
 * Copyright (c) JCThePants (www.jcwhatever.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


package com.jcwhatever.nucleus.internal.providers.permissions;

import com.jcwhatever.nucleus.internal.providers.permissions.bukkit.FastPermissions;
import com.jcwhatever.nucleus.internal.providers.permissions.bukkit.SuperPermission;
import com.jcwhatever.nucleus.providers.Provider;
import com.jcwhatever.nucleus.providers.permissions.IPermission;
import com.jcwhatever.nucleus.providers.permissions.IPermissionsProvider;
import com.jcwhatever.nucleus.utils.PreCon;

import org.bukkit.Bukkit;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;

/**
 * Abstract implementation of a permissions handler
 */
public abstract class AbstractPermissionsProvider extends Provider implements IPermissionsProvider {

    private final FastPermissions _fastPerms = new FastPermissions();

    @Override
    public IPermission get(String permissionName) {
        return new SuperPermission(this, manager().getPermission(permissionName), _fastPerms);
    }

    @Override
    public IPermission register(String permissionName, PermissionDefault value) {
        Permission perm = manager().getPermission(permissionName);
        if (perm != null)
            return new SuperPermission(this, perm, _fastPerms);

        perm = new Permission(permissionName);
        perm.setDefault(value);

        _fastPerms.addPermission(perm);

        return new SuperPermission(this, perm, _fastPerms);
    }

    @Override
    public void unregister(String permissionName) {
        Bukkit.getPluginManager().removePermission(permissionName);
    }

    @Override
    public void unregister(IPermission permission) {
        Bukkit.getPluginManager().removePermission((Permission) permission.getHandle());
    }

    @Override
    public void runBatchOperation(Runnable operations) {
        PreCon.notNull(operations);

        _fastPerms.start();
        operations.run();
        _fastPerms.end();
    }

    private PluginManager manager() {
        return Bukkit.getPluginManager();
    }
}

@@ -1846,16 +1846,51 @@
 nager;%0A%0A
+import javax.annotation.Nullable;%0A%0A
 /**%0A * A
@@ -2110,24 +2110,38 @@
 issions();%0A%0A
+    @Nullable%0A
     @Overrid
@@ -2190,32 +2190,33 @@
 sionName) %7B%0A
+%0A
         
 return new S
@@ -2203,33 +2203,28 @@
         
-return new SuperP
+Permission p
 ermissio
@@ -2224,22 +2224,18 @@
 rmission
-(this,
+ =
  manager
@@ -2266,16 +2266,127 @@
 ionName)
+;%0A        if (permission == null)%0A            return null;%0A%0A        return new SuperPermission(this, permission
 , _fastP

fix null reference if permission not found