Class PermissionsModule

All Implemented Interfaces:
CommandOwner

public class PermissionsModule extends JavaPlugin
A module responsible for managing permissions within the server.
  • Field Details

    • ROOT

      @Nonnull public static final String ROOT
      The node that grants every permission.
      See Also:
    • ROOT_DENY

      @Nonnull public static final String ROOT_DENY
      The node that denies every permission, which beats every grant.
      See Also:
    • MANIFEST

      @Nonnull public static final PluginManifest MANIFEST
      The plugin manifest for this module.
  • Constructor Details

    • PermissionsModule

      public PermissionsModule(@Nonnull JavaPluginInit init)
      Default Constructor for a PermissionsModule instance.
      Parameters:
      init - The plugin initialization step for this plugin.
  • Method Details

    • get

      public static PermissionsModule get()
      Returns:
      the singleton instance of the PermissionsModule module.
    • registerPermission

      public static void registerPermission(@Nonnull String permission)
      Registers a permission node without any group associations. The node will appear in getRegisteredPermissions() as a known node.
    • registerPermission

      public static void registerPermission(@Nonnull String permission, @Nonnull String... groups)
      Registers a permission node and associates it with one or more virtual groups. Called at class-load time from permission constant declarations.
    • getRegisteredPermissions

      @Nonnull public static Map<String, Set<String>> getRegisteredPermissions()
      Returns:
      all permission nodes that have been registered via registerPermission(String).
    • refreshVirtualGroups

      public void refreshVirtualGroups()
      Rebuilds virtual groups from command permissions and statically registered permissions.
    • reload

      public void reload()
      Reloads permissions.json from disk and rebuilds virtual groups.
    • addProvider

      public void addProvider(@Nonnull PermissionProvider permissionProvider)
      Called to add a new PermissionProvider to the list of providers.
      Parameters:
      permissionProvider - The permission provider to add.
    • removeProvider

      public void removeProvider(@Nonnull PermissionProvider provider)
      Called to remove a PermissionProvider from the list of providers.
      Parameters:
      provider - The permission provider to remove.
    • getProviders

      @Nonnull public List<PermissionProvider> getProviders()
      Returns:
      a list of all registered PermissionProvider instances.
    • getFirstPermissionProvider

      public PermissionProvider getFirstPermissionProvider()
      Returns:
      the first registered PermissionProvider instance.
    • areProvidersTampered

      public boolean areProvidersTampered()
      Returns:
      true if the providers list has been modified from its default state.
    • addUserPermission

      public void addUserPermission(@Nonnull UUID uuid, @Nonnull Set<String> permissions)
      Called to add the given set of permissions to the user with the given UUID.
      Parameters:
      uuid - The UUID of the user.
      permissions - The set of permissions to add.
    • addUserPermission

      @Nonnull public Set<UUID> addUserPermission(@Nonnull Collection<UUID> uuids, @Nonnull Set<String> permissions)
      Called to add the given set of permissions to every user named, as one change.
      Parameters:
      uuids - The UUID of each user.
      permissions - The set of permissions to add.
      Returns:
      the users the permissions were added to.
    • removeUserPermissionFromAll

      @Nonnull public Set<UUID> removeUserPermissionFromAll(@Nonnull String permission)
      Called to take the permission back from every user that holds it as a grant of their own, as one change. A user who holds it through a group keeps it.
      Parameters:
      permission - The permission node.
      Returns:
      the users the permission was taken from.
    • hasUserGrant

      public boolean hasUserGrant(@Nonnull UUID uuid, @Nonnull String permission)
      Determines whether the user holds the permission as a grant of their own, on any provider. A user who holds it through a group or a wildcard does not hold it as a grant.
      Parameters:
      uuid - The UUID of the user.
      permission - The permission node.
      Returns:
      true if the user was granted the permission.
    • removeUserPermission

      public void removeUserPermission(@Nonnull UUID uuid, @Nonnull Set<String> permissions)
      Called to remove the given set of permissions from the user with the given UUID.
      Parameters:
      uuid - The UUID of the user.
      permissions - The set of permissions to remove.
    • getUsersWithPermission

      @Nonnull public Set<UUID> getUsersWithPermission(@Nonnull String permission)
      Finds the users that hold the permission as a grant of their own, across every provider. A user who holds it through a group is not one of them.
      Parameters:
      permission - The permission node.
      Returns:
      the users that were granted the permission.
    • addGroupPermission

      public void addGroupPermission(@Nonnull String group, @Nonnull Set<String> permissions)
      Called to add the given set of permissions to the group with the given name.
      Parameters:
      group - The name of the group.
      permissions - The set of permissions to add.
    • removeGroupPermission

      public void removeGroupPermission(@Nonnull String group, @Nonnull Set<String> permissions)
      Called to remove the given set of permissions from the group with the given name.
      Parameters:
      group - The name of the group.
      permissions - The set of permissions to remove.
    • addUserToGroup

      public void addUserToGroup(@Nonnull UUID uuid, @Nonnull String group)
      Called to add the user with the given UUID to the group with the given name.
      Parameters:
      uuid - The UUID of the user.
      group - The name of the group.
    • removeUserFromGroup

      public void removeUserFromGroup(@Nonnull UUID uuid, @Nonnull String group)
      Called to remove the user with the given UUID from the group with the given name.
      Parameters:
      uuid - The UUID of the user.
      group - The name of the group.
    • setUserGroup

      public void setUserGroup(@Nonnull UUID uuid, @Nonnull String group)
      Atomically replaces all groups for a user with the given single group.
      Parameters:
      uuid - The UUID of the user.
      group - The group to set.
    • setVirtualGroups

      public void setVirtualGroups(@Nonnull Map<String, Set<String>> virtualGroups)
      Called to set the virtual permission groups.
      Parameters:
      virtualGroups - A map of virtual permission groups.
    • getVirtualGroups

      @Nonnull public Map<String, Set<String>> getVirtualGroups()
      Returns:
      the current virtual permission groups (group name to permission nodes).
    • getGroupsForUser

      @Nonnull public Set<String> getGroupsForUser(@Nonnull UUID uuid)
      Called to get all groups for a user with the given UUID.
      Parameters:
      uuid - The UUID of the user.
      Returns:
      a set of group names the user belongs to.
    • getAllRegisteredGroups

      @Nonnull public Set<String> getAllRegisteredGroups()
      Returns:
      all groups known across all providers plus virtual groups.
    • hasPermission

      public boolean hasPermission(@Nonnull UUID uuid, @Nonnull String id)
      Determines whether the given user has the specified permission.
      Parameters:
      uuid - The UUID of the user.
      id - The permission identifier.
      Returns:
      true if the user has the permission, false otherwise.
    • hasPermission

      public boolean hasPermission(@Nonnull UUID uuid, @Nonnull String id, boolean def)
      Full resolution order (deny-wins within each layer, first definitive result wins):
      1. User direct permissions
      2. Group direct permissions (for each group the user belongs to)
      3. Virtual group permissions (for each group the user belongs to)
      4. Parent group permissions (a bounded walk up the inheritance chain, which decides nothing past its bound)
      5. Default value
    • hasPermission

      public boolean hasPermission(@Nonnull UUID uuid, @Nonnull PermissionQuery query)
      Parameters:
      uuid - The UUID of the user.
      query - The lookup for the permission, from PermissionQuery.of(String).
      Returns:
      true if the user has the permission.
      See Also:
    • hasPermission

      public boolean hasPermission(@Nonnull UUID uuid, @Nonnull PermissionQuery query, boolean def)
      Parameters:
      uuid - The UUID of the user.
      query - The lookup for the permission, from PermissionQuery.of(String).
      def - The default value to return if nothing decides.
      Returns:
      true if the user has the permission.
      See Also:
    • hasPermission

      @Nullable public static Boolean hasPermission(@Nullable Set<String> nodes, @Nonnull String id)
      "Deny wins" evaluation of a single permission set.
      1. -* root deny → false
      2. exact deny -id → false
      3. exact grant id → true
      4. deny wildcards (most specific → least specific)
      5. * root grant → true
      6. grant wildcards (least specific → most specific)
      7. null (unset)
    • hasPermission

      @Nullable public static Boolean hasPermission(@Nullable Set<String> nodes, @Nonnull PermissionQuery query)
      See Also: