diff --git a/plugin/plugin-permission/src/main/java/io/github/projectunified/minelib/plugin/permission/PermissionComponent.java b/plugin/plugin-permission/src/main/java/io/github/projectunified/minelib/plugin/permission/PermissionComponent.java index c87f28a..5e32f60 100644 --- a/plugin/plugin-permission/src/main/java/io/github/projectunified/minelib/plugin/permission/PermissionComponent.java +++ b/plugin/plugin-permission/src/main/java/io/github/projectunified/minelib/plugin/permission/PermissionComponent.java @@ -14,7 +14,8 @@ * A component that handles the registration and unregistration of {@link Permission} */ public class PermissionComponent implements Loadable { - private final List permissions; + private final List permissions = new ArrayList<>(); + private boolean enabled = false; /** * Create a new instance @@ -22,7 +23,7 @@ public class PermissionComponent implements Loadable { * @param permissions the permissions */ public PermissionComponent(List permissions) { - this.permissions = permissions; + this.permissions.addAll(permissions); } /** @@ -31,10 +32,6 @@ public PermissionComponent(List permissions) { * @param plugin the plugin */ public PermissionComponent(BasePlugin plugin) { - this.permissions = getPermissions(plugin); - } - - private List getPermissions(BasePlugin plugin) { List permissions = new ArrayList<>(); Class[] classes = { @@ -57,7 +54,31 @@ private List getPermissions(BasePlugin plugin) { } } - return permissions; + this.permissions.addAll(permissions); + } + + /** + * Add a permission + * + * @param permission the permission + */ + public void addPermission(Permission permission) { + if (enabled) { + Bukkit.getPluginManager().addPermission(permission); + } + permissions.add(permission); + } + + /** + * Remove a permission + * + * @param permission the permission + */ + public void removePermission(Permission permission) { + if (enabled) { + Bukkit.getPluginManager().removePermission(permission); + } + permissions.remove(permission); } @Override @@ -65,6 +86,7 @@ public void enable() { for (Permission permission : permissions) { Bukkit.getPluginManager().addPermission(permission); } + enabled = true; } @Override @@ -72,5 +94,6 @@ public void disable() { for (Permission permission : permissions) { Bukkit.getPluginManager().removePermission(permission); } + enabled = false; } }