mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-01 14:07:46 +01:00
Merge remote branch 'remotes/ess/groupmanager' into essmaster
This commit is contained in:
commit
90c9fe7e65
@ -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 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.
|
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.
|
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.
|
- 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).
|
@ -83,7 +83,6 @@ public class GlobalGroups {
|
|||||||
public void load() {
|
public void load() {
|
||||||
|
|
||||||
GGroups = new YamlConfiguration();
|
GGroups = new YamlConfiguration();
|
||||||
groups = new HashMap<String, Group>();
|
|
||||||
|
|
||||||
GroupManager.setLoaded(false);
|
GroupManager.setLoaded(false);
|
||||||
|
|
||||||
@ -110,7 +109,9 @@ public class GlobalGroups {
|
|||||||
Map<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
|
Map<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
|
||||||
|
|
||||||
// Load each groups permissions list.
|
// Load each groups permissions list.
|
||||||
if (allGroups != null)
|
if (allGroups != null) {
|
||||||
|
// Clear out old groups
|
||||||
|
resetGlobalGroups();
|
||||||
for (String groupName : allGroups.keySet()) {
|
for (String groupName : allGroups.keySet()) {
|
||||||
Group newGroup = new Group(groupName.toLowerCase());
|
Group newGroup = new Group(groupName.toLowerCase());
|
||||||
Object element;
|
Object element;
|
||||||
@ -144,12 +145,12 @@ public class GlobalGroups {
|
|||||||
// Push a new group
|
// Push a new group
|
||||||
addGroup(newGroup);
|
addGroup(newGroup);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
removeGroupsChangedFlag();
|
removeGroupsChangedFlag();
|
||||||
setTimeStampGroups(GlobalGroupsFile.lastModified());
|
setTimeStampGroups(GlobalGroupsFile.lastModified());
|
||||||
GroupManager.setLoaded(true);
|
GroupManager.setLoaded(true);
|
||||||
//GlobalGroupsFile = null;
|
//GlobalGroupsFile = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -351,6 +352,13 @@ public class GlobalGroups {
|
|||||||
return groups.keySet();
|
return groups.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets GlobalGroups.
|
||||||
|
*/
|
||||||
|
public void resetGlobalGroups() {
|
||||||
|
this.groups = new HashMap<String, Group>();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return a collection of the groups
|
* @return a collection of the groups
|
||||||
|
@ -76,8 +76,13 @@ public class Group extends DataUnit implements Cloneable {
|
|||||||
if (dataSource.groupExists(this.getName())) {
|
if (dataSource.groupExists(this.getName())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Group clone = getDataSource().createGroup(this.getName());
|
|
||||||
clone.inherits = new ArrayList<String>(this.getInherits());
|
Group clone = dataSource.createGroup(this.getName());
|
||||||
|
|
||||||
|
// Don't add inheritance for GlobalGroups
|
||||||
|
if (getDataSource() != null) {
|
||||||
|
clone.inherits = new ArrayList<String>(this.getInherits());
|
||||||
|
}
|
||||||
for (String perm : this.getPermissionList()) {
|
for (String perm : this.getPermissionList()) {
|
||||||
clone.addPermission(perm);
|
clone.addPermission(perm);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class User extends DataUnit implements Cloneable {
|
|||||||
if (dataSource.getGroup(group) == null) {
|
if (dataSource.getGroup(group) == null) {
|
||||||
clone.setGroup(dataSource.getDefaultGroup());
|
clone.setGroup(dataSource.getDefaultGroup());
|
||||||
} else {
|
} else {
|
||||||
clone.setGroup(this.getGroupName());
|
clone.setGroup(dataSource.getGroup(this.getGroupName()));
|
||||||
}
|
}
|
||||||
for (String perm : this.getPermissionList()) {
|
for (String perm : this.getPermissionList()) {
|
||||||
clone.addPermission(perm);
|
clone.addPermission(perm);
|
||||||
@ -117,13 +117,20 @@ public class User extends DataUnit implements Cloneable {
|
|||||||
getDataSource().addGroup(group);
|
getDataSource().addGroup(group);
|
||||||
}
|
}
|
||||||
group = getDataSource().getGroup(group.getName());
|
group = getDataSource().getGroup(group.getName());
|
||||||
|
String oldGroup = this.group;
|
||||||
this.group = group.getName();
|
this.group = group.getName();
|
||||||
flagAsChanged();
|
flagAsChanged();
|
||||||
if (GroupManager.isLoaded()) {
|
if (GroupManager.isLoaded()) {
|
||||||
if (GroupManager.BukkitPermissions.player_join = false)
|
if (GroupManager.BukkitPermissions.player_join = false)
|
||||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
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))) ;
|
||||||
|
|
||||||
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ import org.yaml.snakeyaml.reader.UnicodeReader;
|
|||||||
public class WorldDataHolder {
|
public class WorldDataHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* World name
|
||||||
*/
|
*/
|
||||||
protected String name;
|
protected String name;
|
||||||
/**
|
/**
|
||||||
@ -321,24 +321,58 @@ public class WorldDataHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh Group data from file
|
||||||
|
*/
|
||||||
public void reloadGroups() {
|
public void reloadGroups() {
|
||||||
GroupManager.setLoaded(false);
|
GroupManager.setLoaded(false);
|
||||||
try {
|
try {
|
||||||
resetGroups();
|
// temporary holder in case the load fails.
|
||||||
loadGroups(this, getGroupsFile());
|
WorldDataHolder ph = new WorldDataHolder(this.getName());
|
||||||
|
|
||||||
|
loadGroups(ph, getGroupsFile());
|
||||||
|
// transfer new data
|
||||||
|
resetGroups();
|
||||||
|
for (Group tempGroup : ph.getGroupList()) {
|
||||||
|
tempGroup.clone(this);
|
||||||
|
}
|
||||||
|
this.setDefaultGroup(this.getGroup(ph.getDefaultGroup().getName()));
|
||||||
|
this.removeGroupsChangedFlag();
|
||||||
|
this.timeStampGroups = ph.getTimeStampGroups();
|
||||||
|
|
||||||
|
ph = null;
|
||||||
} catch (Exception ex) {
|
} 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);
|
GroupManager.setLoaded(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh Users data from file
|
||||||
|
*/
|
||||||
public void reloadUsers() {
|
public void reloadUsers() {
|
||||||
GroupManager.setLoaded(false);
|
GroupManager.setLoaded(false);
|
||||||
try {
|
try {
|
||||||
resetUsers();
|
// temporary holder in case the load fails.
|
||||||
loadUsers(this, getUsersFile());
|
WorldDataHolder ph = new WorldDataHolder(this.getName());
|
||||||
|
// copy groups for reference
|
||||||
|
for (Group tempGroup : this.getGroupList()) {
|
||||||
|
tempGroup.clone(ph);
|
||||||
|
}
|
||||||
|
// setup the default group before loading user data.
|
||||||
|
ph.setDefaultGroup(ph.getGroup(this.getDefaultGroup().getName()));
|
||||||
|
loadUsers(ph, getUsersFile());
|
||||||
|
// transfer new data
|
||||||
|
resetUsers();
|
||||||
|
for (User tempUser : ph.getUserList()) {
|
||||||
|
tempUser.clone(this);
|
||||||
|
}
|
||||||
|
this.removeUsersChangedFlag();
|
||||||
|
this.timeStampUsers = ph.getTimeStampUsers();
|
||||||
|
|
||||||
|
ph = null;
|
||||||
} catch (Exception ex) {
|
} 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);
|
GroupManager.setLoaded(true);
|
||||||
}
|
}
|
||||||
@ -523,29 +557,6 @@ public class WorldDataHolder {
|
|||||||
return ph;
|
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
|
* Updates the WorldDataHolder from the Groups file
|
||||||
*
|
*
|
||||||
@ -591,7 +602,7 @@ public class WorldDataHolder {
|
|||||||
}
|
}
|
||||||
if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) {
|
if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) {
|
||||||
if (ph.getDefaultGroup() != null) {
|
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.");
|
GroupManager.logger.warning("Overriding first request.");
|
||||||
}
|
}
|
||||||
ph.setDefaultGroup(thisGrp);
|
ph.setDefaultGroup(thisGrp);
|
||||||
@ -662,7 +673,7 @@ public class WorldDataHolder {
|
|||||||
ph.removeGroupsChangedFlag();
|
ph.removeGroupsChangedFlag();
|
||||||
// Update the LastModified time.
|
// Update the LastModified time.
|
||||||
ph.groupsFile = groupsFile;
|
ph.groupsFile = groupsFile;
|
||||||
ph.setTimeStamps();
|
ph.setTimeStampGroups(groupsFile.lastModified());
|
||||||
|
|
||||||
//return ph;
|
//return ph;
|
||||||
}
|
}
|
||||||
@ -769,7 +780,7 @@ public class WorldDataHolder {
|
|||||||
ph.removeUsersChangedFlag();
|
ph.removeUsersChangedFlag();
|
||||||
// Update the LastModified time.
|
// Update the LastModified time.
|
||||||
ph.usersFile = usersFile;
|
ph.usersFile = usersFile;
|
||||||
ph.setTimeStamps();
|
ph.setTimeStampUsers(usersFile.lastModified());
|
||||||
|
|
||||||
//return ph;
|
//return ph;
|
||||||
}
|
}
|
||||||
|
@ -200,8 +200,8 @@ public class WorldsHolder {
|
|||||||
//Check for newer file as no local changes.
|
//Check for newer file as no local changes.
|
||||||
if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) {
|
if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) {
|
||||||
System.out.print("Newer Groups file found (Loading changes)!");
|
System.out.print("Newer Groups file found (Loading changes)!");
|
||||||
// Backup Users file
|
// Backup Groups file
|
||||||
backupFile(w,false);
|
backupFile(w,true);
|
||||||
w.reloadGroups();
|
w.reloadGroups();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@ users:
|
|||||||
subgroups: []
|
subgroups: []
|
||||||
permissions: []
|
permissions: []
|
||||||
group: Admin
|
group: Admin
|
||||||
mudzereli:
|
KHobbits:
|
||||||
subgroups: []
|
subgroups: []
|
||||||
permissions: []
|
permissions: []
|
||||||
group: Builder
|
group: Moderator
|
||||||
ElgarL:
|
ElgarL:
|
||||||
subgroups: []
|
subgroups: []
|
||||||
permissions: []
|
permissions: []
|
||||||
group: Admin
|
group: Owner
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user