2011-03-19 22:39:51 +00:00
/ *
* To change this template , choose Tools | Templates
* and open the template in the editor .
* /
package org.anjocaido.groupmanager.dataholder ;
import java.io.File ;
import java.io.FileInputStream ;
import java.io.FileNotFoundException ;
2011-04-10 22:55:11 +00:00
import java.io.FileOutputStream ;
2011-03-19 22:39:51 +00:00
import java.io.IOException ;
2011-04-10 22:55:11 +00:00
import java.io.OutputStreamWriter ;
import java.io.UnsupportedEncodingException ;
2011-03-19 22:39:51 +00:00
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.HashMap ;
2012-04-07 18:24:46 +00:00
import java.util.Iterator ;
2011-03-19 22:39:51 +00:00
import java.util.List ;
import java.util.Map ;
import java.util.logging.Level ;
import java.util.logging.Logger ;
import org.anjocaido.groupmanager.GroupManager ;
import org.anjocaido.groupmanager.data.Group ;
import org.anjocaido.groupmanager.data.User ;
2011-12-13 17:13:53 +00:00
import org.anjocaido.groupmanager.events.GMGroupEvent ;
import org.anjocaido.groupmanager.events.GMSystemEvent ;
import org.anjocaido.groupmanager.events.GMUserEvent ;
import org.anjocaido.groupmanager.events.GMUserEvent.Action ;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler ;
2011-03-19 22:39:51 +00:00
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler ;
import org.bukkit.Server ;
import org.bukkit.plugin.Plugin ;
import org.bukkit.plugin.PluginManager ;
import org.yaml.snakeyaml.DumperOptions ;
import org.yaml.snakeyaml.Yaml ;
import org.yaml.snakeyaml.constructor.SafeConstructor ;
import org.yaml.snakeyaml.reader.UnicodeReader ;
/ * *
2012-02-05 16:41:34 +00:00
* One instance of this should exist per world / mirror
* it contains all functions to manage these data sets
* and points to the relevant users and groups objects .
*
* @author gabrielcouto , ElgarL
2011-03-19 22:39:51 +00:00
* /
public class WorldDataHolder {
/ * *
2011-11-05 15:41:40 +00:00
* World name
2011-03-19 22:39:51 +00:00
* /
protected String name ;
/ * *
2011-08-14 19:56:40 +00:00
* The actual groups holder
2011-03-19 22:39:51 +00:00
* /
2012-01-11 05:51:40 +00:00
protected GroupsDataHolder groups = new GroupsDataHolder ( ) ;
2011-11-02 22:33:29 +00:00
/ * *
2011-03-19 22:39:51 +00:00
* The actual users holder
* /
2012-01-11 05:51:40 +00:00
protected UsersDataHolder users = new UsersDataHolder ( ) ;
2011-03-19 22:39:51 +00:00
/ * *
*
* /
protected AnjoPermissionsHandler permissionsHandler ;
2011-11-02 22:33:29 +00:00
/ * *
2011-08-14 19:56:40 +00:00
* Prevent direct instantiation
2011-03-19 22:39:51 +00:00
* @param worldName
* /
2012-01-11 05:51:40 +00:00
public WorldDataHolder ( String worldName ) {
2011-03-19 22:39:51 +00:00
name = worldName ;
}
/ * *
* The main constructor for a new WorldDataHolder
* @param worldName
2012-01-11 05:51:40 +00:00
* @param groups
* @param users
2011-03-19 22:39:51 +00:00
* /
2012-01-11 05:51:40 +00:00
public WorldDataHolder ( String worldName , GroupsDataHolder groups , UsersDataHolder users ) {
2011-03-19 22:39:51 +00:00
this . name = worldName ;
2012-01-11 05:51:40 +00:00
this . groups = groups ;
this . users = users ;
//this.defaultGroup = defaultGroup;
2011-03-19 22:39:51 +00:00
}
2012-02-05 16:30:58 +00:00
/ * *
* update the dataSource to point to this object .
*
* This should be called whenever a set of world data is fetched .
* /
public void updateDataSource ( ) {
this . groups . setDataSource ( this ) ;
this . users . setDataSource ( this ) ;
}
2011-03-19 22:39:51 +00:00
/ * *
* Search for a user . If it doesn ' t exist , create a new one with
* default group .
*
* @param userName the name of the user
* @return class that manage that user permission
* /
public User getUser ( String userName ) {
2012-01-11 05:51:40 +00:00
if ( getUsers ( ) . containsKey ( userName . toLowerCase ( ) ) ) {
return getUsers ( ) . get ( userName . toLowerCase ( ) ) ;
2011-03-19 22:39:51 +00:00
}
User newUser = createUser ( userName ) ;
return newUser ;
}
/ * *
2011-08-14 19:56:40 +00:00
* Add a user to the list . If it already exists , overwrite the old .
2011-03-19 22:39:51 +00:00
* @param theUser the user you want to add to the permission list
* /
public void addUser ( User theUser ) {
if ( theUser . getDataSource ( ) ! = this ) {
theUser = theUser . clone ( this ) ;
}
if ( theUser = = null ) {
return ;
}
if ( ( theUser . getGroup ( ) = = null ) ) {
2012-01-11 05:51:40 +00:00
theUser . setGroup ( groups . getDefaultGroup ( ) ) ;
2011-03-19 22:39:51 +00:00
}
removeUser ( theUser . getName ( ) ) ;
2012-01-11 05:51:40 +00:00
getUsers ( ) . put ( theUser . getName ( ) . toLowerCase ( ) , theUser ) ;
setUsersChanged ( true ) ;
2011-12-13 17:13:53 +00:00
if ( GroupManager . isLoaded ( ) )
GroupManagerEventHandler . callEvent ( theUser , Action . USER_ADDED ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
* Removes the user from the list . ( he might become a default user )
* @param userName the username from the user to remove
* @return true if it had something to remove
* /
public boolean removeUser ( String userName ) {
2012-01-11 05:51:40 +00:00
if ( getUsers ( ) . containsKey ( userName . toLowerCase ( ) ) ) {
getUsers ( ) . remove ( userName . toLowerCase ( ) ) ;
setUsersChanged ( true ) ;
2011-12-13 17:13:53 +00:00
if ( GroupManager . isLoaded ( ) )
GroupManagerEventHandler . callEvent ( userName , GMUserEvent . Action . USER_REMOVED ) ;
2011-03-19 22:39:51 +00:00
return true ;
}
return false ;
}
/ * *
*
* @param userName
2011-11-04 09:36:11 +00:00
* @return true if we have data for this player .
2011-03-19 22:39:51 +00:00
* /
public boolean isUserDeclared ( String userName ) {
2012-01-11 05:51:40 +00:00
return getUsers ( ) . containsKey ( userName . toLowerCase ( ) ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-08-14 19:56:40 +00:00
* Change the default group of the file .
2011-03-19 22:39:51 +00:00
* @param group the group you want make default .
* /
public void setDefaultGroup ( Group group ) {
2012-01-11 05:51:40 +00:00
if ( ! getGroups ( ) . containsKey ( group . getName ( ) . toLowerCase ( ) ) | | ( group . getDataSource ( ) ! = this ) ) {
2011-03-19 22:39:51 +00:00
addGroup ( group ) ;
}
2012-01-11 05:51:40 +00:00
groups . setDefaultGroup ( getGroup ( group . getName ( ) ) ) ;
setGroupsChanged ( true ) ;
2011-12-13 17:13:53 +00:00
if ( GroupManager . isLoaded ( ) )
GroupManagerEventHandler . callEvent ( GMSystemEvent . Action . DEFAULT_GROUP_CHANGED ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-08-14 19:56:40 +00:00
* Returns the default group of the file
2011-03-19 22:39:51 +00:00
* @return the default group
* /
public Group getDefaultGroup ( ) {
2012-01-11 05:51:40 +00:00
return groups . getDefaultGroup ( ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-08-14 19:56:40 +00:00
* Returns a group of the given name
2011-03-19 22:39:51 +00:00
* @param groupName the name of the group
* @return a group if it is found . null if not found .
* /
public Group getGroup ( String groupName ) {
2011-11-29 02:32:09 +00:00
if ( groupName . toLowerCase ( ) . startsWith ( " g: " ) )
2011-10-31 08:34:07 +00:00
return GroupManager . getGlobalGroups ( ) . getGroup ( groupName ) ;
else
2012-01-11 05:51:40 +00:00
return getGroups ( ) . get ( groupName . toLowerCase ( ) ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-08-14 19:56:40 +00:00
* Check if a group exists .
2011-03-19 22:39:51 +00:00
* Its the same of getGroup , but check if it is null .
* @param groupName the name of the group
* @return true if exists . false if not .
* /
public boolean groupExists ( String groupName ) {
2011-11-29 02:32:09 +00:00
if ( groupName . toLowerCase ( ) . startsWith ( " g: " ) )
2011-10-31 08:34:07 +00:00
return GroupManager . getGlobalGroups ( ) . hasGroup ( groupName ) ;
else
2012-01-11 05:51:40 +00:00
return getGroups ( ) . containsKey ( groupName . toLowerCase ( ) ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
* Add a group to the list
* @param groupToAdd
* /
public void addGroup ( Group groupToAdd ) {
2011-11-29 02:32:09 +00:00
if ( groupToAdd . getName ( ) . toLowerCase ( ) . startsWith ( " g: " ) ) {
2011-10-31 17:23:24 +00:00
GroupManager . getGlobalGroups ( ) . addGroup ( groupToAdd ) ;
2011-12-13 17:13:53 +00:00
GroupManagerEventHandler . callEvent ( groupToAdd , GMGroupEvent . Action . GROUP_ADDED ) ;
2011-10-31 17:23:24 +00:00
return ;
}
2011-03-19 22:39:51 +00:00
if ( groupToAdd . getDataSource ( ) ! = this ) {
groupToAdd = groupToAdd . clone ( this ) ;
}
removeGroup ( groupToAdd . getName ( ) ) ;
2012-01-11 05:51:40 +00:00
getGroups ( ) . put ( groupToAdd . getName ( ) . toLowerCase ( ) , groupToAdd ) ;
setGroupsChanged ( true ) ;
2011-12-13 17:13:53 +00:00
if ( GroupManager . isLoaded ( ) )
GroupManagerEventHandler . callEvent ( groupToAdd , GMGroupEvent . Action . GROUP_ADDED ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-12-13 17:13:53 +00:00
* Remove the group from the list
2011-03-19 22:39:51 +00:00
* @param groupName
* @return true if had something to remove . false the group was default or non - existant
* /
public boolean removeGroup ( String groupName ) {
2011-11-29 02:32:09 +00:00
if ( groupName . toLowerCase ( ) . startsWith ( " g: " ) ) {
2011-10-31 08:34:07 +00:00
return GroupManager . getGlobalGroups ( ) . removeGroup ( groupName ) ;
}
2012-01-11 05:51:40 +00:00
if ( getDefaultGroup ( ) ! = null & & groupName . equalsIgnoreCase ( getDefaultGroup ( ) . getName ( ) ) ) {
2011-03-19 22:39:51 +00:00
return false ;
}
2012-01-11 05:51:40 +00:00
if ( getGroups ( ) . containsKey ( groupName . toLowerCase ( ) ) ) {
getGroups ( ) . remove ( groupName . toLowerCase ( ) ) ;
setGroupsChanged ( true ) ;
2011-12-13 17:13:53 +00:00
if ( GroupManager . isLoaded ( ) )
GroupManagerEventHandler . callEvent ( groupName . toLowerCase ( ) , GMGroupEvent . Action . GROUP_REMOVED ) ;
2011-03-19 22:39:51 +00:00
return true ;
}
return false ;
}
/ * *
* Creates a new User with the given name
* and adds it to this holder .
* @param userName the username you want
* @return null if user already exists . or new User
* /
public User createUser ( String userName ) {
2012-01-11 05:51:40 +00:00
if ( getUsers ( ) . containsKey ( userName . toLowerCase ( ) ) ) {
2011-03-19 22:39:51 +00:00
return null ;
}
User newUser = new User ( this , userName ) ;
2012-01-25 23:44:14 +00:00
newUser . setGroup ( groups . getDefaultGroup ( ) , false ) ;
2012-01-11 05:51:40 +00:00
addUser ( newUser ) ;
setUsersChanged ( true ) ;
2011-03-19 22:39:51 +00:00
return newUser ;
}
/ * *
* Creates a new Group with the given name
* and adds it to this holder
* @param groupName the groupname you want
* @return null if group already exists . or new Group
* /
public Group createGroup ( String groupName ) {
2011-11-29 02:32:09 +00:00
if ( groupName . toLowerCase ( ) . startsWith ( " g: " ) ) {
2011-10-31 08:34:07 +00:00
Group newGroup = new Group ( groupName ) ;
2011-10-31 17:23:24 +00:00
return GroupManager . getGlobalGroups ( ) . newGroup ( newGroup ) ;
2011-10-31 08:34:07 +00:00
}
2012-01-11 05:51:40 +00:00
if ( getGroups ( ) . containsKey ( groupName . toLowerCase ( ) ) ) {
2011-03-19 22:39:51 +00:00
return null ;
}
2011-10-31 08:34:07 +00:00
Group newGroup = new Group ( this , groupName ) ;
2012-01-11 05:51:40 +00:00
addGroup ( newGroup ) ;
setGroupsChanged ( true ) ;
2011-03-19 22:39:51 +00:00
return newGroup ;
}
/ * *
*
* @return a collection of the groups
* /
public Collection < Group > getGroupList ( ) {
2012-01-11 05:51:40 +00:00
return getGroups ( ) . values ( ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
*
* @return a collection of the users
* /
public Collection < User > getUserList ( ) {
2012-01-11 05:51:40 +00:00
return getUsers ( ) . values ( ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-08-14 19:56:40 +00:00
* reads the file again
2011-03-19 22:39:51 +00:00
* /
public void reload ( ) {
try {
2011-11-02 22:33:29 +00:00
reloadGroups ( ) ;
reloadUsers ( ) ;
2011-03-19 22:39:51 +00:00
} catch ( Exception ex ) {
Logger . getLogger ( WorldDataHolder . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ;
}
}
2011-11-02 22:33:29 +00:00
2011-11-05 15:41:40 +00:00
/ * *
* Refresh Group data from file
* /
2011-11-02 22:33:29 +00:00
public void reloadGroups ( ) {
GroupManager . setLoaded ( false ) ;
try {
2011-11-04 23:13:42 +00:00
// temporary holder in case the load fails.
WorldDataHolder ph = new WorldDataHolder ( this . getName ( ) ) ;
2011-11-05 15:41:40 +00:00
2011-11-04 23:13:42 +00:00
loadGroups ( ph , getGroupsFile ( ) ) ;
2011-11-05 15:41:40 +00:00
// transfer new data
resetGroups ( ) ;
for ( Group tempGroup : ph . getGroupList ( ) ) {
2011-11-07 15:33:15 +00:00
tempGroup . clone ( this ) ;
2011-11-05 15:41:40 +00:00
}
2012-01-11 05:51:40 +00:00
this . setDefaultGroup ( getGroup ( ph . getDefaultGroup ( ) . getName ( ) ) ) ;
2011-11-04 23:13:42 +00:00
this . removeGroupsChangedFlag ( ) ;
2012-01-11 05:51:40 +00:00
this . setTimeStampGroups ( getGroupsFile ( ) . lastModified ( ) ) ;
2011-11-07 15:33:15 +00:00
ph = null ;
2011-11-02 22:33:29 +00:00
} catch ( Exception ex ) {
2011-11-05 15:41:40 +00:00
Logger . getLogger ( WorldDataHolder . class . getName ( ) ) . log ( Level . WARNING , null , ex ) ;
2011-11-02 22:33:29 +00:00
}
GroupManager . setLoaded ( true ) ;
2011-12-13 17:13:53 +00:00
GroupManagerEventHandler . callEvent ( GMSystemEvent . Action . RELOADED ) ;
2011-11-02 22:33:29 +00:00
}
2011-11-05 15:41:40 +00:00
/ * *
* Refresh Users data from file
* /
2011-11-02 22:33:29 +00:00
public void reloadUsers ( ) {
GroupManager . setLoaded ( false ) ;
try {
2011-11-04 23:13:42 +00:00
// temporary holder in case the load fails.
WorldDataHolder ph = new WorldDataHolder ( this . getName ( ) ) ;
2011-11-05 15:41:40 +00:00
// copy groups for reference
for ( Group tempGroup : this . getGroupList ( ) ) {
2011-11-07 15:33:15 +00:00
tempGroup . clone ( ph ) ;
2011-11-05 15:41:40 +00:00
}
// setup the default group before loading user data.
2012-01-11 05:51:40 +00:00
ph . setDefaultGroup ( ph . getGroup ( getDefaultGroup ( ) . getName ( ) ) ) ;
2011-11-04 23:13:42 +00:00
loadUsers ( ph , getUsersFile ( ) ) ;
2011-11-05 15:41:40 +00:00
// transfer new data
resetUsers ( ) ;
for ( User tempUser : ph . getUserList ( ) ) {
tempUser . clone ( this ) ;
}
2011-11-04 23:13:42 +00:00
this . removeUsersChangedFlag ( ) ;
2012-01-11 05:51:40 +00:00
this . setTimeStampUsers ( getUsersFile ( ) . lastModified ( ) ) ;
2011-11-07 15:33:15 +00:00
ph = null ;
2011-11-02 22:33:29 +00:00
} catch ( Exception ex ) {
2011-11-05 15:41:40 +00:00
Logger . getLogger ( WorldDataHolder . class . getName ( ) ) . log ( Level . WARNING , null , ex ) ;
2011-11-02 22:33:29 +00:00
}
GroupManager . setLoaded ( true ) ;
2011-12-13 17:13:53 +00:00
GroupManagerEventHandler . callEvent ( GMSystemEvent . Action . RELOADED ) ;
2011-11-02 22:33:29 +00:00
}
2011-03-19 22:39:51 +00:00
2012-01-11 05:51:40 +00:00
public void loadGroups ( File groupsFile ) {
2011-03-19 22:39:51 +00:00
2012-01-11 05:51:40 +00:00
GroupManager . setLoaded ( false ) ;
try {
setGroupsFile ( groupsFile ) ;
loadGroups ( this , groupsFile ) ;
} catch ( FileNotFoundException e ) {
e . printStackTrace ( ) ;
throw new IllegalArgumentException ( " The file which should contain groups does not exist! \ n " + groupsFile . getPath ( ) ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
throw new IllegalArgumentException ( " Error access the groups file! \ n " + groupsFile . getPath ( ) ) ;
}
2011-03-19 22:39:51 +00:00
2012-01-11 05:51:40 +00:00
GroupManager . setLoaded ( true ) ;
}
public void loadUsers ( File usersFile ) {
2011-03-19 22:39:51 +00:00
2012-01-11 05:51:40 +00:00
GroupManager . setLoaded ( false ) ;
try {
setUsersFile ( usersFile ) ;
loadUsers ( this , usersFile ) ;
} catch ( FileNotFoundException e ) {
e . printStackTrace ( ) ;
throw new IllegalArgumentException ( " The file which should contain users does not exist! \ n " + usersFile . getPath ( ) ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
throw new IllegalArgumentException ( " Error access the users file! \ n " + usersFile . getPath ( ) ) ;
}
2011-03-19 22:39:51 +00:00
2012-01-11 05:51:40 +00:00
GroupManager . setLoaded ( true ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-11-02 22:33:29 +00:00
* Returns a NEW data holder containing data read from the files
*
2011-03-19 22:39:51 +00:00
* @param worldName
* @param groupsFile
* @param usersFile
2011-11-04 09:36:11 +00:00
*
2011-03-19 22:39:51 +00:00
* @throws FileNotFoundException
* @throws IOException
* /
public static WorldDataHolder load ( String worldName , File groupsFile , File usersFile ) throws FileNotFoundException , IOException {
2011-11-02 22:33:29 +00:00
WorldDataHolder ph = new WorldDataHolder ( worldName ) ;
GroupManager . setLoaded ( false ) ;
2012-01-11 05:51:40 +00:00
if ( groupsFile ! = null ) loadGroups ( ph , groupsFile ) ;
if ( usersFile ! = null ) loadUsers ( ph , usersFile ) ;
2011-11-02 22:33:29 +00:00
GroupManager . setLoaded ( true ) ;
return ph ;
}
/ * *
* Updates the WorldDataHolder from the Groups file
*
2011-11-04 09:36:11 +00:00
* @param ph
2011-11-02 22:33:29 +00:00
* @param groupsFile
2011-11-04 09:36:11 +00:00
*
2011-11-02 22:33:29 +00:00
* @throws FileNotFoundException
* @throws IOException
* /
@SuppressWarnings ( { " rawtypes " , " unchecked " } )
protected static void loadGroups ( WorldDataHolder ph , File groupsFile ) throws FileNotFoundException , IOException {
2011-03-19 22:39:51 +00:00
//READ GROUPS FILE
Yaml yamlGroups = new Yaml ( new SafeConstructor ( ) ) ;
Map < String , Object > groupsRootDataNode ;
if ( ! groupsFile . exists ( ) ) {
2011-11-02 22:33:29 +00:00
throw new IllegalArgumentException ( " The file which should contain groups does not exist! \ n " + groupsFile . getPath ( ) ) ;
2011-03-19 22:39:51 +00:00
}
FileInputStream groupsInputStream = new FileInputStream ( groupsFile ) ;
try {
groupsRootDataNode = ( Map < String , Object > ) yamlGroups . load ( new UnicodeReader ( groupsInputStream ) ) ;
if ( groupsRootDataNode = = null ) {
throw new NullPointerException ( ) ;
}
} catch ( Exception ex ) {
throw new IllegalArgumentException ( " The following file couldn't pass on Parser. \ n " + groupsFile . getPath ( ) , ex ) ;
} finally {
groupsInputStream . close ( ) ;
}
//PROCESS GROUPS FILE
Map < String , List < String > > inheritance = new HashMap < String , List < String > > ( ) ;
2012-01-31 03:16:34 +00:00
try {
2012-04-07 18:24:46 +00:00
/ *
* Fetch all child nodes under the ' groups ' entry .
* /
2011-03-19 22:39:51 +00:00
Map < String , Object > allGroupsNode = ( Map < String , Object > ) groupsRootDataNode . get ( " groups " ) ;
2012-04-07 18:24:46 +00:00
Iterator < String > groupItr = allGroupsNode . keySet ( ) . iterator ( ) ;
String groupKey ;
Integer groupCount = 0 ;
/ *
* loop each group entry
* and read it ' s data .
* /
while ( groupItr . hasNext ( ) ) {
try {
groupCount + + ;
// Attempt to fetch the next group name.
groupKey = groupItr . next ( ) ;
} catch ( Exception e ) {
throw new IllegalArgumentException ( " Invalid node type for group entry ( " + groupCount + " ) in file: " + groupsFile . getPath ( ) ) ;
}
/ *
* Fetch this groups child nodes
* /
Map < String , Object > thisGroupNode = ( Map < String , Object > ) allGroupsNode . get ( groupKey ) ;
/ *
* Create a new group with this name
* in the assigned data source .
* /
Group thisGrp = ph . createGroup ( groupKey ) ;
if ( thisGrp = = null ) {
throw new IllegalArgumentException ( " I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile . getPath ( ) ) ;
}
/ *
* If no default node is found set it as false .
* /
if ( thisGroupNode . get ( " default " ) = = null ) {
thisGroupNode . put ( " default " , false ) ;
} else if ( ( Boolean . parseBoolean ( thisGroupNode . get ( " default " ) . toString ( ) ) ) ) {
/ *
* Set this as the default group .
* Warn if some other group has already claimed that position .
* /
if ( ph . getDefaultGroup ( ) ! = null ) {
GroupManager . logger . warning ( " The group " + thisGrp . getName ( ) + " is claiming to be default where " + ph . getDefaultGroup ( ) . getName ( ) + " already was. " ) ;
GroupManager . logger . warning ( " Overriding first request for file: " + groupsFile . getPath ( ) ) ;
}
ph . setDefaultGroup ( thisGrp ) ;
}
//PERMISSIONS NODE
try {
/ *
* If no permissions node is found , or it ' s empty
* set an empty permission list
* /
if ( thisGroupNode . get ( " permissions " ) = = null ) {
thisGroupNode . put ( " permissions " , new ArrayList < String > ( ) ) ;
} else {
/ *
* There is a permission list Which seems to hold some data
* /
if ( thisGroupNode . get ( " permissions " ) instanceof List ) {
/ *
* Check each entry and add it as a new permission .
* /
for ( Object o : ( ( List ) thisGroupNode . get ( " permissions " ) ) ) {
try {
/ *
* Only add this permission if it ' s not empty .
* /
if ( ! thisGroupNode . get ( " permissions " ) . toString ( ) . isEmpty ( ) )
thisGrp . addPermission ( o . toString ( ) ) ;
} catch ( NullPointerException e ) {
// Ignore this entry as it's null. It can be safely dropped
}
}
} else if ( thisGroupNode . get ( " permissions " ) instanceof String ) {
/ *
* Only add this permission if it ' s not empty .
* /
if ( ! thisGroupNode . get ( " permissions " ) . toString ( ) . isEmpty ( ) )
thisGrp . addPermission ( ( String ) thisGroupNode . get ( " permissions " ) ) ;
2012-02-05 16:30:58 +00:00
} else {
2012-04-07 18:24:46 +00:00
throw new IllegalArgumentException ( " Unknown type of permissions node(Should be String or List<String>) for group: " + thisGrp . getName ( ) + " in file: " + groupsFile . getPath ( ) ) ;
2012-02-05 16:30:58 +00:00
}
2012-04-07 18:24:46 +00:00
/ *
* Sort all permissions so they are in the correct order for checking .
* /
thisGrp . sortPermissions ( ) ;
2012-01-30 14:41:19 +00:00
}
2012-04-07 18:24:46 +00:00
} catch ( Exception e ) {
throw new IllegalArgumentException ( " Invalid formatting found in permissions section for group: " + thisGrp . getName ( ) + " in file: " + groupsFile . getPath ( ) ) ;
}
//INFO NODE
try {
if ( thisGroupNode . get ( " info " ) instanceof Map ) {
Map < String , Object > infoNode = ( Map < String , Object > ) thisGroupNode . get ( " info " ) ;
if ( infoNode ! = null ) {
thisGrp . setVariables ( infoNode ) ;
}
} else
throw new IllegalArgumentException ( " Unknown entry found in Info section for group: " + thisGrp . getName ( ) + " in file: " + groupsFile . getPath ( ) ) ;
} catch ( Exception e1 ) {
throw new IllegalArgumentException ( " Invalid formatting found in info section for group: " + thisGrp . getName ( ) + " in file: " + groupsFile . getPath ( ) ) ;
}
//END INFO NODE
try {
if ( thisGroupNode . get ( " inheritance " ) = = null | | thisGroupNode . get ( " inheritance " ) instanceof List ) {
Object inheritNode = thisGroupNode . get ( " inheritance " ) ;
if ( inheritNode = = null ) {
thisGroupNode . put ( " inheritance " , new ArrayList < String > ( ) ) ;
} else if ( inheritNode instanceof List ) {
List < String > groupsInh = ( List < String > ) inheritNode ;
for ( String grp : groupsInh ) {
if ( inheritance . get ( groupKey ) = = null ) {
List < String > thisInherits = new ArrayList < String > ( ) ;
inheritance . put ( groupKey , thisInherits ) ;
}
inheritance . get ( groupKey ) . add ( grp ) ;
}
}
} else
throw new IllegalArgumentException ( " Unknown entry found in inheritance section for group: " + thisGrp . getName ( ) + " in file: " + groupsFile . getPath ( ) ) ;
} catch ( Exception e2 ) {
throw new IllegalArgumentException ( " Invalid formatting found in inheritance section for group: " + thisGrp . getName ( ) + " in file: " + groupsFile . getPath ( ) ) ;
}
}
2012-01-31 03:16:34 +00:00
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
throw new IllegalArgumentException ( " Your " + groupsFile . getPath ( ) + " file is invalid. See console for details. " ) ;
}
2012-01-11 05:51:40 +00:00
if ( ph . getDefaultGroup ( ) = = null ) {
2011-11-27 03:12:28 +00:00
throw new IllegalArgumentException ( " There was no Default Group declared in file: " + groupsFile . getPath ( ) ) ;
2011-03-19 22:39:51 +00:00
}
for ( String groupKey : inheritance . keySet ( ) ) {
List < String > inheritedList = inheritance . get ( groupKey ) ;
Group thisGroup = ph . getGroup ( groupKey ) ;
for ( String inheritedKey : inheritedList ) {
2012-04-03 13:30:27 +00:00
if ( inheritedKey ! = null ) {
Group inheritedGroup = ph . getGroup ( inheritedKey ) ;
if ( thisGroup ! = null & & inheritedGroup ! = null ) {
thisGroup . addInherits ( inheritedGroup ) ;
}
}
2011-03-19 22:39:51 +00:00
}
}
2011-11-02 22:33:29 +00:00
ph . removeGroupsChangedFlag ( ) ;
// Update the LastModified time.
2012-01-11 05:51:40 +00:00
ph . setGroupsFile ( groupsFile ) ;
2011-11-07 01:59:12 +00:00
ph . setTimeStampGroups ( groupsFile . lastModified ( ) ) ;
2011-03-19 22:39:51 +00:00
2011-11-02 22:33:29 +00:00
//return ph;
}
/ * *
* Updates the WorldDataHolder from the Users file
*
2011-11-04 09:36:11 +00:00
* @param ph
2011-11-02 22:33:29 +00:00
* @param usersFile
2011-11-04 09:36:11 +00:00
*
2011-11-02 22:33:29 +00:00
* @throws FileNotFoundException
* @throws IOException
* /
@SuppressWarnings ( { " rawtypes " , " unchecked " } )
protected static void loadUsers ( WorldDataHolder ph , File usersFile ) throws FileNotFoundException , IOException {
2011-03-19 22:39:51 +00:00
//READ USERS FILE
Yaml yamlUsers = new Yaml ( new SafeConstructor ( ) ) ;
Map < String , Object > usersRootDataNode ;
2011-11-02 22:33:29 +00:00
if ( ! usersFile . exists ( ) ) {
throw new IllegalArgumentException ( " The file which should contain users does not exist! \ n " + usersFile . getPath ( ) ) ;
2011-03-19 22:39:51 +00:00
}
FileInputStream usersInputStream = new FileInputStream ( usersFile ) ;
try {
usersRootDataNode = ( Map < String , Object > ) yamlUsers . load ( new UnicodeReader ( usersInputStream ) ) ;
if ( usersRootDataNode = = null ) {
throw new NullPointerException ( ) ;
}
} catch ( Exception ex ) {
2011-04-30 18:12:46 +00:00
throw new IllegalArgumentException ( " The following file couldn't pass on Parser. \ n " + usersFile . getPath ( ) , ex ) ;
2011-03-19 22:39:51 +00:00
} finally {
usersInputStream . close ( ) ;
}
// PROCESS USERS FILE
Map < String , Object > allUsersNode = ( Map < String , Object > ) usersRootDataNode . get ( " users " ) ;
2011-09-03 15:13:43 +00:00
2011-11-21 09:51:31 +00:00
// Load users if the file is NOT empty
2012-04-07 18:24:46 +00:00
if ( allUsersNode ! = null ) {
Iterator < String > usersItr = allUsersNode . keySet ( ) . iterator ( ) ;
String usersKey ;
Integer userCount = 0 ;
while ( usersItr . hasNext ( ) ) {
try {
userCount + + ;
// Attempt to fetch the next user name.
usersKey = usersItr . next ( ) ;
} catch ( Exception e ) {
throw new IllegalArgumentException ( " Invalid node type for user entry ( " + userCount + " ) in file: " + usersFile . getPath ( ) ) ;
}
Map < String , Object > thisUserNode = null ;
try {
thisUserNode = ( Map < String , Object > ) allUsersNode . get ( usersKey ) ;
} catch ( Exception ex ) {
throw new IllegalArgumentException ( " Bad format found in file: " + usersFile . getPath ( ) ) ;
}
User thisUser = ph . createUser ( usersKey ) ;
if ( thisUser = = null ) {
throw new IllegalArgumentException ( " I think this user was declared more than once: " + usersKey + " in file: " + usersFile . getPath ( ) ) ;
}
if ( thisUserNode . get ( " permissions " ) = = null ) {
thisUserNode . put ( " permissions " , new ArrayList < String > ( ) ) ;
} else {
if ( thisUserNode . get ( " permissions " ) instanceof List ) {
for ( Object o : ( ( List ) thisUserNode . get ( " permissions " ) ) ) {
/ *
* Only add this permission if it ' s not empty
* /
if ( ! o . toString ( ) . isEmpty ( ) )
thisUser . addPermission ( o . toString ( ) ) ;
2012-03-29 13:02:53 +00:00
}
2012-04-07 18:24:46 +00:00
} else if ( thisUserNode . get ( " permissions " ) instanceof String ) {
try {
/ *
* Only add this permission if it ' s not empty
* /
if ( ! thisUserNode . get ( " permissions " ) . toString ( ) . isEmpty ( ) )
thisUser . addPermission ( thisUserNode . get ( " permissions " ) . toString ( ) ) ;
} catch ( NullPointerException e ) {
// Ignore this entry as it's null.
//throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath());
}
2012-03-29 13:02:53 +00:00
}
2012-04-07 18:24:46 +00:00
thisUser . sortPermissions ( ) ;
}
//SUBGROUPS LOADING
if ( thisUserNode . get ( " subgroups " ) = = null ) {
thisUserNode . put ( " subgroups " , new ArrayList < String > ( ) ) ;
}
if ( thisUserNode . get ( " subgroups " ) instanceof List ) {
for ( Object o : ( ( List ) thisUserNode . get ( " subgroups " ) ) ) {
Group subGrp = ph . getGroup ( o . toString ( ) ) ;
if ( subGrp ! = null ) {
thisUser . addSubGroup ( subGrp ) ;
} else {
GroupManager . logger . warning ( " Subgroup " + o . toString ( ) + " not found for user " + thisUser . getName ( ) + " . Ignoring entry in file: " + usersFile . getPath ( ) ) ;
}
}
} else if ( thisUserNode . get ( " subgroups " ) instanceof String ) {
Group subGrp = ph . getGroup ( thisUserNode . get ( " subgroups " ) . toString ( ) ) ;
if ( subGrp ! = null ) {
thisUser . addSubGroup ( subGrp ) ;
} else {
GroupManager . logger . warning ( " Subgroup " + thisUserNode . get ( " subgroups " ) . toString ( ) + " not found for user " + thisUser . getName ( ) + " . Ignoring entry in file: " + usersFile . getPath ( ) ) ;
}
}
//USER INFO NODE
//INFO NODE
if ( thisUserNode . get ( " info " ) instanceof Map ) {
Map < String , Object > infoNode = ( Map < String , Object > ) thisUserNode . get ( " info " ) ;
if ( infoNode ! = null ) {
thisUser . setVariables ( infoNode ) ;
}
} else if ( thisUserNode . get ( " info " ) ! = null )
throw new IllegalArgumentException ( " Unknown entry found in Info section for user: " + thisUser . getName ( ) + " in file: " + usersFile . getPath ( ) ) ;
//END INFO NODE
if ( thisUserNode . get ( " group " ) ! = null ) {
Group hisGroup = ph . getGroup ( thisUserNode . get ( " group " ) . toString ( ) ) ;
if ( hisGroup = = null ) {
GroupManager . logger . warning ( " There is no group " + thisUserNode . get ( " group " ) . toString ( ) + " , as stated for player " + thisUser . getName ( ) + " : Set to ' " + ph . getDefaultGroup ( ) . getName ( ) + " ' for file: " + usersFile . getPath ( ) ) ;
hisGroup = ph . getDefaultGroup ( ) ;
//throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName());
}
thisUser . setGroup ( hisGroup ) ;
} else {
thisUser . setGroup ( ph . getDefaultGroup ( ) ) ;
}
}
}
2011-11-02 22:33:29 +00:00
ph . removeUsersChangedFlag ( ) ;
// Update the LastModified time.
2012-01-11 05:51:40 +00:00
ph . setUsersFile ( usersFile ) ;
2011-11-07 01:59:12 +00:00
ph . setTimeStampUsers ( usersFile . lastModified ( ) ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
2011-08-14 19:56:40 +00:00
* Write a dataHolder in a specified file
2011-03-19 22:39:51 +00:00
* @param ph
* @param groupsFile
* /
public static void writeGroups ( WorldDataHolder ph , File groupsFile ) {
Map < String , Object > root = new HashMap < String , Object > ( ) ;
Map < String , Object > groupsMap = new HashMap < String , Object > ( ) ;
2011-11-15 18:17:18 +00:00
2011-03-19 22:39:51 +00:00
root . put ( " groups " , groupsMap ) ;
2012-01-11 05:51:40 +00:00
for ( String groupKey : ph . getGroups ( ) . keySet ( ) ) {
Group group = ph . getGroups ( ) . get ( groupKey ) ;
2011-03-19 22:39:51 +00:00
Map < String , Object > aGroupMap = new HashMap < String , Object > ( ) ;
groupsMap . put ( group . getName ( ) , aGroupMap ) ;
2012-01-11 05:51:40 +00:00
if ( ph . getDefaultGroup ( ) = = null ) {
2011-03-19 22:39:51 +00:00
GroupManager . logger . severe ( " There is no default group for world: " + ph . getName ( ) ) ;
}
2012-01-11 05:51:40 +00:00
aGroupMap . put ( " default " , group . equals ( ph . getDefaultGroup ( ) ) ) ;
2011-03-19 22:39:51 +00:00
Map < String , Object > infoMap = new HashMap < String , Object > ( ) ;
aGroupMap . put ( " info " , infoMap ) ;
for ( String infoKey : group . getVariables ( ) . getVarKeyList ( ) ) {
infoMap . put ( infoKey , group . getVariables ( ) . getVarObject ( infoKey ) ) ;
}
aGroupMap . put ( " inheritance " , group . getInherits ( ) ) ;
aGroupMap . put ( " permissions " , group . getPermissionList ( ) ) ;
}
2011-10-01 12:54:28 +00:00
if ( ! root . isEmpty ( ) ) {
DumperOptions opt = new DumperOptions ( ) ;
opt . setDefaultFlowStyle ( DumperOptions . FlowStyle . BLOCK ) ;
final Yaml yaml = new Yaml ( opt ) ;
try {
2011-11-15 18:17:18 +00:00
OutputStreamWriter out = new OutputStreamWriter ( new FileOutputStream ( groupsFile ) , " UTF-8 " ) ;
String newLine = System . getProperty ( " line.separator " ) ;
out . write ( " # Group inheritance " + newLine ) ;
2012-04-11 18:10:28 +00:00
out . write ( " # " + newLine ) ;
out . write ( " # Any inherited groups prefixed with a g: are global groups " + newLine ) ;
out . write ( " # and are inherited from the GlobalGroups.yml. " + newLine ) ;
2011-11-15 18:17:18 +00:00
out . write ( " # " + newLine ) ;
out . write ( " # Groups without the g: prefix are groups local to this world " + newLine ) ;
2012-04-11 18:10:28 +00:00
out . write ( " # and are defined in the this groups.yml file. " + newLine ) ;
out . write ( " # " + newLine ) ;
out . write ( " # Local group inheritances define your promotion tree when using 'manpromote/mandemote' " + newLine ) ;
2011-11-15 18:17:18 +00:00
out . write ( newLine ) ;
yaml . dump ( root , out ) ;
2011-11-17 05:46:01 +00:00
out . close ( ) ;
2011-10-01 12:54:28 +00:00
} catch ( UnsupportedEncodingException ex ) {
} catch ( FileNotFoundException ex ) {
2011-11-15 18:17:18 +00:00
} catch ( IOException e ) {
}
2011-08-14 19:56:40 +00:00
}
2011-11-02 22:33:29 +00:00
// Update the LastModified time.
2012-01-11 05:51:40 +00:00
ph . setGroupsFile ( groupsFile ) ;
2011-11-02 22:33:29 +00:00
ph . setTimeStampGroups ( groupsFile . lastModified ( ) ) ;
ph . removeGroupsChangedFlag ( ) ;
2011-12-13 17:13:53 +00:00
if ( GroupManager . isLoaded ( ) )
GroupManagerEventHandler . callEvent ( GMSystemEvent . Action . SAVED ) ;
2011-03-19 22:39:51 +00:00
2011-04-10 22:55:11 +00:00
/ * FileWriter tx = null ;
2011-03-19 22:39:51 +00:00
try {
2011-08-14 19:56:40 +00:00
tx = new FileWriter ( groupsFile , false ) ;
tx . write ( yaml . dump ( root ) ) ;
tx . flush ( ) ;
2011-03-19 22:39:51 +00:00
} catch ( Exception e ) {
} finally {
2011-08-14 19:56:40 +00:00
try {
tx . close ( ) ;
} catch ( IOException ex ) {
}
2011-04-10 22:55:11 +00:00
} * /
2011-03-19 22:39:51 +00:00
}
/ * *
2011-08-14 19:56:40 +00:00
* Write a dataHolder in a specified file
2011-03-19 22:39:51 +00:00
* @param ph
* @param usersFile
* /
public static void writeUsers ( WorldDataHolder ph , File usersFile ) {
Map < String , Object > root = new HashMap < String , Object > ( ) ;
Map < String , Object > usersMap = new HashMap < String , Object > ( ) ;
root . put ( " users " , usersMap ) ;
2012-01-11 05:51:40 +00:00
for ( String userKey : ph . getUsers ( ) . keySet ( ) ) {
User user = ph . getUsers ( ) . get ( userKey ) ;
if ( ( user . getGroup ( ) = = null | | user . getGroup ( ) . equals ( ph . getDefaultGroup ( ) ) ) & & user . getPermissionList ( ) . isEmpty ( ) & & user . getVariables ( ) . isEmpty ( ) & & user . isSubGroupsEmpty ( ) ) {
2011-03-19 22:39:51 +00:00
continue ;
}
Map < String , Object > aUserMap = new HashMap < String , Object > ( ) ;
usersMap . put ( user . getName ( ) , aUserMap ) ;
if ( user . getGroup ( ) = = null ) {
2012-01-11 05:51:40 +00:00
aUserMap . put ( " group " , ph . getDefaultGroup ( ) . getName ( ) ) ;
2011-03-19 22:39:51 +00:00
} else {
aUserMap . put ( " group " , user . getGroup ( ) . getName ( ) ) ;
}
//USER INFO NODE - BETA
if ( user . getVariables ( ) . getSize ( ) > 0 ) {
Map < String , Object > infoMap = new HashMap < String , Object > ( ) ;
aUserMap . put ( " info " , infoMap ) ;
for ( String infoKey : user . getVariables ( ) . getVarKeyList ( ) ) {
infoMap . put ( infoKey , user . getVariables ( ) . getVarObject ( infoKey ) ) ;
}
}
//END USER INFO NODE - BETA
aUserMap . put ( " permissions " , user . getPermissionList ( ) ) ;
//SUBGROUPS NODE - BETA
aUserMap . put ( " subgroups " , user . subGroupListStringCopy ( ) ) ;
//END SUBGROUPS NODE - BETA
}
2011-10-01 12:54:28 +00:00
if ( ! root . isEmpty ( ) ) {
DumperOptions opt = new DumperOptions ( ) ;
opt . setDefaultFlowStyle ( DumperOptions . FlowStyle . BLOCK ) ;
final Yaml yaml = new Yaml ( opt ) ;
try {
2011-11-17 05:46:01 +00:00
OutputStreamWriter out = new OutputStreamWriter ( new FileOutputStream ( usersFile ) , " UTF-8 " ) ;
yaml . dump ( root , out ) ;
out . close ( ) ;
2011-10-01 12:54:28 +00:00
} catch ( UnsupportedEncodingException ex ) {
} catch ( FileNotFoundException ex ) {
2011-11-17 05:46:01 +00:00
} catch ( IOException e ) {
}
2011-08-14 19:56:40 +00:00
}
2011-11-02 22:33:29 +00:00
// Update the LastModified time.
2012-01-11 05:51:40 +00:00
ph . setUsersFile ( usersFile ) ;
2011-11-02 22:33:29 +00:00
ph . setTimeStampUsers ( usersFile . lastModified ( ) ) ;
ph . removeUsersChangedFlag ( ) ;
2011-12-13 17:13:53 +00:00
if ( GroupManager . isLoaded ( ) )
GroupManagerEventHandler . callEvent ( GMSystemEvent . Action . SAVED ) ;
2011-04-10 22:55:11 +00:00
/ * FileWriter tx = null ;
2011-03-19 22:39:51 +00:00
try {
2011-08-14 19:56:40 +00:00
tx = new FileWriter ( usersFile , false ) ;
tx . write ( yaml . dump ( root ) ) ;
tx . flush ( ) ;
2011-03-19 22:39:51 +00:00
} catch ( Exception e ) {
} finally {
2011-08-14 19:56:40 +00:00
try {
tx . close ( ) ;
} catch ( IOException ex ) {
}
2011-04-10 22:55:11 +00:00
} * /
2011-03-19 22:39:51 +00:00
}
/ * *
* Don ' t use this . Unless you want to make this plugin to interact with original Nijikokun Permissions
* This method is supposed to make the original one reload the file , and propagate the changes made here .
*
* Prefer to use the AnjoCaido ' s fake version of Nijikokun ' s Permission plugin .
* The AnjoCaido ' s Permission can propagate the changes made on this plugin instantly ,
* without need to save the file .
*
* @param server the server that holds the plugin
* @deprecated it is not used anymore . . . unless if you use original Permissions
* /
@Deprecated
public static void reloadOldPlugins ( Server server ) {
// Only reload permissions
PluginManager pm = server . getPluginManager ( ) ;
Plugin [ ] plugins = pm . getPlugins ( ) ;
for ( int i = 0 ; i < plugins . length ; i + + ) {
2012-02-21 16:33:46 +00:00
//plugins[i].getConfiguration().load();
2011-03-19 22:39:51 +00:00
try {
plugins [ i ] . getClass ( ) . getMethod ( " setupPermissions " ) . invoke ( plugins [ i ] ) ;
} catch ( Exception ex ) {
continue ;
}
}
}
/ * *
* @return the permissionsHandler
* /
public AnjoPermissionsHandler getPermissionsHandler ( ) {
if ( permissionsHandler = = null ) {
permissionsHandler = new AnjoPermissionsHandler ( this ) ;
}
return permissionsHandler ;
}
2012-01-11 05:51:40 +00:00
/ * *
* @param haveUsersChanged the haveUsersChanged to set
* /
public void setUsersChanged ( boolean haveUsersChanged ) {
users . setUsersChanged ( haveUsersChanged ) ;
}
2011-03-19 22:39:51 +00:00
/ * *
*
2011-11-04 09:36:11 +00:00
* @return true if any user data has changed
2011-03-19 22:39:51 +00:00
* /
public boolean haveUsersChanged ( ) {
2012-01-11 05:51:40 +00:00
if ( users . HaveUsersChanged ( ) ) {
2011-03-19 22:39:51 +00:00
return true ;
}
2012-01-11 05:51:40 +00:00
for ( User u : users . getUsers ( ) . values ( ) ) {
2011-03-19 22:39:51 +00:00
if ( u . isChanged ( ) ) {
return true ;
}
}
return false ;
}
2012-01-11 05:51:40 +00:00
/ * *
* @param setGroupsChanged the haveGroupsChanged to set
* /
public void setGroupsChanged ( boolean setGroupsChanged ) {
groups . setGroupsChanged ( setGroupsChanged ) ;
}
2011-03-19 22:39:51 +00:00
/ * *
*
2011-11-04 09:36:11 +00:00
* @return true if any group data has changed .
2011-03-19 22:39:51 +00:00
* /
public boolean haveGroupsChanged ( ) {
2012-01-11 05:51:40 +00:00
if ( groups . HaveGroupsChanged ( ) ) {
2011-03-19 22:39:51 +00:00
return true ;
}
2012-01-11 05:51:40 +00:00
for ( Group g : groups . getGroups ( ) . values ( ) ) {
2011-03-19 22:39:51 +00:00
if ( g . isChanged ( ) ) {
return true ;
}
}
return false ;
}
/ * *
*
* /
public void removeUsersChangedFlag ( ) {
2012-01-11 05:51:40 +00:00
setUsersChanged ( false ) ;
for ( User u : getUsers ( ) . values ( ) ) {
2011-03-19 22:39:51 +00:00
u . flagAsSaved ( ) ;
}
}
/ * *
*
* /
public void removeGroupsChangedFlag ( ) {
2012-01-11 05:51:40 +00:00
setGroupsChanged ( false ) ;
for ( Group g : getGroups ( ) . values ( ) ) {
2011-03-19 22:39:51 +00:00
g . flagAsSaved ( ) ;
}
}
/ * *
* @return the usersFile
* /
public File getUsersFile ( ) {
2012-01-11 05:51:40 +00:00
return users . getUsersFile ( ) ;
}
/ * *
* @param file the usersFile to set
* /
public void setUsersFile ( File file ) {
users . setUsersFile ( file ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
* @return the groupsFile
* /
public File getGroupsFile ( ) {
2012-01-11 05:51:40 +00:00
return groups . getGroupsFile ( ) ;
}
/ * *
* @param file the groupsFile to set
* /
public void setGroupsFile ( File file ) {
groups . setGroupsFile ( file ) ;
2011-03-19 22:39:51 +00:00
}
/ * *
* @return the name
* /
public String getName ( ) {
return name ;
}
2011-11-02 22:33:29 +00:00
/ * *
* Resets Groups .
* /
public void resetGroups ( ) {
2012-01-11 05:51:40 +00:00
//setDefaultGroup(null);
groups . setGroups ( new HashMap < String , Group > ( ) ) ;
2011-11-02 22:33:29 +00:00
}
/ * *
* Resets Users
* /
public void resetUsers ( ) {
2012-01-11 05:51:40 +00:00
users . setUsers ( new HashMap < String , User > ( ) ) ;
2011-11-02 22:33:29 +00:00
}
/ * *
* @return the groups
* /
public Map < String , Group > getGroups ( ) {
2012-01-11 05:51:40 +00:00
return groups . getGroups ( ) ;
2011-11-02 22:33:29 +00:00
}
/ * *
* @return the users
* /
public Map < String , User > getUsers ( ) {
2012-01-11 05:51:40 +00:00
return users . getUsers ( ) ;
}
/ * *
* @return the groups
* /
public GroupsDataHolder getGroupsObject ( ) {
return groups ;
}
/ * *
* @param groupsDataHolder the GroupsDataHolder to set
* /
public void setGroupsObject ( GroupsDataHolder groupsDataHolder ) {
groups = groupsDataHolder ;
}
/ * *
* @return the users
* /
public UsersDataHolder getUsersObject ( ) {
2011-11-02 22:33:29 +00:00
return users ;
}
2012-01-11 05:51:40 +00:00
/ * *
* @param usersDataHolder the UsersDataHolder to set
* /
public void setUsersObject ( UsersDataHolder usersDataHolder ) {
users = usersDataHolder ;
}
2011-11-02 22:33:29 +00:00
/ * *
* @return the timeStampGroups
* /
public long getTimeStampGroups ( ) {
2012-01-11 05:51:40 +00:00
return groups . getTimeStampGroups ( ) ;
2011-11-02 22:33:29 +00:00
}
/ * *
* @return the timeStampUsers
* /
public long getTimeStampUsers ( ) {
2012-01-11 05:51:40 +00:00
return users . getTimeStampUsers ( ) ;
2011-11-02 22:33:29 +00:00
}
/ * *
* @param timeStampGroups the timeStampGroups to set
* /
protected void setTimeStampGroups ( long timeStampGroups ) {
2012-01-11 05:51:40 +00:00
groups . setTimeStampGroups ( timeStampGroups ) ;
2011-11-02 22:33:29 +00:00
}
/ * *
* @param timeStampUsers the timeStampUsers to set
* /
protected void setTimeStampUsers ( long timeStampUsers ) {
2012-01-11 05:51:40 +00:00
users . setTimeStampUsers ( timeStampUsers ) ;
2011-11-02 22:33:29 +00:00
}
public void setTimeStamps ( ) {
2012-01-11 05:51:40 +00:00
if ( getGroupsFile ( ) ! = null )
setTimeStampGroups ( getGroupsFile ( ) . lastModified ( ) ) ;
if ( getUsersFile ( ) ! = null )
setTimeStampUsers ( getUsersFile ( ) . lastModified ( ) ) ;
2011-12-13 17:13:53 +00:00
}
2011-03-19 22:39:51 +00:00
}