Added Global Groups

Defined in groupmanager/globalgroups.yml.
Create groups in the yml with a g: prefix, then inherit in the worlds
groups files.
This commit is contained in:
ElgarL 2011-10-31 08:34:07 +00:00
parent b1c6173995
commit 34ba8e89bc
8 changed files with 126 additions and 142 deletions

View file

@ -55,4 +55,7 @@ v 1.5:
- Fixed GM to recognize Superperm child nodes. - Fixed GM to recognize Superperm child nodes.
If you add a node like Towny.admin GM will now correctly report on all child nodes. If you add a node like Towny.admin GM will now correctly report on all child nodes.
- Fixed GM loading world data files twice at startup. - Fixed GM loading world data files twice at startup.
- Improved error reporting for invalid groups.yml - Improved error reporting for invalid groups.yml
- Added Global Groups
Defined in groupmanager/globalgroups.yml.
Create groups in the yml with a g: prefix, then inherit in the worlds groups files.

View file

@ -2,147 +2,42 @@ groups:
Default: Default:
default: true default: true
permissions: permissions:
- essentials.help - -bukkit.command.kill
- essentials.helpop inheritance:
- essentials.list - g:essentials_default
- essentials.motd - g:bukkit_default
- essentials.rules
- essentials.spawn
- groupmanager.notify.self
inheritance: []
info: info:
prefix: '&e' prefix: '&e'
build: false build: false
suffix: '' suffix: ''
Builder: Builder:
default: false default: false
permissions: permissions: []
- essentials.afk
- essentials.back
- essentials.back.ondeath
- essentials.balance
- essentials.balance.others
- essentials.balancetop
- essentials.chat.color
- essentials.chat.shout
- essentials.chat.question
- essentials.compass
- essentials.depth
- essentials.home
- essentials.ignore
- essentials.kit
- essentials.kit.tools
- essentials.mail
- essentials.mail.send
- essentials.me
- essentials.msg
- essentials.nick
- essentials.pay
- essentials.ping
- essentials.powertool
- essentials.protect
- essentials.sethome
- essentials.signs.use.*
- essentials.signs.create.disposal
- essentials.signs.create.mail
- essentials.signs.create.protection
- essentials.signs.create.trade
- essentials.signs.break.disposal
- essentials.signs.break.mail
- essentials.signs.break.protection
- essentials.signs.break.trade
- essentials.suicide
- essentials.time
- essentials.tpa
- essentials.tpaccept
- essentials.tpahere
- essentials.tpdeny
- essentials.warp
- essentials.warp.list
- essentials.worth
inheritance: inheritance:
- default - default
- g:essentials_builder
info: info:
prefix: '&2' prefix: '&2'
build: true build: true
suffix: '' suffix: ''
Moderator: Moderator:
default: false default: false
permissions: permissions: []
- essentials.ban
- essentials.ban.notify
- essentials.banip
- essentials.broadcast
- essentials.clearinventory
- essentials.delwarp
- essentials.eco.loan
- essentials.ext
- essentials.getpos
- essentials.helpop.recieve
- essentials.home.others
- essentials.invsee
- essentials.jails
- essentials.jump
- essentials.kick
- essentials.kick.notify
- essentials.kill
- essentials.mute
- essentials.nick.others
- essentials.realname
- essentials.setwarp
- essentials.signs.create.*
- essentials.signs.break.*
- essentials.spawner
- essentials.thunder
- essentials.time
- essentials.time.set
- essentials.protect.alerts
- essentials.protect.admin
- essentials.protect.ownerinfo
- essentials.ptime
- essentials.ptime.others
- essentials.togglejail
- essentials.top
- essentials.tp
- essentials.tphere
- essentials.tppos
- essentials.tptoggle
- essentials.unban
- essentials.unbanip
- essentials.weather
- essentials.whois
- essentials.world
- groupmanager.listgroups
- groupmanager.mandemote
- groupmanager.manpromote
- groupmanager.manselect
- groupmanager.manuadd
- groupmanager.manudel
- groupmanager.manwhois
- groupmanager.notify.other
inheritance: inheritance:
- builder - builder
- g:essentials_moderator
- g:bukkit_moderator
info: info:
prefix: '&5' prefix: '&5'
build: true build: true
suffix: '' suffix: ''
Admin: Admin:
default: false default: false
permissions: permissions: []
- -essentials.backup
- -essentials.essentials
- -essentials.setspawn
- -essentials.reloadall
- -essentials.plugin
- essentials.*
- groupmanager.mantogglevalidate
- groupmanager.mansave
- groupmanager.mangcheckp
- groupmanager.manglistp
- groupmanager.manucheckp
- groupmanager.manulistp
inheritance: inheritance:
- moderator - moderator
- g:essentials_admin
- g:bukkit_admin
info: info:
prefix: '&c' prefix: '&c'
build: true build: true

