ru.tehkode.permissions
Class PermissionUser

java.lang.Object
  extended by ru.tehkode.permissions.PermissionEntity
      extended by ru.tehkode.permissions.PermissionUser
Direct Known Subclasses:
ProxyPermissionUser

public abstract class PermissionUser
extends PermissionEntity

Author:
code

Field Summary
protected  HashMap<String,String> cachedAnwsers
           
protected  Map<String,List<PermissionGroup>> cachedGroups
           
protected  HashMap<String,String> cachedOptions
           
protected  Map<String,String[]> cachedPermissions
           
protected  Map<String,String> cachedPrefix
           
protected  Map<String,String> cachedSuffix
           
 
Fields inherited from class ru.tehkode.permissions.PermissionEntity
debugMode, manager, patternCache, rangeExpression, timedPermissions, timedPermissionsTime, virtual
 
Constructor Summary
PermissionUser(String playerName, PermissionManager manager)
           
 
Method Summary
 void addGroup(PermissionGroup group)
           
 void addGroup(PermissionGroup group, String worldName)
          Add user to group
 void addGroup(String groupName)
           
 void addGroup(String groupName, String worldName)
          Add user to group
 void addPermission(String permission, String worldName)
          Add permissions for specified world
 void addTimedPermission(String permission, String world, int lifeTime)
          Adds timed permission to specified world in seconds
protected  void clearCache()
           
 PermissionGroup demote(PermissionUser demoter, String ladderName)
          Demotes user in specified ladder.
 boolean explainExpression(String expression)
           
 Map<String,PermissionGroup[]> getAllGroups()
           
 PermissionGroup[] getGroups()
          Get group for this user, global inheritance only
 PermissionGroup[] getGroups(String worldName)
          Get groups for this user for specified world
 String[] getGroupsNames()
          Get group names, common space only
 String[] getGroupsNames(String worldName)
          Get group names in specified world
protected abstract  String[] getGroupsNamesImpl(String worldName)
           
protected  void getInheritedPermissions(String worldName, List<String> permissions, boolean groupInheritance, boolean worldInheritance)
           
 String getMatchingExpression(String permission, String world)
           
 String getOption(String optionName, String worldName, String defaultValue)
          Get option in world
 String getOwnOption(String option)
          Return non-inherited value of specified option in common space (all worlds).
 String getOwnOption(String option, String world)
           
abstract  String getOwnOption(String option, String world, String defaultValue)
          Return non-inherited value of specified option for user in world
 boolean getOwnOptionBoolean(String optionName, String world, boolean defaultValue)
           
 double getOwnOptionDouble(String optionName, String world, double defaultValue)
           
 int getOwnOptionInteger(String optionName, String world, int defaultValue)
           
abstract  String[] getOwnPermissions(String world)
          Return non-inherited permissions of a user in world
 String getOwnPrefix()
          Return non-inherited user prefix.
abstract  String getOwnPrefix(String worldName)
           
 String getOwnSuffix()
          Return non-inherited suffix prefix.
abstract  String getOwnSuffix(String worldName)
           
 String[] getPermissions(String worldName)
          Return all entity permissions in specified world
 String getPrefix(String worldName)
          Returns entity prefix
protected  int getPromoterRankAndCheck(PermissionUser promoter, String ladderName)
           
 int getRank(String ladder)
          Return user rank in specified ladder
 PermissionGroup getRankLadderGroup(String ladder)
          Return user's group in specified ladder
 Map<String,PermissionGroup> getRankLadders()
          Return all ladders the user is participating in
 String getSuffix(String worldName)
          Return entity suffix
