diff options
author | snowleo <schneeleo@gmail.com> | 2011-11-25 21:12:38 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-11-25 21:12:38 +0100 |
commit | 6ba02c7f74652565b2918e1591bee4c56adf6e34 (patch) | |
tree | bf6b9f61a3c0eb7f0a8d4f0b28b6144dfa607d0f /EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java | |
parent | cc155b145b8b51e34c0031ae22b5f14c8b6d196a (diff) | |
parent | befbb4d0e51db31270c9d7b42fc3e4c3b8983b08 (diff) | |
download | Essentials-6ba02c7f74652565b2918e1591bee4c56adf6e34.tar Essentials-6ba02c7f74652565b2918e1591bee4c56adf6e34.tar.gz Essentials-6ba02c7f74652565b2918e1591bee4c56adf6e34.tar.lz Essentials-6ba02c7f74652565b2918e1591bee4c56adf6e34.tar.xz Essentials-6ba02c7f74652565b2918e1591bee4c56adf6e34.zip |
Merge branch 'refs/heads/groupmanager'
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java | 415 |
1 files changed, 219 insertions, 196 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 6c4cdbcf2..eea488ab2 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -10,209 +10,232 @@ import java.util.ArrayList; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import java.util.Map; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + /** - * + * * @author gabrielcouto */ public class User extends DataUnit implements Cloneable { - /** - * - */ - private String group = null; - private ArrayList<String> subGroups = new ArrayList<String>(); - /** - *This one holds the fields in INFO node. - * like prefix = 'c' - * or build = false - */ - private UserVariables variables = new UserVariables(this); - - /** + /** * - * @param name */ - public User(WorldDataHolder source, String name) { - super(source, name); - this.group = source.getDefaultGroup().getName(); - } + private String group = null; + private ArrayList<String> subGroups = new ArrayList<String>(); + /** + * This one holds the fields in INFO node. like prefix = 'c' or build = + * false + */ + private UserVariables variables = new UserVariables(this); + private transient Player bukkitPlayer = null; + + /** + * + * @param name + */ + public User(WorldDataHolder source, String name) { + super(source, name); + this.group = source.getDefaultGroup().getName(); + } + + /** + * + * @return User clone + */ + @Override + public User clone() { + User clone = new User(getDataSource(), this.getName()); + clone.group = this.group; + for (String perm : this.getPermissionList()) { + clone.addPermission(perm); + } + // clone.variables = this.variables.clone(); + // clone.flagAsChanged(); + return clone; + } + + /** + * Use this to deliver a user from one WorldDataHolder to another + * + * @param dataSource + * @return null if given dataSource already contains the same user + */ + public User clone(WorldDataHolder dataSource) { + if (dataSource.isUserDeclared(this.getName())) { + return null; + } + User clone = dataSource.createUser(this.getName()); + if (dataSource.getGroup(group) == null) { + clone.setGroup(dataSource.getDefaultGroup()); + } else { + clone.setGroup(dataSource.getGroup(this.getGroupName())); + } + for (String perm : this.getPermissionList()) { + clone.addPermission(perm); + } + // clone.variables = this.variables.clone(); + clone.flagAsChanged(); + return clone; + } + + public Group getGroup() { + Group result = getDataSource().getGroup(group); + if (result == null) { + this.setGroup(getDataSource().getDefaultGroup()); + result = getDataSource().getDefaultGroup(); + } + return result; + } + + /** + * @return the group + */ + public String getGroupName() { + Group result = getDataSource().getGroup(group); + if (result == null) { + group = getDataSource().getDefaultGroup().getName(); + } + return group; + } + + /** + * @param group + * the group to set + */ + @Deprecated + public void setGroup(String group) { + this.group = group; + flagAsChanged(); + if (GroupManager.isLoaded()) + if (GroupManager.BukkitPermissions.player_join = false) + GroupManager.BukkitPermissions.updateAllPlayers(); + } + + /** + * @param group + * the group to set + */ + public void setGroup(Group group) { + if (!this.getDataSource().groupExists(group.getName())) { + getDataSource().addGroup(group); + } + group = getDataSource().getGroup(group.getName()); + String oldGroup = this.group; + this.group = group.getName(); + flagAsChanged(); + if (GroupManager.isLoaded()) { + if (GroupManager.BukkitPermissions.player_join = false) + GroupManager.BukkitPermissions.updateAllPlayers(); + + // Do we notify of the group change? + String defaultGroupName = getDataSource().getDefaultGroup().getName(); + // if we were not in the default group + // or we were in the default group and the move is to a different + // group. + boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName))); + + if (notify) + GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName())); + } + } + + public void addSubGroup(Group subGroup) { + if (this.group.equalsIgnoreCase(subGroup.getName())) { + return; + } + if (!this.getDataSource().groupExists(subGroup.getName())) { + getDataSource().addGroup(subGroup); + } + subGroup = getDataSource().getGroup(subGroup.getName()); + removeSubGroup(subGroup); + subGroups.add(subGroup.getName()); + flagAsChanged(); + if (GroupManager.isLoaded()) + if (GroupManager.BukkitPermissions.player_join = false) + GroupManager.BukkitPermissions.updateAllPlayers(); + } + + public int subGroupsSize() { + return subGroups.size(); + } + + public boolean isSubGroupsEmpty() { + return subGroups.isEmpty(); + } + + public boolean containsSubGroup(Group subGroup) { + return subGroups.contains(subGroup.getName()); + } + + public boolean removeSubGroup(Group subGroup) { + try { + if (subGroups.remove(subGroup.getName())) { + flagAsChanged(); + if (GroupManager.isLoaded()) + if (GroupManager.BukkitPermissions.player_join = false) + GroupManager.BukkitPermissions.updateAllPlayers(); + return true; + } + } catch (Exception e) { + } + return false; + } + + public ArrayList<Group> subGroupListCopy() { + ArrayList<Group> val = new ArrayList<Group>(); + for (String gstr : subGroups) { + Group g = getDataSource().getGroup(gstr); + if (g == null) { + removeSubGroup(g); + continue; + } + val.add(g); + } + return val; + } + + public ArrayList<String> subGroupListStringCopy() { + return new ArrayList<String>(subGroups); + } + + /** + * @return the variables + */ + public UserVariables getVariables() { + return variables; + } + + /** + * + * @param varList + */ + public void setVariables(Map<String, Object> varList) { + UserVariables temp = new UserVariables(this, varList); + variables.clearVars(); + for (String key : temp.getVarKeyList()) { + variables.addVar(key, temp.getVarObject(key)); + } + flagAsChanged(); + if (GroupManager.isLoaded()) + if (GroupManager.BukkitPermissions.player_join = false) + GroupManager.BukkitPermissions.updateAllPlayers(); + } + + public User updatePlayer(Player player) { + if (player != null) { + bukkitPlayer = player; + } + return this; + } + + public Player getBukkitPlayer() { + if (bukkitPlayer == null) { + bukkitPlayer = Bukkit.getPlayer(this.getName()); + } + return bukkitPlayer; + } - /** - * - * @return User clone - */ - @Override - public User clone() { - User clone = new User(getDataSource(), this.getName()); - clone.group = this.group; - for (String perm : this.getPermissionList()) { - clone.addPermission(perm); - } - //clone.variables = this.variables.clone(); - //clone.flagAsChanged(); - return clone; - } - - /** - * Use this to deliver a user from one WorldDataHolder to another - * @param dataSource - * @return null if given dataSource already contains the same user - */ - public User clone(WorldDataHolder dataSource) { - if (dataSource.isUserDeclared(this.getName())) { - return null; - } - User clone = dataSource.createUser(this.getName()); - if (dataSource.getGroup(group) == null) { - clone.setGroup(dataSource.getDefaultGroup()); - } else { - clone.setGroup(dataSource.getGroup(this.getGroupName())); - } - for (String perm : this.getPermissionList()) { - clone.addPermission(perm); - } - //clone.variables = this.variables.clone(); - clone.flagAsChanged(); - return clone; - } - - public Group getGroup() { - Group result = getDataSource().getGroup(group); - if (result == null) { - this.setGroup(getDataSource().getDefaultGroup()); - result = getDataSource().getDefaultGroup(); - } - return result; - } - - /** - * @return the group - */ - public String getGroupName() { - Group result = getDataSource().getGroup(group); - if (result == null) { - group = getDataSource().getDefaultGroup().getName(); - } - return group; - } - - /** - * @param group the group to set - */ - @Deprecated - public void setGroup(String group) { - this.group = group; - flagAsChanged(); - if (GroupManager.isLoaded()) - if(GroupManager.BukkitPermissions.player_join = false) - GroupManager.BukkitPermissions.updateAllPlayers(); - } - - /** - * @param group the group to set - */ - public void setGroup(Group group) { - if (!this.getDataSource().groupExists(group.getName())) { - getDataSource().addGroup(group); - } - group = getDataSource().getGroup(group.getName()); - String oldGroup = this.group; - this.group = group.getName(); - flagAsChanged(); - if (GroupManager.isLoaded()) { - if (GroupManager.BukkitPermissions.player_join = false) - GroupManager.BukkitPermissions.updateAllPlayers(); - - // Do we notify of the group change? - String defaultGroupName = getDataSource().getDefaultGroup().getName(); - // if we were not in the default group - // or we were in the default group and the move is to a different group. - boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName))) ; - - if (notify) GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName())); - } - } - - public void addSubGroup(Group subGroup) { - if (this.group.equalsIgnoreCase(subGroup.getName())) { - return; - } - if (!this.getDataSource().groupExists(subGroup.getName())) { - getDataSource().addGroup(subGroup); - } - subGroup = getDataSource().getGroup(subGroup.getName()); - removeSubGroup(subGroup); - subGroups.add(subGroup.getName()); - flagAsChanged(); - if (GroupManager.isLoaded()) - if (GroupManager.BukkitPermissions.player_join = false) - GroupManager.BukkitPermissions.updateAllPlayers(); - } - - public int subGroupsSize() { - return subGroups.size(); - } - - public boolean isSubGroupsEmpty() { - return subGroups.isEmpty(); - } - - public boolean containsSubGroup(Group subGroup) { - return subGroups.contains(subGroup.getName()); - } - - public boolean removeSubGroup(Group subGroup) { - try { - if (subGroups.remove(subGroup.getName())) { - flagAsChanged(); - if (GroupManager.isLoaded()) - if (GroupManager.BukkitPermissions.player_join = false) - GroupManager.BukkitPermissions.updateAllPlayers(); - return true; - } - } catch (Exception e) { - } - return false; - } - - public ArrayList<Group> subGroupListCopy() { - ArrayList<Group> val = new ArrayList<Group>(); - for (String gstr : subGroups) { - Group g = getDataSource().getGroup(gstr); - if (g == null) { - removeSubGroup(g); - continue; - } - val.add(g); - } - return val; - } - - public ArrayList<String> subGroupListStringCopy() { - return new ArrayList<String>(subGroups); - } - - /** - * @return the variables - */ - public UserVariables getVariables() { - return variables; - } - - /** - * - * @param varList - */ - public void setVariables(Map<String, Object> varList) { - UserVariables temp = new UserVariables(this, varList); - variables.clearVars(); - for (String key : temp.getVarKeyList()) { - variables.addVar(key, temp.getVarObject(key)); - } - flagAsChanged(); - if (GroupManager.isLoaded()) - if (GroupManager.BukkitPermissions.player_join = false) - GroupManager.BukkitPermissions.updateAllPlayers(); - } } |