From 4ac5551c6bc97794389026259614303d7d8da662 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 4 Nov 2011 17:51:29 +0000 Subject: Notification of being moved to the default group only happens if it's a demotion/promotion (not on join). --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/data/User.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 5262c7018..d71bc135a 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -69,4 +69,5 @@ v 1.5: If the files have been altered (on disc) it will reload, so long as the in-memory data hasn't changed. If the files on Disc have changed AND there have been changes to it's in-memory data it will show a warning. You then MUST issue a '/mansave force' to overwrite the disc files, or a '/manload' to overwrite the memory data. - - Fix for an error in checkFullUserPermission caused by players disconnecting mid perms update. \ No newline at end of file + - Fix for an error in checkFullUserPermission caused by players disconnecting mid perms update. + - Notification of being moved to the default group only happens if it's a demotion/promotion (not on join). \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index bcfa8e01b..85b69f101 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -117,13 +117,18 @@ public class User extends DataUnit implements Cloneable { getDataSource().addGroup(group); } group = getDataSource().getGroup(group.getName()); + // Do we notify of the group change? + String defaultGroupName = getDataSource().getDefaultGroup().getName(); + // if we are not in the default group + // or we are in the default group and the move is to a different group. + boolean notify = (this.group != defaultGroupName) || ((this.group == defaultGroupName) && (group.getName() != defaultGroupName)) ; this.group = group.getName(); flagAsChanged(); if (GroupManager.isLoaded()) { if (GroupManager.BukkitPermissions.player_join = false) GroupManager.BukkitPermissions.updateAllPlayers(); - GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName())); + if (notify) GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName())); } } -- cgit v1.2.3 From 269947bdae7b0f0ad8bdef701f47e379c5be3c27 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 4 Nov 2011 18:12:37 +0000 Subject: Fix string compares --- EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 85b69f101..ee1623bed 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -121,7 +121,7 @@ public class User extends DataUnit implements Cloneable { String defaultGroupName = getDataSource().getDefaultGroup().getName(); // if we are not in the default group // or we are in the default group and the move is to a different group. - boolean notify = (this.group != defaultGroupName) || ((this.group == defaultGroupName) && (group.getName() != defaultGroupName)) ; + boolean notify = (!this.group.equalsIgnoreCase(defaultGroupName)) || ((this.group.equalsIgnoreCase(defaultGroupName)) && (!group.getName().equalsIgnoreCase(defaultGroupName))) ; this.group = group.getName(); flagAsChanged(); if (GroupManager.isLoaded()) { -- cgit v1.2.3 From e7234e621dc9c6dfb09011eb9ef5338d8824368f Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 4 Nov 2011 18:20:09 +0000 Subject: Optimize notify test so it's not run as often --- .../src/org/anjocaido/groupmanager/data/User.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index ee1623bed..8cfb3d14a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -117,16 +117,18 @@ public class User extends DataUnit implements Cloneable { getDataSource().addGroup(group); } group = getDataSource().getGroup(group.getName()); - // Do we notify of the group change? - String defaultGroupName = getDataSource().getDefaultGroup().getName(); - // if we are not in the default group - // or we are in the default group and the move is to a different group. - boolean notify = (!this.group.equalsIgnoreCase(defaultGroupName)) || ((this.group.equalsIgnoreCase(defaultGroupName)) && (!group.getName().equalsIgnoreCase(defaultGroupName))) ; + 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())); } -- cgit v1.2.3 From 1c7e0e5b9fe3045ac5e14884f8fb0a1def5f0f99 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 4 Nov 2011 23:13:42 +0000 Subject: Fix for file date conflict causing memory data to be wiped. --- .../groupmanager/dataholder/WorldDataHolder.java | 39 +++++++--------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 4140cbfea..1d07cdbe2 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -324,8 +324,12 @@ public class WorldDataHolder { public void reloadGroups() { GroupManager.setLoaded(false); try { - resetGroups(); - loadGroups(this, getGroupsFile()); + // temporary holder in case the load fails. + WorldDataHolder ph = new WorldDataHolder(this.getName()); + loadGroups(ph, getGroupsFile()); + this.groups = ph.getGroups(); + this.removeGroupsChangedFlag(); + this.timeStampGroups = ph.getTimeStampGroups(); } catch (Exception ex) { Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex); } @@ -335,8 +339,12 @@ public class WorldDataHolder { public void reloadUsers() { GroupManager.setLoaded(false); try { - resetUsers(); - loadUsers(this, getUsersFile()); + // temporary holder in case the load fails. + WorldDataHolder ph = new WorldDataHolder(this.getName()); + loadUsers(ph, getUsersFile()); + this.users = ph.getUsers(); + this.removeUsersChangedFlag(); + this.timeStampUsers = ph.getTimeStampUsers(); } catch (Exception ex) { Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex); } @@ -523,29 +531,6 @@ public class WorldDataHolder { return ph; } - /** - * Updates the WorldDataHolder from the files - * - * @param ph - * @param groupsFile - * @param usersFile - * - * @throws FileNotFoundException - * @throws IOException - */ - public static WorldDataHolder Update(WorldDataHolder ph, File groupsFile, File usersFile) throws FileNotFoundException, IOException { - - GroupManager.setLoaded(false); - ph.resetGroups(); - loadGroups(ph, groupsFile); - - ph.resetUsers(); - loadUsers(ph, usersFile); - GroupManager.setLoaded(true); - - return ph; - } - /** * Updates the WorldDataHolder from the Groups file * -- cgit v1.2.3 From cf9ef461822f9480d5d7c3de26489a061bc05b1e Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 5 Nov 2011 15:41:40 +0000 Subject: Fixed Group/User reloading Fixed Group.clone(dataholder) --- .../src/org/anjocaido/groupmanager/data/Group.java | 9 ++++-- .../src/org/anjocaido/groupmanager/data/User.java | 2 +- .../groupmanager/dataholder/WorldDataHolder.java | 34 ++++++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index e580918e7..c05065f5e 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -76,8 +76,13 @@ public class Group extends DataUnit implements Cloneable { if (dataSource.groupExists(this.getName())) { return null; } - Group clone = getDataSource().createGroup(this.getName()); - clone.inherits = new ArrayList(this.getInherits()); + + Group clone = dataSource.createGroup(this.getName()); + + // Don't add inheritance for GlobalGroups + if (getDataSource() != null) { + clone.inherits = new ArrayList(this.getInherits()); + } for (String perm : this.getPermissionList()) { clone.addPermission(perm); } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 8cfb3d14a..6c4cdbcf2 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -67,7 +67,7 @@ public class User extends DataUnit implements Cloneable { if (dataSource.getGroup(group) == null) { clone.setGroup(dataSource.getDefaultGroup()); } else { - clone.setGroup(this.getGroupName()); + clone.setGroup(dataSource.getGroup(this.getGroupName())); } for (String perm : this.getPermissionList()) { clone.addPermission(perm); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 1d07cdbe2..ce1693fc4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -38,7 +38,7 @@ import org.yaml.snakeyaml.reader.UnicodeReader; public class WorldDataHolder { /** - * + * World name */ protected String name; /** @@ -321,32 +321,54 @@ public class WorldDataHolder { } } + /** + * Refresh Group data from file + */ public void reloadGroups() { GroupManager.setLoaded(false); try { // temporary holder in case the load fails. WorldDataHolder ph = new WorldDataHolder(this.getName()); + loadGroups(ph, getGroupsFile()); - this.groups = ph.getGroups(); + // transfer new data + resetGroups(); + for (Group tempGroup : ph.getGroupList()) { + if (tempGroup.getDataSource() != null) tempGroup.clone(this); + } + this.setDefaultGroup(this.getGroup(ph.getDefaultGroup().getName())); this.removeGroupsChangedFlag(); this.timeStampGroups = ph.getTimeStampGroups(); } catch (Exception ex) { - Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); } GroupManager.setLoaded(true); } + /** + * Refresh Users data from file + */ public void reloadUsers() { GroupManager.setLoaded(false); try { // temporary holder in case the load fails. WorldDataHolder ph = new WorldDataHolder(this.getName()); + // copy groups for reference + for (Group tempGroup : this.getGroupList()) { + if (tempGroup.getDataSource() != null) tempGroup.clone(ph); + } + // setup the default group before loading user data. + ph.setDefaultGroup(ph.getGroup(this.getDefaultGroup().getName())); loadUsers(ph, getUsersFile()); - this.users = ph.getUsers(); + // transfer new data + resetUsers(); + for (User tempUser : ph.getUserList()) { + tempUser.clone(this); + } this.removeUsersChangedFlag(); this.timeStampUsers = ph.getTimeStampUsers(); } catch (Exception ex) { - Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); } GroupManager.setLoaded(true); } @@ -576,7 +598,7 @@ public class WorldDataHolder { } if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group " + thisGrp.getName() + " is declaring be default where" + ph.getDefaultGroup().getName() + " already was."); + GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); GroupManager.logger.warning("Overriding first request."); } ph.setDefaultGroup(thisGrp); -- cgit v1.2.3 From ab2e8f94f084bb1381ba8df604990796f63f5fc0 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 7 Nov 2011 01:59:12 +0000 Subject: Fix for Users file being flagged as updated when it wasn't. --- .../src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java | 4 ++-- .../org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index ce1693fc4..80291d066 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -669,7 +669,7 @@ public class WorldDataHolder { ph.removeGroupsChangedFlag(); // Update the LastModified time. ph.groupsFile = groupsFile; - ph.setTimeStamps(); + ph.setTimeStampGroups(groupsFile.lastModified()); //return ph; } @@ -776,7 +776,7 @@ public class WorldDataHolder { ph.removeUsersChangedFlag(); // Update the LastModified time. ph.usersFile = usersFile; - ph.setTimeStamps(); + ph.setTimeStampUsers(usersFile.lastModified()); //return ph; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index bf7b290ae..6544bb1cc 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -200,8 +200,8 @@ public class WorldsHolder { //Check for newer file as no local changes. if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) { System.out.print("Newer Groups file found (Loading changes)!"); - // Backup Users file - backupFile(w,false); + // Backup Groups file + backupFile(w,true); w.reloadGroups(); } } -- cgit v1.2.3 From f40260acef8ca6a9deff7c005b2b9d70816b1ef2 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 7 Nov 2011 15:33:15 +0000 Subject: Minor optimization for Group loading/clone --- .../src/org/anjocaido/groupmanager/GlobalGroups.java | 14 +++++++++++--- .../anjocaido/groupmanager/dataholder/WorldDataHolder.java | 8 ++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index eef5ba59e..861c5e3d4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -83,7 +83,6 @@ public class GlobalGroups { public void load() { GGroups = new YamlConfiguration(); - groups = new HashMap(); GroupManager.setLoaded(false); @@ -110,7 +109,9 @@ public class GlobalGroups { Map allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); // Load each groups permissions list. - if (allGroups != null) + if (allGroups != null) { + // Clear out old groups + resetGlobalGroups(); for (String groupName : allGroups.keySet()) { Group newGroup = new Group(groupName.toLowerCase()); Object element; @@ -144,12 +145,12 @@ public class GlobalGroups { // Push a new group addGroup(newGroup); } + } removeGroupsChangedFlag(); setTimeStampGroups(GlobalGroupsFile.lastModified()); GroupManager.setLoaded(true); //GlobalGroupsFile = null; - } /** @@ -351,6 +352,13 @@ public class GlobalGroups { return groups.keySet(); } + /** + * Resets GlobalGroups. + */ + public void resetGlobalGroups() { + this.groups = new HashMap(); + } + /** * * @return a collection of the groups diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 80291d066..8f5fad5cf 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -334,11 +334,13 @@ public class WorldDataHolder { // transfer new data resetGroups(); for (Group tempGroup : ph.getGroupList()) { - if (tempGroup.getDataSource() != null) tempGroup.clone(this); + tempGroup.clone(this); } this.setDefaultGroup(this.getGroup(ph.getDefaultGroup().getName())); this.removeGroupsChangedFlag(); this.timeStampGroups = ph.getTimeStampGroups(); + + ph = null; } catch (Exception ex) { Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); } @@ -355,7 +357,7 @@ public class WorldDataHolder { WorldDataHolder ph = new WorldDataHolder(this.getName()); // copy groups for reference for (Group tempGroup : this.getGroupList()) { - if (tempGroup.getDataSource() != null) tempGroup.clone(ph); + tempGroup.clone(ph); } // setup the default group before loading user data. ph.setDefaultGroup(ph.getGroup(this.getDefaultGroup().getName())); @@ -367,6 +369,8 @@ public class WorldDataHolder { } this.removeUsersChangedFlag(); this.timeStampUsers = ph.getTimeStampUsers(); + + ph = null; } catch (Exception ex) { Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); } -- cgit v1.2.3 From e9f942e8023e8206f0a4de342935ff85e4ffd2b2 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Mon, 7 Nov 2011 22:15:58 +0000 Subject: Change to default users as examples --- EssentialsGroupManager/src/users.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EssentialsGroupManager/src/users.yml b/EssentialsGroupManager/src/users.yml index 43d030e9a..28fa79910 100644 --- a/EssentialsGroupManager/src/users.yml +++ b/EssentialsGroupManager/src/users.yml @@ -4,12 +4,12 @@ users: subgroups: [] permissions: [] group: Admin - mudzereli: + KHobbits: subgroups: [] permissions: [] - group: Builder + group: Moderator ElgarL: subgroups: [] permissions: [] - group: Admin + group: Owner -- cgit v1.2.3