View file

@ -47,7 +47,7 @@ import org.bukkit.plugin.java.JavaPlugin;
*/ */
public class GroupManager extends JavaPlugin { public class GroupManager extends JavaPlugin {
private File configFile; //private File configFile;
private File backupFolder; private File backupFolder;
private Runnable commiter; private Runnable commiter;
private ScheduledThreadPoolExecutor scheduler; private ScheduledThreadPoolExecutor scheduler;
@ -58,6 +58,9 @@ public class GroupManager extends JavaPlugin {
private boolean isReady = false; private boolean isReady = false;
private static boolean isLoaded = false; private static boolean isLoaded = false;
protected GMConfiguration config; protected GMConfiguration config;
protected static GlobalGroups globalGroups;
private GMLoggerHandler ch; private GMLoggerHandler ch;
public static BukkitPermissions BukkitPermissions; public static BukkitPermissions BukkitPermissions;
private static WorldListener WorldEvents; private static WorldListener WorldEvents;
@ -92,8 +95,12 @@ public class GroupManager extends JavaPlugin {
GroupManager.logger.addHandler(ch); GroupManager.logger.addHandler(ch);
logger.setLevel(Level.ALL); logger.setLevel(Level.ALL);
if (worldsHolder == null) { if (worldsHolder == null) {
// Create the backup folder, if it doesn't exist.
prepareFileFields(); prepareFileFields();
// Load the config.yml
prepareConfig(); prepareConfig();
// Load the global groups
globalGroups = new GlobalGroups(this);
worldsHolder = new WorldsHolder(this); worldsHolder = new WorldsHolder(this);
} }
@ -138,7 +145,7 @@ public class GroupManager extends JavaPlugin {
} }
private void prepareFileFields() { private void prepareFileFields() {
configFile = new File(this.getDataFolder(), "config.yml"); //configFile = new File(this.getDataFolder(), "config.yml");
backupFolder = new File(this.getDataFolder(), "backup"); backupFolder = new File(this.getDataFolder(), "backup");
if (!backupFolder.exists()) { if (!backupFolder.exists()) {
getBackupFolder().mkdirs(); getBackupFolder().mkdirs();
@ -1537,6 +1544,9 @@ public class GroupManager extends JavaPlugin {
for (Group g : dataHolder.getGroupList()) { for (Group g : dataHolder.getGroupList()) {
auxString += g.getName() + ", "; auxString += g.getName() + ", ";
} }
for (Group g : getGlobalGroups().getGroupList()) {
auxString += g.getName() + ", ";
}
if (auxString.lastIndexOf(",") > 0) { if (auxString.lastIndexOf(",") > 0) {
auxString = auxString.substring(0, auxString.lastIndexOf(",")); auxString = auxString.substring(0, auxString.lastIndexOf(","));
} }
@ -1796,4 +1806,9 @@ public class GroupManager extends JavaPlugin {
public File getBackupFolder() { public File getBackupFolder() {
return backupFolder; return backupFolder;
} }
public static GlobalGroups getGlobalGroups() {
return globalGroups;
}
} }

View file

@ -26,7 +26,11 @@ public abstract class DataUnit {
this.name = name; this.name = name;
} }
/** public DataUnit(String name) {
this.name = name;
}
/**
* Every group is matched only by their names and DataSources names. * Every group is matched only by their names and DataSources names.
* @param o * @param o
* @return true if they are equal. false if not. * @return true if they are equal. false if not.
@ -64,7 +68,15 @@ public abstract class DataUnit {
} }
public void flagAsChanged() { public void flagAsChanged() {
GroupManager.logger.finest("DataSource: " + getDataSource().getName() + " - DataUnit: " + getName() + " flagged as changed!"); WorldDataHolder testSource = getDataSource();
String source = "";
if (testSource == null)
source = "GlobalGroups";
else
source = testSource.getName();
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!");
// for(StackTraceElement st: Thread.currentThread().getStackTrace()){ // for(StackTraceElement st: Thread.currentThread().getStackTrace()){
// GroupManager.logger.finest(st.toString()); // GroupManager.logger.finest(st.toString());
// } // }
@ -76,7 +88,15 @@ public abstract class DataUnit {
} }
public void flagAsSaved() { public void flagAsSaved() {
GroupManager.logger.finest("DataSource: " + getDataSource().getName() + " - DataUnit: " + getName() + " flagged as saved!"); WorldDataHolder testSource = getDataSource();
String source = "";
if (testSource == null)
source = "GlobalGroups";
else
source = testSource.getName();
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as saved!");
changed = false; changed = false;
} }

View file

@ -27,12 +27,22 @@ public class Group extends DataUnit implements Cloneable {
private GroupVariables variables = new GroupVariables(this); private GroupVariables variables = new GroupVariables(this);
/** /**
* Constructor for individual World Groups.
* *
* @param name * @param name
*/ */
public Group(WorldDataHolder source, String name) { public Group(WorldDataHolder source, String name) {
super(source, name); super(source, name);
} }
/**
* Constructor for Global Groups.
*
* @param name
*/
public Group(String name) {
super(name);
}
/** /**
* Clone this group * Clone this group

View file

@ -183,7 +183,10 @@ public class WorldDataHolder {
* @return a group if it is found. null if not found. * @return a group if it is found. null if not found.
*/ */
public Group getGroup(String groupName) { public Group getGroup(String groupName) {
return groups.get(groupName.toLowerCase()); if (groupName.startsWith("g:"))
return GroupManager.getGlobalGroups().getGroup(groupName);
else
return groups.get(groupName.toLowerCase());
} }
/** /**
@ -193,7 +196,10 @@ public class WorldDataHolder {
* @return true if exists. false if not. * @return true if exists. false if not.
*/ */
public boolean groupExists(String groupName) { public boolean groupExists(String groupName) {
return groups.containsKey(groupName.toLowerCase()); if (groupName.startsWith("g:"))
return GroupManager.getGlobalGroups().hasGroup(groupName);
else
return groups.containsKey(groupName.toLowerCase());
} }
/** /**
@ -215,6 +221,10 @@ public class WorldDataHolder {
* @return true if had something to remove. false the group was default or non-existant * @return true if had something to remove. false the group was default or non-existant
*/ */
public boolean removeGroup(String groupName) { public boolean removeGroup(String groupName) {
if (groupName.startsWith("g:")) {
return GroupManager.getGlobalGroups().removeGroup(groupName);
}
if (defaultGroup != null && groupName.equalsIgnoreCase(defaultGroup.getName())) { if (defaultGroup != null && groupName.equalsIgnoreCase(defaultGroup.getName())) {
return false; return false;
} }
@ -251,10 +261,16 @@ public class WorldDataHolder {
* @return null if group already exists. or new Group * @return null if group already exists. or new Group
*/ */
public Group createGroup(String groupName) { public Group createGroup(String groupName) {
if (this.groups.containsKey(groupName.toLowerCase())) { if (groupName.startsWith("g:")) {
Group newGroup = new Group(groupName);
return GroupManager.getGlobalGroups().addGroup(newGroup);
}
if (this.groups.containsKey(groupName.toLowerCase())) {
return null; return null;
} }
Group newGroup = new Group(this, groupName);
Group newGroup = new Group(this, groupName);
this.addGroup(newGroup); this.addGroup(newGroup);
haveGroupsChanged = true; haveGroupsChanged = true;
return newGroup; return newGroup;

View file

@ -149,6 +149,8 @@ public class WorldsHolder {
w.reload(); w.reload();
alreadyDone.add(w); alreadyDone.add(w);
} }
// Load global groups
GroupManager.getGlobalGroups().load();
} }
/** /**
@ -196,6 +198,10 @@ public class WorldsHolder {
} }
alreadyDone.add(w); alreadyDone.add(w);
} }
// Write Global Groups
if (GroupManager.getGlobalGroups().haveGroupsChanged()) {
GroupManager.getGlobalGroups().writeGroups();
}
} }
/** /**

View file

@ -93,22 +93,40 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
List<String> playerPermArray = new ArrayList<String>(ph.getUser(userName).getPermissionList()); List<String> playerPermArray = new ArrayList<String>(ph.getUser(userName).getPermissionList());
for (String group : getGroups(userName)) { for (String group : getGroups(userName)) {
for (String perm : ph.getGroup(group).getPermissionList()) { if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) { for (String perm : GroupManager.getGlobalGroups().getGroupsPermissions(group)) {
playerPermArray.add(perm); if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) {
playerPermArray.add(perm);
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
if (children != null) { Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
for (String child : children.keySet()) { if (children != null) {
if (children.get(child)) for (String child : children.keySet()) {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) if (children.get(child))
playerPermArray.add(child); if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm)))
} playerPermArray.add(child);
} }
}
}
} }
}
} else {
for (String perm : ph.getGroup(group).getPermissionList()) {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm))) {
playerPermArray.add(perm);
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
if (children != null) {
for (String child : children.keySet()) {
if (children.get(child))
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-"+perm)))
playerPermArray.add(child);
}
}
}
}
}
} }
return playerPermArray; return playerPermArray;
@ -935,6 +953,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
for (Group subg : ph.getUser(userName).subGroupListCopy()) { for (Group subg : ph.getUser(userName).subGroupListCopy()) {
allGroups.addAll(listAllGroupsInherited(subg)); allGroups.addAll(listAllGroupsInherited(subg));
} }
String[] arr = new String[allGroups.size()]; String[] arr = new String[allGroups.size()];
return allGroups.toArray(arr); return allGroups.toArray(arr);
} }