protected  PermissionGroup[] getWorldGroups(String worldName)
           
 boolean has(String permission)
          Checks if entity has specified permission in default world
 boolean inGroup(PermissionGroup group)
           
 boolean inGroup(PermissionGroup group, boolean checkInheritance)
           
 boolean inGroup(PermissionGroup group, String worldName)
          Check if this user is member of group or one of its descendant groups
 boolean inGroup(PermissionGroup group, String worldName, boolean checkInheritance)
          Check if this user is member of group or one of its descendant groups (optionally)
 boolean inGroup(String groupName)
           
 boolean inGroup(String groupName, boolean checkInheritance)
           
 boolean inGroup(String groupName, String worldName)
          Checks if this user is member of specified group or one of its descendant groups
 boolean inGroup(String groupName, String worldName, boolean checkInheritance)
          Check if this user is member of group or one of its descendant groups (optionally)
 void initialize()
          This method 100% run after all constructors have been run and entity object, and entity object are completely ready to operate
 boolean isRanked(String ladder)
          Check if the user is in the specified ladder
 PermissionGroup promote(PermissionUser promoter, String ladderName)
          Promotes user in specified ladder.
 void remove()
          Remove entity data from backend
 void removeGroup(PermissionGroup group)
           
 void removeGroup(PermissionGroup group, String worldName)
          Remove user from group
 void removeGroup(String groupName)
           
 void removeGroup(String groupName, String worldName)
          Remove user from group
 void removePermission(String permission, String worldName)
          Remove permission in world
 void removeTimedPermission(String permission, String world)
          Removes specified timed permission for world
 void save()
          Save in-memory data to storage backend
 void setGroups(PermissionGroup[] parentGroups)
           
 void setGroups(PermissionGroup[] parentGroups, String worldName)
          Set parent groups for user
 void setGroups(String[] groups)
           
abstract  void setGroups(String[] groups, String worldName)
          Set parent groups for user
 void setPrefix(String prefix, String worldName)
          Set prefix to value
 void setSuffix(String postfix, String worldName)
          Set suffix to value
protected  void swapGroups(PermissionGroup src, PermissionGroup dst)
           
 
Methods inherited from class ru.tehkode.permissions.PermissionEntity
addPermission, callEvent, callEvent, equals, getAllOptions, getAllPermissions, getMatchingExpression, getName, getOption, getOption, getOptionBoolean, getOptionDouble, getOptionInteger, getOptions, getPrefix, getSuffix, getTimedPermissionLifetime, getTimedPermissions, getWorlds, has, hashCode, isDebug, isMatches, isVirtual, prepareRegexp, removePermission, setDebug, setName, setOption, setOption, setPermissions, setPermissions, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

cachedGroups

protected Map<String,List<PermissionGroup>> cachedGroups

cachedPermissions

protected Map<String,String[]> cachedPermissions

cachedPrefix

protected Map<String,String> cachedPrefix

cachedSuffix

protected Map<String,String> cachedSuffix

cachedAnwsers

protected HashMap<String,String> cachedAnwsers

cachedOptions

protected HashMap<String,String> cachedOptions
Constructor Detail

PermissionUser

public PermissionUser(String playerName,
                      PermissionManager manager)
Method Detail

initialize

public void initialize()
Description copied from class: PermissionEntity
This method 100% run after all constructors have been run and entity object, and entity object are completely ready to operate

Overrides:
initialize in class PermissionEntity

getOwnPrefix

public String getOwnPrefix()
Return non-inherited user prefix. This means if a user don't have has own prefix then empty string or null would be returned

Returns:
prefix as string

getOwnPrefix

public abstract String getOwnPrefix(String worldName)

getOwnSuffix

public final String getOwnSuffix()
Return non-inherited suffix prefix. This means if a user don't has own suffix then empty string or null would be returned

Returns:
suffix as string

getOwnSuffix

public abstract String getOwnSuffix(String worldName)

getOwnPermissions

public abstract String[] getOwnPermissions(String world)
Return non-inherited permissions of a user in world

Parameters:
world - world's name
Returns:
String array of owned Permissions

getOption

public String getOption(String optionName,
                        String worldName,
                        String defaultValue)
Description copied from class: PermissionEntity
Get option in world

Specified by:
getOption in class PermissionEntity
Parameters:
optionName - Name of option
worldName - World to look for
defaultValue - Default value to fallback if no such option was found
Returns:
Value of option as String

getOwnOption

public abstract String getOwnOption(String option,
                                    String world,
                                    String defaultValue)
Return non-inherited value of specified option for user in world

Parameters:
option - option string
world - world's name
defaultValue - default value
Returns:
option value or defaultValue if option is not set

getOwnOption

public String getOwnOption(String option)
Return non-inherited value of specified option in common space (all worlds).

Parameters:
option -
Returns:
option value or empty string if option is not set

getOwnOption

public String getOwnOption(String option,
                           String world)

