Class PermissionsManager


  • public class PermissionsManager
    extends java.lang.Object
    • Method Detail

      • loadConfig

        public final void loadConfig()
        Loads the configuration of the plugin from the config.yml file.
      • loadPerms

        public final void loadPerms()
        (Re)loads the all groups and online players from file/table.
      • enable

        public void enable()
        Enables the permissions manager.
      • disable

        public void disable()
        Disables the permissions manager.
      • reload

        public void reload()
        Reloads the config and permissions.
      • validateUsersGroups

        @Deprecated
        public void validateUsersGroups()
        Deprecated.
        Validates all loaded groups and users and fixes invalid objects.
      • getMainGroup

        public Group getMainGroup​(User player)
        Get the group of the player with the highesst rank. Do not to be confused with the rank property. The higher the rank the smaller the rank property. (1 is highest rank; 1000 is a low rank)
        Parameters:
        player - the user to get the main group of
        Returns:
        the main group of the user (highest rank)
        Throws:
        java.lang.NullPointerException - if player is null
      • getNextGroup

        public Group getNextGroup​(Group group)
        Gets the next (higher) group in the same ladder.
        Parameters:
        group - the group to get the next group of
        Returns:
        the next group in the same ladder or null if the group has no next group
        Throws:
        java.lang.IllegalArgumentException - if the group ladder does not exist (anymore)
      • getPreviousGroup

        public Group getPreviousGroup​(Group group)
        Gets the previous (lower) group in the same ladder.
        Parameters:
        group - the group to get the previous group of
        Returns:
        the previous group in the same ladder or null if the group has no previous group
        Throws:
        java.lang.IllegalArgumentException - if the group ladder does not exist (anymore)
      • getLadderGroups

        public java.util.List<Group> getLadderGroups​(java.lang.String ladder)
        Gets all groups of the given ladder.
        Parameters:
        ladder - the ladder of the groups to get
        Returns:
        a sorted list of all matched groups
      • getLadders

        public java.util.List<java.lang.String> getLadders()
        Gets a list of all existing ladders.
        Returns:
        a list of all ladders
      • getDefaultGroups

        public java.util.List<Group> getDefaultGroups()
        Gets a list of all groups that are marked as default and given to all users by default.
        Returns:
        a list of default groups
      • getDefaultGroupsString

        public java.util.List<java.lang.String> getDefaultGroupsString()
        Gets a list of all groups that are marked as default and given to all users by default.
        Returns:
        a list of default groups
      • getGroup

        public Group getGroup​(java.lang.String groupname)
        Gets a group by its name.
        Parameters:
        groupname - the name of the group to get
        Returns:
        the found group if any or null
      • getUser

        public User getUser​(java.lang.String usernameoruuid)
        Gets a user by its name. If the user is not loaded it will be loaded.
        Parameters:
        usernameoruuid - the name or the UUID of the user to get
        Returns:
        the found user or null if it does not exist
      • getUser

        public User getUser​(java.lang.String usernameoruuid,
                            boolean loadfromdb)
        Gets a user by its name. If the user is not loaded it will be loaded if loadfromdb is true.
        Parameters:
        usernameoruuid - the name or the UUID of the user to get
        loadfromdb - whether or not to load the user from the database if not already loaded
        Returns:
        the found user or null if it does not exist
      • getUser

        public User getUser​(java.util.UUID uuid)
        Gets a user by its UUID. If the user is not loaded it will be loaded.
        Parameters:
        uuid - the uuid of the user to get
        Returns:
        the found user or null if it does not exist
      • getUser

        public User getUser​(java.util.UUID uuid,
                            boolean loadfromdb)
        Gets a user by its UUID. If the user is not loaded it will be loaded if loadfromdb is true.
        Parameters:
        uuid - the uuid of the user to get
        loadfromdb - whether or not to load the user from the database if not already loaded
        Returns:
        the found user or null if it does not exist
      • createTempUser

        public User createTempUser​(java.lang.String playername,
                                   java.util.UUID uuid)
        Creates a temporary user with the given parameters and adds it to the users cache. The returned user object is no saved to the backend in this function.
        Parameters:
        playername - the name of the temporary user
        uuid - the user of the temporary user
        Returns:
        the created user
      • getGroups

        public java.util.List<Group> getGroups()
        Gets an unmodifiable list of all groups
        Returns:
        an unmodifiable list of all groups
      • getUsers

        public java.util.List<User> getUsers()
        Gets an unmodifiable list of all loaded users
        Returns:
        an unmodifiable list of all loaded users
      • getRegisteredUsers

        public java.util.List<java.lang.String> getRegisteredUsers()
        Gets a list of all users
        Returns:
        a list of all users
      • getRegisteredUsersUUID

        public java.util.Map<java.util.UUID,​java.lang.String> getRegisteredUsersUUID()
        Gets a list of all users and their uuids
        Returns:
        a list of all users
      • getGroupUsers

        public java.util.List<java.lang.String> getGroupUsers​(Group group)
        Gets a list of all user which are in the given group
        Parameters:
        group - the group
        Returns:
        a list of all user which are in the given group
      • getGroupUsersUUID

        public java.util.Map<java.util.UUID,​java.lang.String> getGroupUsersUUID​(Group group)
        Gets a list of all user and their UUIDs which are in the given group
        Parameters:
        group - the group
        Returns:
        a list of all user which are in the given group
      • deleteUser

        public void deleteUser​(User user)
        Deletes a user from cache and database.
        Parameters:
        user - the user to delete
      • deleteGroup

        public void deleteGroup​(Group group)
        Deletes a user from cache and database and validates all groups and users.
        Parameters:
        group - the group the remove
      • addUser

        public void addUser​(User user)
        Adds a user to cache and database.
        Parameters:
        user - the user to add
      • addGroup

        public void addGroup​(Group group)
        Adds a group to cache and database.
        Parameters:
        group - the group to add
      • format

        public void format()
        Formats the permissions backEnd.
      • cleanup

        public int cleanup()
        Cleans the permissions backEnd and wipes 0815 users.
        Returns:
        the number of deleted users
      • addUserGroup

        @Deprecated
        public void addUserGroup​(User user,
                                 Group group)
        Deprecated.
        Adds the given group to the user.
        Parameters:
        user - the user to add the group to
        group - the group to add to the user
      • addUserGroup

        public void addUserGroup​(User user,
                                 Group group,
                                 java.lang.String server,
                                 java.lang.String world)
        Adds the given group to the user.
        Parameters:
        user - the user to add the group to
        group - the group to add to the user
        server - optional: the server
        world - optional: the world
      • addUserTimedGroup

        @Deprecated
        public void addUserTimedGroup​(User user,
                                      TimedValue<Group> group)
        Deprecated.
        Adds the given timed group to the user.
        Parameters:
        user - the user to add the group to
        group - the timed group to add to the user
      • addUserTimedGroup

        public void addUserTimedGroup​(User user,
                                      TimedValue<Group> group,
                                      java.lang.String server,
                                      java.lang.String world)
        Adds the given timed group to the user.
        Parameters:
        user - the user to add the group to
        group - the timed group to add to the user
        server - optional: the server
        world - optional: the world
      • removeUserGroup

        @Deprecated
        public void removeUserGroup​(User user,
                                    Group group)
        Deprecated.
        Removes the given group from the user.
        Parameters:
        user - the user to remove the group from
        group - the group to remove from the user
      • removeUserGroup

        public void removeUserGroup​(User user,
                                    Group group,
                                    java.lang.String server,
                                    java.lang.String world)
        Removes the given group from the user.
        Parameters:
        user - the user to remove the group from
        group - the group to remove from the user
        server - optional: the server
        world - optional: the world
      • removeUserTimedGroup

        @Deprecated
        public void removeUserTimedGroup​(User user,
                                         Group group)
        Deprecated.
        Removes the given timed group from the user.
        Parameters:
        user - the user to remove the group from
        group - the timed group to remove from the user
      • removeUserTimedGroup

        public void removeUserTimedGroup​(User user,
                                         Group group,
                                         java.lang.String server,
                                         java.lang.String world)
        Removes the given timed group from the user.
        Parameters:
        user - the user to remove the group from
        group - the timed group to remove from the user
        server - optional: the server
        world - optional: the world
      • addUserPerm

        @Deprecated
        public void addUserPerm​(User user,
                                java.lang.String perm)
        Deprecated.
        Adds a permission to the user.
        Parameters:
        user - the user to add the permission to
        perm - the permission to add to the user
      • removeUserPerm

        @Deprecated
        public void removeUserPerm​(User user,
                                   java.lang.String perm)
        Deprecated.
        Removes a permission from the user.
        Parameters:
        user - the user to remove the permission from
        perm - the permission to remove from the user
      • addUserPerm

        public void addUserPerm​(User user,
                                java.lang.String server,
                                java.lang.String world,
                                java.lang.String perm)
        Adds a permission to a user.
        Parameters:
        user - the user
        server - optional: the server
        world - optional: the world
        perm - the permission to add
      • addUserTimedPerm

        public void addUserTimedPerm​(User user,
                                     java.lang.String server,
                                     java.lang.String world,
                                     TimedValue perm)
        Adds a timed permission to a user.
        Parameters:
        user - the user
        server - optional: the server
        world - optional: the world
        perm - the timed permission to add
      • removeUserPerm

        public void removeUserPerm​(User user,
                                   java.lang.String server,
                                   java.lang.String world,
                                   java.lang.String perm)
        Removes a permission from a user.
        Parameters:
        user - the user
        server - optional: the server
        world - optional: the world
        perm - the permission to remove
      • removeUserTimedPerm

        public void removeUserTimedPerm​(User user,
                                        java.lang.String server,
                                        java.lang.String world,
                                        java.lang.String perm)
        Removes a timed permission from a user.
        Parameters:
        user - the user
        server - optional: the server
        world - optional: the world
        perm - timed the permission to remove
      • setUserDisplay

        public void setUserDisplay​(User user,
                                   java.lang.String display,
                                   java.lang.String server,
                                   java.lang.String world)
        Sets the displayname of the group
        Parameters:
        user - the user
        display - the display
        server - the server to set the display on; may be null
        world - the world to ser the display in; may be null
      • setUserPrefix

        public void setUserPrefix​(User user,
                                  java.lang.String prefix,
                                  java.lang.String server,
                                  java.lang.String world)
        Sets the prefix for the group.
        Parameters:
        user - the user
        prefix - the prefix
        server - the server to set the prefix on; may be null
        world - the world to ser the prefix in; may be null
      • setUserSuffix

        public void setUserSuffix​(User user,
                                  java.lang.String suffix,
                                  java.lang.String server,
                                  java.lang.String world)
        Sets the suffix for the group.
        Parameters:
        user - the user
        suffix - the suffix
        server - the server to set the suffix on; may be null
        world - the world to ser the suffix in; may be null
      • addGroupPerm

        @Deprecated
        public void addGroupPerm​(Group group,
                                 java.lang.String perm)
        Deprecated.
        Adds a permission to a group.
        Parameters:
        group - the group
        perm - the permission to add
      • removeGroupPerm

        @Deprecated
        public void removeGroupPerm​(Group group,
                                    java.lang.String perm)
        Deprecated.
        Removes a permission from a group.
        Parameters:
        group - the group
        perm - the permission to remove
      • addGroupPerm

        public void addGroupPerm​(Group group,
                                 java.lang.String server,
                                 java.lang.String world,
                                 java.lang.String perm)
        Adds a permission to a group.
        Parameters:
        group - the group
        server - optional: the server
        world - optional: the world
        perm - the permission to add
      • addGroupTimedPerm

        public void addGroupTimedPerm​(Group group,
                                      java.lang.String server,
                                      java.lang.String world,
                                      TimedValue perm)
        Adds a timed permission to a group.
        Parameters:
        group - the group
        server - optional: the server
        world - optional: the world
        perm - the timed permission to add
      • removeGroupPerm

        public void removeGroupPerm​(Group group,
                                    java.lang.String server,
                                    java.lang.String world,
                                    java.lang.String perm)
        Removes a permission from a group.
        Parameters:
        group - the group
        server - optional: the server
        world - optional: the world
        perm - the permission to remove
      • removeGroupTimedPerm

        public void removeGroupTimedPerm​(Group group,
                                         java.lang.String server,
                                         java.lang.String world,
                                         java.lang.String perm)
        Removes a timed permission from a group.
        Parameters:
        group - the group
        server - optional: the server
        world - optional: the world
        perm - the timed permission to remove
      • addGroupInheritance

        @Deprecated
        public void addGroupInheritance​(Group group,
                                        Group toadd)
        Deprecated.
        Adds the toadd group to the group as inheritance
        Parameters:
        group - the group which should inherit
        toadd - the group which should be inherited
      • addGroupInheritance

        public void addGroupInheritance​(Group group,
                                        Group toadd,
                                        java.lang.String server,
                                        java.lang.String world)
        Adds the toadd group to the group as inheritance
        Parameters:
        group - the group which should inherit
        toadd - the group which should be inherited
        server - optional: the server
        world - optional: the world
      • addGroupTimedInheritance

        @Deprecated
        public void addGroupTimedInheritance​(Group group,
                                             TimedValue<Group> toadd)
        Deprecated.
        Adds the toadd timed group to the group as inheritance
        Parameters:
        group - the group which should inherit
        toadd - the timed group which should be inherited
      • addGroupTimedInheritance

        public void addGroupTimedInheritance​(Group group,
                                             TimedValue<Group> toadd,
                                             java.lang.String server,
                                             java.lang.String world)
        Adds the toadd timed group to the group as inheritance
        Parameters:
        group - the group which should inherit
        toadd - the timed group which should be inherited
        server - optional: the server
        world - optional: the world
      • removeGroupInheritance

        @Deprecated
        public void removeGroupInheritance​(Group group,
                                           Group toremove)
        Deprecated.
        Removes the toremove group from the group as inheritance
        Parameters:
        group - the group which should no longer inherit
        toremove - the group which should no longer be inherited
      • removeGroupInheritance

        public void removeGroupInheritance​(Group group,
                                           Group toremove,
                                           java.lang.String server,
                                           java.lang.String world)
        Removes the toremove group from the group as inheritance
        Parameters:
        group - the group which should no longer inherit
        toremove - the group which should no longer be inherited
        server - optional: the server
        world - optional: the world
      • removeGroupTimedInheritance

        @Deprecated
        public void removeGroupTimedInheritance​(Group group,
                                                Group toremove)
        Deprecated.
        Removes the toremove timed group from the group as inheritance
        Parameters:
        group - the group which should no longer inherit
        toremove - the timed group which should no longer be inherited
      • removeGroupTimedInheritance

        public void removeGroupTimedInheritance​(Group group,
                                                Group toremove,
                                                java.lang.String server,
                                                java.lang.String world)
        Removes the toremove timed group from the group as inheritance
        Parameters:
        group - the group which should no longer inherit
        toremove - the timed group which should no longer be inherited
        server - optional: the server
        world - optional: the world
      • ladderGroup

        public void ladderGroup​(Group group,
                                java.lang.String ladder)
        Set the ladder for the group.
        Parameters:
        group - the group
        ladder - the ladder name
      • rankGroup

        public void rankGroup​(Group group,
                              int rank)
        Sets the rank for the group.
        Parameters:
        group - the group
        rank - the rank
      • weightGroup

        public void weightGroup​(Group group,
                                int weight)
        Sets the weight for the group.
        Parameters:
        group - the group
        weight - the weight
      • setGroupDefault

        public void setGroupDefault​(Group group,
                                    boolean isdefault)
        Sets if the the group is a default group.
        Parameters:
        group - the group
        isdefault - whether or not the group is aded by default to new users
      • setGroupDisplay

        public void setGroupDisplay​(Group group,
                                    java.lang.String display,
                                    java.lang.String server,
                                    java.lang.String world)
        Sets the displayname of the group
        Parameters:
        group - the group
        display - the display
        server - the server to set the display on; may be null
        world - the world to ser the display in; may be null
      • setGroupPrefix

        public void setGroupPrefix​(Group group,
                                   java.lang.String prefix,
                                   java.lang.String server,
                                   java.lang.String world)
        Sets the prefix for the group.
        Parameters:
        group - the group
        prefix - the prefix
        server - the server to set the prefix on; may be null
        world - the world to ser the prefix in; may be null
      • setGroupSuffix

        public void setGroupSuffix​(Group group,
                                   java.lang.String suffix,
                                   java.lang.String server,
                                   java.lang.String world)
        Sets the suffix for the group.
        Parameters:
        group - the group
        suffix - the suffix
        server - the server to set the suffix on; may be null
        world - the world to ser the suffix in; may be null
      • migrateBackEnd

        public void migrateBackEnd​(BackEndType bet)
        Migrates the permissions to the given backnd type.
        Parameters:
        bet - the backEnd type to migrate to
      • migrateUseUUID

        public void migrateUseUUID​(java.util.Map<java.lang.String,​java.util.UUID> uuids)
        Converts the permissions database to use UUIDs for player identification.
        Parameters:
        uuids - a map of player names and their corresponding UUIDs
      • migrateUsePlayerNames

        public void migrateUsePlayerNames​(java.util.Map<java.util.UUID,​java.lang.String> playernames)
        Converts the permissions database to use player names for player identification.
        Parameters:
        playernames - a map of UUIDs and their corresponding player names
      • reloadUser

        public void reloadUser​(java.lang.String user)
      • reloadUser

        public void reloadUser​(java.util.UUID uuid)
      • reloadGroup

        public void reloadGroup​(java.lang.String group)
      • reloadUsers

        public void reloadUsers()
      • reloadGroups

        public void reloadGroups()
      • addUserToCache

        public void addUserToCache​(User u)
      • removeUserFromCache

        public void removeUserFromCache​(User u)
      • addGroupToCache

        public void addGroupToCache​(Group g)
      • removeGroupFromCache

        public void removeGroupFromCache​(Group g)