Skip to content

Commit

Permalink
add methods to add and remove Permission
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Oct 8, 2024
1 parent 8606b41 commit 55d9979
Showing 1 changed file with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* A component that handles the registration and unregistration of {@link Permission}
*/
public class PermissionComponent implements Loadable {
private final List<Permission> permissions;
private final List<Permission> permissions = new ArrayList<>();
private boolean enabled = false;

/**
* Create a new instance
*
* @param permissions the permissions
*/
public PermissionComponent(List<Permission> permissions) {
this.permissions = permissions;
this.permissions.addAll(permissions);
}

/**
Expand All @@ -31,10 +32,6 @@ public PermissionComponent(List<Permission> permissions) {
* @param plugin the plugin
*/
public PermissionComponent(BasePlugin plugin) {
this.permissions = getPermissions(plugin);
}

private List<Permission> getPermissions(BasePlugin plugin) {
List<Permission> permissions = new ArrayList<>();

Class<?>[] classes = {
Expand All @@ -57,20 +54,46 @@ private List<Permission> 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
public void enable() {
for (Permission permission : permissions) {
Bukkit.getPluginManager().addPermission(permission);
}
enabled = true;
}

@Override
public void disable() {
for (Permission permission : permissions) {
Bukkit.getPluginManager().removePermission(permission);
}
enabled = false;
}
}

0 comments on commit 55d9979

Please sign in to comment.