getOwnOptionInteger

public int getOwnOptionInteger(String optionName,
                               String world,
                               int defaultValue)

getOwnOptionBoolean

public boolean getOwnOptionBoolean(String optionName,
                                   String world,
                                   boolean defaultValue)

getOwnOptionDouble

public double getOwnOptionDouble(String optionName,
                                 String world,
                                 double defaultValue)

getGroupsNamesImpl

protected abstract String[] getGroupsNamesImpl(String worldName)

getGroups

public PermissionGroup[] getGroups()
Get group for this user, global inheritance only

Returns:

getGroups

public PermissionGroup[] getGroups(String worldName)
Get groups for this user for specified world

Parameters:
worldName - Name of world
Returns:
PermissionGroup groups

getAllGroups

public Map<String,PermissionGroup[]> getAllGroups()

getWorldGroups

protected PermissionGroup[] getWorldGroups(String worldName)

getGroupsNames

public String[] getGroupsNames()
Get group names, common space only

Returns:

getGroupsNames

public String[] getGroupsNames(String worldName)
Get group names in specified world

Returns:
String array of user's group names

setGroups

public abstract void setGroups(String[] groups,
                               String worldName)
Set parent groups for user

Parameters:
groups - array of parent group names

setGroups

public void setGroups(String[] groups)

setGroups

public void setGroups(PermissionGroup[] parentGroups,
                      String worldName)
Set parent groups for user

Parameters:
groups - array of parent group objects

setGroups

public void setGroups(PermissionGroup[] parentGroups)

addGroup

public void addGroup(String groupName,
                     String worldName)
Add user to group

Parameters:
groupName - group's name as String

addGroup

public void addGroup(String groupName)

addGroup

public void addGroup(PermissionGroup group,
                     String worldName)
Add user to group

Parameters:
group - as PermissionGroup object

addGroup

public void addGroup(PermissionGroup group)

removeGroup

public void removeGroup(String groupName,
                        String worldName)
Remove user from group

Parameters:
groupName - group's name as String

removeGroup

public void removeGroup(String groupName)

removeGroup

public void removeGroup(PermissionGroup group,
                        String worldName)
Remove user from group

Parameters:
group - group as PermissionGroup object

removeGroup

public void removeGroup(PermissionGroup group)

inGroup

public boolean inGroup(PermissionGroup group,
                       String worldName,
                       boolean checkInheritance)
Check if this user is member of group or one of its descendant groups (optionally)

Parameters:
group - group as PermissionGroup object
worldName -
checkInheritance - if true then descendant groups of the given group would be checked too
Returns:
true on success, false otherwise

inGroup

public boolean inGroup(PermissionGroup group,
                       boolean checkInheritance)

inGroup

public boolean inGroup(String groupName,
                       String worldName,
                       boolean checkInheritance)
Check if this user is member of group or one of its descendant groups (optionally)

Parameters:
groupName - group's name to check
worldName -
checkInheritance - if true than descendant groups of specified group would be checked too
Returns:
true on success, false otherwise

inGroup

public boolean inGroup(String groupName,
                       boolean checkInheritance)

inGroup

public boolean inGroup(PermissionGroup group,
                       String worldName)
Check if this user is member of group or one of its descendant groups

Parameters:
group -
worldName -
Returns:
true on success, false otherwise

inGroup

public boolean inGroup(PermissionGroup group)

inGroup

public boolean inGroup(String groupName,
                       String worldName)
Checks if this user is member of specified group or one of its descendant groups

Parameters:
group - group's name
Returns:
true on success, false otherwise

inGroup

public boolean inGroup(String groupName)

promote

public PermissionGroup promote(PermissionUser promoter,
                               String ladderName)
                        throws RankingException
Promotes user in specified ladder. If user is not member of the ladder RankingException will be thrown If promoter is not null and he is member of the ladder and his rank is lower then user's RankingException will be thrown too. If there is no group to promote the user to RankingException would be thrown

Parameters:
promoter - null if action is performed from console or by a plugin
ladderName - Ladder name
Throws:
RankingException

demote

public PermissionGroup demote(PermissionUser demoter,
                              String ladderName)
                       throws RankingException
