diff options
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager')
6 files changed, 110 insertions, 24 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index a450b4bee..b74a29977 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -47,7 +47,7 @@ import org.bukkit.plugin.java.JavaPlugin; */ public class GroupManager extends JavaPlugin { - private File configFile; + //private File configFile; private File backupFolder; private Runnable commiter; private ScheduledThreadPoolExecutor scheduler; @@ -58,6 +58,9 @@ public class GroupManager extends JavaPlugin { private boolean isReady = false; private static boolean isLoaded = false; protected GMConfiguration config; + + protected static GlobalGroups globalGroups; + private GMLoggerHandler ch; public static BukkitPermissions BukkitPermissions; private static WorldListener WorldEvents; @@ -92,8 +95,12 @@ public class GroupManager extends JavaPlugin { GroupManager.logger.addHandler(ch); logger.setLevel(Level.ALL); if (worldsHolder == null) { + // Create the backup folder, if it doesn't exist. prepareFileFields(); + // Load the config.yml prepareConfig(); + // Load the global groups + globalGroups = new GlobalGroups(this); worldsHolder = new WorldsHolder(this); } @@ -138,7 +145,7 @@ public class GroupManager extends JavaPlugin { } private void prepareFileFields() { - configFile = new File(this.getDataFolder(), "config.yml"); + //configFile = new File(this.getDataFolder(), "config.yml"); backupFolder = new File(this.getDataFolder(), "backup"); if (!backupFolder.exists()) { getBackupFolder().mkdirs(); @@ -1537,6 +1544,9 @@ public class GroupManager extends JavaPlugin { for (Group g : dataHolder.getGroupList()) { auxString += g.getName() + ", "; } + for (Group g : getGlobalGroups().getGroupList()) { + auxString += g.getName() + ", "; + } if (auxString.lastIndexOf(",") > 0) { auxString = auxString.substring(0, auxString.lastIndexOf(",")); } @@ -1796,4 +1806,9 @@ public class GroupManager extends JavaPlugin { public File getBackupFolder() { return backupFolder; } + + public static GlobalGroups getGlobalGroups() { + return globalGroups; + + } }
\ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java index 7b027a94d..6f2fdd3b3 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java @@ -26,7 +26,11 @@ public abstract class DataUnit { this.name = name; } - /** + public DataUnit(String name) { + this.name = name; + } + + /** * Every group is matched only by their names and DataSources names. * @param o * @return true if they are equal. false if not. @@ -64,7 +68,15 @@ public abstract class DataUnit { } 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()){ // GroupManager.logger.finest(st.toString()); // } @@ -76,7 +88,15 @@ public abstract class DataUnit { } 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; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index 84d4fceed..09eabb43f 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -27,12 +27,22 @@ public class Group extends DataUnit implements Cloneable { private GroupVariables variables = new GroupVariables(this); /** + * Constructor for individual World Groups. * * @param name */ public Group(WorldDataHolder source, String name) { super(source, name); } + + /** + * Constructor for Global Groups. + * + * @param name + */ + public Group(String name) { + super(name); + } /** * Clone this group diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index c8dc8cbd1..c8aa15cec 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -183,7 +183,10 @@ public class WorldDataHolder { * @return a group if it is found. null if not found. */ 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. */ 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 */ public boolean removeGroup(String groupName) { + if (groupName.startsWith("g:")) { + return GroupManager.getGlobalGroups().removeGroup(groupName); + } + if (defaultGroup != null && groupName.equalsIgnoreCase(defaultGroup.getName())) { return false; } @@ -251,10 +261,16 @@ public class WorldDataHolder { * @return null if group already exists. or new Group */ 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; } - Group newGroup = new Group(this, groupName); + + Group newGroup = new Group(this, groupName); this.addGroup(newGroup); haveGroupsChanged = true; return newGroup; diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java index 7c40e19f5..f5b55a25a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java @@ -149,6 +149,8 @@ public class WorldsHolder { w.reload(); alreadyDone.add(w); } + // Load global groups + GroupManager.getGlobalGroups().load(); } /** @@ -196,6 +198,10 @@ public class WorldsHolder { } alreadyDone.add(w); } + // Write Global Groups + if (GroupManager.getGlobalGroups().haveGroupsChanged()) { + GroupManager.getGlobalGroups().writeGroups(); + } } /** diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index 203ac95a9..99f6fb5c3 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -93,22 +93,40 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { List<String> playerPermArray = new ArrayList<String>(ph.getUser(userName).getPermissionList()); - for (String group : getGroups(userName)) { - 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); - } - } - + for (String group : getGroups(userName)) { + if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) { + for (String perm : GroupManager.getGlobalGroups().getGroupsPermissions(group)) { + 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); + } + } + } } - } + + } 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; @@ -935,6 +953,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { for (Group subg : ph.getUser(userName).subGroupListCopy()) { allGroups.addAll(listAllGroupsInherited(subg)); } + String[] arr = new String[allGroups.size()]; return allGroups.toArray(arr); } |