diff options
author | ElgarL <ElgarL@palmergames.com> | 2011-10-31 08:34:57 +0000 |
---|---|---|
committer | ElgarL <ElgarL@palmergames.com> | 2011-10-31 08:34:57 +0000 |
commit | 0f67d42c9965ecbacc52e7f938dcae0c978d3dbd (patch) | |
tree | 76aec9adff9696665a216b6738902f46949a955e /EssentialsGroupManager | |
parent | 34ba8e89bc9e9be00a539bb07a8ddaca16f9e954 (diff) | |
download | Essentials-0f67d42c9965ecbacc52e7f938dcae0c978d3dbd.tar Essentials-0f67d42c9965ecbacc52e7f938dcae0c978d3dbd.tar.gz Essentials-0f67d42c9965ecbacc52e7f938dcae0c978d3dbd.tar.lz Essentials-0f67d42c9965ecbacc52e7f938dcae0c978d3dbd.tar.xz Essentials-0f67d42c9965ecbacc52e7f938dcae0c978d3dbd.zip |
Global Groups yml and class
Diffstat (limited to 'EssentialsGroupManager')
-rw-r--r-- | EssentialsGroupManager/src/globalgroups.yml | 181 | ||||
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java | 291 |
2 files changed, 472 insertions, 0 deletions
diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml new file mode 100644 index 000000000..43c225b6a --- /dev/null +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -0,0 +1,181 @@ +groups:
+
+ g:bukkit_default:
+ permissions:
+ - bukkit.broadcast.user
+
+ g:essentials_default:
+ permissions:
+ - essentials.help
+ - essentials.helpop
+ - essentials.list
+ - essentials.motd
+ - essentials.rules
+ - essentials.spawn
+ - groupmanager.notify.self
+
+ g:essentials_builder:
+ 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
+
+ g:essentials_moderator:
+ 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
+
+ g:essentials_admin:
+ permissions:
+ - -essentials.backup
+ - -essentials.essentials
+ - -essentials.setspawn
+ - -essentials.reloadall
+ - -essentials.plugin
+ - essentials.*
+ - groupmanager.mantogglevalidate
+ - groupmanager.mansave
+ - groupmanager.mangcheckp
+ - groupmanager.manglistp
+ - groupmanager.manucheckp
+ - groupmanager.manulistp
+
+ g:bukkit_moderator:
+ permissions:
+ - bukkit.command.ban
+ - bukkit.command.ban.ip
+ - bukkit.command.ban.player
+ - bukkit.command.gamemode
+ - bukkit.command.kick
+ - bukkit.command.unban
+ - bukkit.command.unban.ip
+ - bukkit.command.unban.player
+
+ g:bukkit_admin:
+ permissions:
+ - bPermissions.admin
+ - bPermissions.demote.admin
+ - bPermissions.gui
+ - bPermissions.iplock.lock
+ - bPermissions.promote.admin
+ - bukkit.broadcast
+ - bukkit.broadcast.admin
+ - bukkit.command
+ - bukkit.command.give
+ - bukkit.command.help
+ - bukkit.command.kill
+ - bukkit.command.list
+ - bukkit.command.me
+ - bukkit.command.op
+ - bukkit.command.op.give
+ - bukkit.command.op.take
+ - bukkit.command.plugins
+ - bukkit.command.reload
+ - bukkit.command.save
+ - bukkit.command.save.disable
+ - bukkit.command.save.enable
+ - bukkit.command.save.perform
+ - bukkit.command.say
+ - bukkit.command.stop
+ - bukkit.command.teleport
+ - bukkit.command.tell
+ - bukkit.command.time
+ - bukkit.command.time.add
+ - bukkit.command.time.set
+ - bukkit.command.version
+ - bukkit.command.whitelist
+ - bukkit.command.whitelist.add
+ - bukkit.command.whitelist.disable
+ - bukkit.command.whitelist.enable
+ - bukkit.command.whitelist.list
+ - bukkit.command.whitelist.reload
+ - bukkit.command.whitelist.remove
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java new file mode 100644 index 000000000..72bedc106 --- /dev/null +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -0,0 +1,291 @@ +package org.anjocaido.groupmanager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+
+import org.anjocaido.groupmanager.data.Group;
+import org.anjocaido.groupmanager.utils.PermissionCheckResult;
+import org.anjocaido.groupmanager.utils.Tasks;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.Yaml;
+
+
+
+/**
+ * @author ElgarL
+ *
+ */
+public class GlobalGroups {
+
+ private GroupManager plugin;
+ private YamlConfiguration GGroups;
+
+ private Map<String, Group> groups;
+ /**
+ *
+ */
+ protected boolean haveGroupsChanged = false;
+
+ public GlobalGroups(GroupManager plugin) {
+ this.plugin = plugin;
+ load();
+ }
+
+ /**
+ * @return the haveGroupsChanged
+ */
+ public boolean haveGroupsChanged() {
+ if (this.haveGroupsChanged) {
+ return true;
+ }
+ for (Group g : groups.values()) {
+ if (g.isChanged()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param haveGroupsChanged the haveGroupsChanged to set
+ */
+ public void setGroupsChanged(boolean haveGroupsChanged) {
+ this.haveGroupsChanged = haveGroupsChanged;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void load() {
+
+ GGroups = new YamlConfiguration();
+ groups = new HashMap<String, Group>();
+
+ // READ globalGroups FILE
+ File GlobalGroupsFile = new File(plugin.getDataFolder(),
+ "globalgroups.yml");
+
+ if (!GlobalGroupsFile.exists()) {
+ try {
+ // Create a new file if it doesn't exist.
+ Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"),
+ GlobalGroupsFile);
+ } catch (IOException ex) {
+ GroupManager.logger.log(Level.SEVERE, null, ex);
+ }
+ }
+
+ try {
+ GGroups.load(GlobalGroupsFile);
+ } catch (Exception ex) {
+ throw new IllegalArgumentException(
+ "The following file couldn't pass on Parser.\n"
+ + GlobalGroupsFile.getPath(), ex);
+ }
+
+ // Read all global groups
+ Map<String, Object> allGroups = (Map<String, Object>) GGroups
+ .getConfigurationSection("groups").getValues(false);
+
+ // Load each groups permissions list.
+ if (allGroups != null)
+ for (String groupName : allGroups.keySet()) {
+ Group newGroup = new Group(groupName.toLowerCase());
+ Object permissions = GGroups.get("groups." + groupName
+ + ".permissions");
+
+ if (permissions instanceof List) {
+ for (String permission : (List<String>) permissions) {
+ newGroup.addPermission(permission);
+ }
+ } else if (permissions instanceof String) {
+ newGroup.addPermission((String) permissions);
+ }
+
+ // Push a new group
+ addGroup(newGroup);
+ }
+
+ GlobalGroupsFile = null;
+
+ }
+
+ /**
+ * Write a dataHolder in a specified file
+ * @param ph
+ * @param groupsFile
+ */
+
+ public void writeGroups() {
+
+ File GlobalGroupsFile = new File(plugin.getDataFolder(),
+ "globalgroups.yml");
+
+ Map<String, Object> root = new HashMap<String, Object>();
+
+ Map<String, Object> groupsMap = new HashMap<String, Object>();
+ root.put("groups", groupsMap);
+ for (String groupKey : groups.keySet()) {
+ Group group = groups.get(groupKey);
+
+ Map<String, Object> aGroupMap = new HashMap<String, Object>();
+ groupsMap.put(group.getName(), aGroupMap);
+
+ aGroupMap.put("permissions", group.getPermissionList());
+ }
+
+ if (!root.isEmpty()) {
+ DumperOptions opt = new DumperOptions();
+ opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ final Yaml yaml = new Yaml(opt);
+ try {
+ yaml.dump(root, new OutputStreamWriter(new FileOutputStream(GlobalGroupsFile), "UTF-8"));
+ } catch (UnsupportedEncodingException ex) {
+ } catch (FileNotFoundException ex) {
+ }
+ }
+
+ }
+
+ /**
+ * Add a new group if it doesn't already exist.
+ *
+ * @param newGroup
+ */
+ public Group addGroup(Group newGroup) {
+ // Push a new group
+ if (!groups.containsKey(newGroup.getName().toLowerCase())) {
+ groups.put(newGroup.getName().toLowerCase(), newGroup);
+ this.setGroupsChanged(true);
+ return newGroup;
+ }
+ return null;
+ }
+
+ /**
+ * Delete a group if it exist.
+ *
+ * @param newGroup
+ */
+ public boolean removeGroup(String groupName) {
+ // Push a new group
+ if (groups.containsKey(groupName.toLowerCase())) {
+ groups.remove(groupName.toLowerCase());
+ this.setGroupsChanged(true);
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Returns true if the Global Group exists in the globalgroups.yml
+ *
+ * @param groupName
+ * @return
+ */
+ public boolean hasGroup(String groupName) {
+ return groups.containsKey(groupName.toLowerCase());
+ }
+
+ /**
+ * Returns true if the group has the correct permission node.
+ *
+ * @param groupName
+ * @param permissionNode
+ * @return
+ */
+ public boolean hasPermission(String groupName, String permissionNode) {
+
+ if (!hasGroup(groupName.toLowerCase()))
+ return false;
+
+ return groups.get(groupName.toLowerCase()).hasSamePermissionNode(
+ permissionNode);
+
+ }
+
+ /**
+ * Returns a PermissionCheckResult of the permission node for the group to
+ * be tested against.
+ *
+ * @param groupName
+ * @param permissionNode
+ * @return
+ */
+ public PermissionCheckResult checkPermission(String groupName,
+ String permissionNode) {
+
+ PermissionCheckResult result = new PermissionCheckResult();
+ result.askedPermission = permissionNode;
+ result.resultType = PermissionCheckResult.Type.NOTFOUND;
+
+ if (!hasGroup(groupName.toLowerCase()))
+ return result;
+
+ Group tempGroup = groups.get(groupName.toLowerCase());
+
+ if (tempGroup.hasSamePermissionNode(permissionNode))
+ result.resultType = PermissionCheckResult.Type.FOUND;
+ if (tempGroup.hasSamePermissionNode("-" + permissionNode))
+ result.resultType = PermissionCheckResult.Type.NEGATION;
+ if (tempGroup.hasSamePermissionNode("+" + permissionNode))
+ result.resultType = PermissionCheckResult.Type.EXCEPTION;
+
+ return result;
+ }
+
+ /**
+ * Returns a List of all permission nodes for this group null if none
+ *
+ * @param groupName
+ * @return
+ */
+ public List<String> getGroupsPermissions(String groupName) {
+ if (!hasGroup(groupName.toLowerCase()))
+ return null;
+
+ return groups.get(groupName.toLowerCase()).getPermissionList();
+ }
+
+ /**
+ * Returns a Set of all global group names.
+ *
+ * @return
+ */
+ public Set<String> getGlobalGroups() {
+ return groups.keySet();
+ }
+
+ /**
+ *
+ * @return a collection of the groups
+ */
+ public Collection<Group> getGroupList() {
+ return groups.values();
+ }
+
+ /**
+ * Returns the Global Group or null if it doesn't exist.
+ *
+ * @param groupName
+ * @return
+ */
+ public Group getGroup(String groupName) {
+ if (!hasGroup(groupName.toLowerCase()))
+ return null;
+
+ return groups.get(groupName.toLowerCase());
+
+ }
+
+}
\ No newline at end of file |