Demotes user in specified ladder. If user is not member of the ladder RankingException will be thrown If demoter is not null and he is member of the ladder and his rank is lower then user's RankingException will be thrown too. If there is no group to demote the user to RankingException would be thrown

Parameters:
promoter - Specify null if action performed from console or by plugin
ladderName -
Throws:
RankingException

isRanked

public boolean isRanked(String ladder)
Check if the user is in the specified ladder

Parameters:
ladder - Ladder name
Returns:
true on success, false otherwise

getRank

public int getRank(String ladder)
Return user rank in specified ladder

Parameters:
ladder - Ladder name
Returns:
rank as int

getRankLadderGroup

public PermissionGroup getRankLadderGroup(String ladder)
Return user's group in specified ladder

Parameters:
ladder - Ladder name
Returns:
PermissionGroup object of ranked ladder group

getRankLadders

public Map<String,PermissionGroup> getRankLadders()
Return all ladders the user is participating in

Returns:
Map, key - name of ladder, group - corresponding group of that ladder

getPermissions

public String[] getPermissions(String worldName)
Description copied from class: PermissionEntity
Return all entity permissions in specified world

Specified by:
getPermissions in class PermissionEntity
Parameters:
worldName - World name
Returns:
Array of permission expressions

addPermission

public void addPermission(String permission,
                          String worldName)
Description copied from class: PermissionEntity
Add permissions for specified world

Overrides:
addPermission in class PermissionEntity
Parameters:
permission - Permission to add
worldName - World name to add permission to

removePermission

public void removePermission(String permission,
                             String worldName)
Description copied from class: PermissionEntity
Remove permission in world

Overrides:
removePermission in class PermissionEntity
Parameters:
permission - Permission to remove

getInheritedPermissions

protected void getInheritedPermissions(String worldName,
                                       List<String> permissions,
                                       boolean groupInheritance,
                                       boolean worldInheritance)

addTimedPermission

public void addTimedPermission(String permission,
                               String world,
                               int lifeTime)
Description copied from class: PermissionEntity
Adds timed permission to specified world in seconds

Overrides:
addTimedPermission in class PermissionEntity
lifeTime - Lifetime of permission in seconds. 0 for transient permission (world disappear only after server reload)

removeTimedPermission

public void removeTimedPermission(String permission,
                                  String world)
Description copied from class: PermissionEntity
Removes specified timed permission for world

Overrides:
removeTimedPermission in class PermissionEntity

getPromoterRankAndCheck

protected int getPromoterRankAndCheck(PermissionUser promoter,
                                      String ladderName)
                               throws RankingException
Throws:
RankingException

swapGroups

protected void swapGroups(PermissionGroup src,
                          PermissionGroup dst)

getPrefix

public String getPrefix(String worldName)
Description copied from class: PermissionEntity
Returns entity prefix

Specified by:
getPrefix in class PermissionEntity
Returns:
prefix

has

public boolean has(String permission)
Description copied from class: PermissionEntity
Checks if entity has specified permission in default world

Overrides:
has in class PermissionEntity
Parameters:
permission - Permission to check
Returns:
true if entity has this permission otherwise false

getSuffix

public String getSuffix(String worldName)
Description copied from class: PermissionEntity
Return entity suffix

Specified by:
getSuffix in class PermissionEntity
Returns:
suffix

getMatchingExpression

public String getMatchingExpression(String permission,
                                    String world)
Overrides:
getMatchingExpression in class PermissionEntity

clearCache

protected void clearCache()

setPrefix

public void setPrefix(String prefix,
                      String worldName)
Description copied from class: PermissionEntity
Set prefix to value

Specified by:
setPrefix in class PermissionEntity
Parameters:
prefix - new prefix

setSuffix

public void setSuffix(String postfix,
                      String worldName)
Description copied from class: PermissionEntity
Set suffix to value

Specified by:
setSuffix in class PermissionEntity
Parameters:
postfix - new suffix

remove

public void remove()
Description copied from class: PermissionEntity
Remove entity data from backend

Specified by:
remove in class PermissionEntity

save

public void save()
Description copied from class: PermissionEntity
Save in-memory data to storage backend

Specified by:
save in class PermissionEntity

explainExpression

public boolean explainExpression(String expression)
Overrides:
explainExpression in class PermissionEntity


Copyright © 2011. All Rights Reserved.