Merge branch 'refs/heads/groupmanager'

This commit is contained in:
snowleo 2011-11-22 15:12:20 +01:00
commit e683ce5751
4 changed files with 81 additions and 71 deletions

View file

@ -73,3 +73,6 @@ v 1.5:
- Notification of being moved to the default group only happens if it's a demotion/promotion (not on join). - Notification of being moved to the default group only happens if it's a demotion/promotion (not on join).
- Fixed GM holding files open and causing the time stamp to be incorrect. This caused GM to require a '/mansave force' when it shouldn't be needed. - Fixed GM holding files open and causing the time stamp to be incorrect. This caused GM to require a '/mansave force' when it shouldn't be needed.
- Fixed a crash on reload due to bukkit not unloading plugins before reloading. - Fixed a crash on reload due to bukkit not unloading plugins before reloading.
v 1.6:
- Prevent Group.equals tests throwing a NullPointerException for GlobalGroups.
- Stop throwing errors on an empty users file.

View file

@ -39,8 +39,19 @@ public abstract class DataUnit {
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof DataUnit) { if (o instanceof DataUnit) {
DataUnit go = (DataUnit) o; DataUnit go = (DataUnit) o;
if (this.getName().equalsIgnoreCase(go.getName()) && this.dataSource.getName().equalsIgnoreCase(go.getDataSource().getName())) { if (this.getName().equalsIgnoreCase(go.getName())) {
return true; // Global Group match.
if (this.dataSource == null && go.getDataSource() == null)
return true;
// This is a global group, the object to test isn't.
if (this.dataSource == null && go.getDataSource() != null)
return false;
// This is not a global group, but the object to test is.
if (this.dataSource != null && go.getDataSource() == null)
return false;
// Match on group name and world name.
if (this.dataSource.getName().equalsIgnoreCase(go.getDataSource().getName()))
return true;
} }
} }
return false; return false;

View file

@ -711,78 +711,74 @@ public class WorldDataHolder {
// PROCESS USERS FILE // PROCESS USERS FILE
Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users"); Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
// Stop loading if the file is empty // Load users if the file is NOT empty
if (allUsersNode == null) if (allUsersNode != null)
return ; for (String usersKey : allUsersNode.keySet()) {
Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
User thisUser = ph.createUser(usersKey);
if (thisUser == null) {
throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey);
}
if (thisUserNode.get("permissions") == null) {
thisUserNode.put("permissions", new ArrayList<String>());
}
if (thisUserNode.get("permissions") instanceof List) {
for (Object o : ((List) thisUserNode.get("permissions"))) {
thisUser.addPermission(o.toString());
}
} else if (thisUserNode.get("permissions") instanceof String) {
thisUser.addPermission(thisUserNode.get("permissions").toString());
}
for (String usersKey : allUsersNode.keySet()) { //SUBGROUPS LOADING
Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey); if (thisUserNode.get("subgroups") == null) {
User thisUser = ph.createUser(usersKey); thisUserNode.put("subgroups", new ArrayList<String>());
if (thisUser == null) { }
throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey); if (thisUserNode.get("subgroups") instanceof List) {
} for (Object o : ((List) thisUserNode.get("subgroups"))) {
if (thisUserNode.get("permissions") == null) { Group subGrp = ph.getGroup(o.toString());
thisUserNode.put("permissions", new ArrayList<String>()); if (subGrp != null) {
} thisUser.addSubGroup(subGrp);
if (thisUserNode.get("permissions") instanceof List) { } else {
for (Object o : ((List) thisUserNode.get("permissions"))) { GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry.");
thisUser.addPermission(o.toString()); }
} }
} else if (thisUserNode.get("permissions") instanceof String) { } else if (thisUserNode.get("subgroups") instanceof String) {
thisUser.addPermission(thisUserNode.get("permissions").toString()); Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString());
} if (subGrp != null) {
thisUser.addSubGroup(subGrp);
//SUBGROUPS LOADING } else {
if (thisUserNode.get("subgroups") == null) { GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry.");
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.");
}
}
} 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.");
}
}
//USER INFO NODE - BETA //USER INFO NODE - BETA
//INFO NODE //INFO NODE
Map<String, Object> infoNode = (Map<String, Object>) thisUserNode.get("info"); Map<String, Object> infoNode = (Map<String, Object>) thisUserNode.get("info");
if (infoNode != null) { if (infoNode != null) {
thisUser.setVariables(infoNode); thisUser.setVariables(infoNode);
} }
//END INFO NODE - BETA //END INFO NODE - BETA
if (thisUserNode.get("group") != null) { if (thisUserNode.get("group") != null) {
Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); Group hisGroup = ph.getGroup(thisUserNode.get("group").toString());
if (hisGroup == null) { 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() + "'."); GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "'.");
hisGroup = ph.defaultGroup; hisGroup = ph.defaultGroup;
//throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName());
} }
thisUser.setGroup(hisGroup); thisUser.setGroup(hisGroup);
} else { } else {
thisUser.setGroup(ph.defaultGroup); thisUser.setGroup(ph.defaultGroup);
} }
} }
ph.removeUsersChangedFlag(); ph.removeUsersChangedFlag();
// Update the LastModified time. // Update the LastModified time.
ph.usersFile = usersFile; ph.usersFile = usersFile;
ph.setTimeStampUsers(usersFile.lastModified()); ph.setTimeStampUsers(usersFile.lastModified());
//return ph;
} }
/** /**

View file

@ -1,5 +1,5 @@
name: GroupManager name: GroupManager
version: "1.5 (Phoenix)" version: "1.6 (Phoenix)"
main: org.anjocaido.groupmanager.GroupManager main: org.anjocaido.groupmanager.GroupManager
website: http://www.anjocaido.info/ website: http://www.anjocaido.info/
description: Provides on-the-fly system for permissions system created by Nijikokun. But all in memory, and with flat-file saving schedule. description: Provides on-the-fly system for permissions system created by Nijikokun. But all in memory, and with flat-file saving schedule.