summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2011-11-04 11:40:33 +0000
committerKHobbits <rob@khobbits.co.uk>2011-11-04 11:40:33 +0000
commitfd4c82b0eb947042d4ff64393b7350ce9fc5e11e (patch)
tree4b9188ed69c30e174d0783c1467111bfcda50602
parent70d1c7d7d7acc97d32ebd83de56c8d476ea1a487 (diff)
parent52c2110a2b7e8be079588e5abe2bd7b1a89546ef (diff)
downloadEssentials-fd4c82b0eb947042d4ff64393b7350ce9fc5e11e.tar
Essentials-fd4c82b0eb947042d4ff64393b7350ce9fc5e11e.tar.gz
Essentials-fd4c82b0eb947042d4ff64393b7350ce9fc5e11e.tar.lz
Essentials-fd4c82b0eb947042d4ff64393b7350ce9fc5e11e.tar.xz
Essentials-fd4c82b0eb947042d4ff64393b7350ce9fc5e11e.zip
Merge remote branch 'remotes/ess/groupmanager' into essmaster
-rw-r--r--EssentialsGroupManager/src/Changelog.txt18
-rw-r--r--EssentialsGroupManager/src/config.yml4
-rw-r--r--EssentialsGroupManager/src/globalgroups.yml181
-rw-r--r--EssentialsGroupManager/src/groups.yml129
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java6
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java393
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java3539
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java26
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java21
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java2
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java2
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java2
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java2
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java11
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java300
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java128
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java2181
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java2
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java139
19 files changed, 4012 insertions, 3074 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt
index 9a2eff5f2..5262c7018 100644
--- a/EssentialsGroupManager/src/Changelog.txt
+++ b/EssentialsGroupManager/src/Changelog.txt
@@ -53,4 +53,20 @@ v 1.5:
- Fixed opOverrides and bukkit_perms_override to read the correct entries.
- Better commenting in config.yml
- Fixed GM to recognize Superperm child nodes.
- If you add a node like Towny.admin GM will now correctly report on all child nodes. \ No newline at end of file
+ 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.
+ - 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.
+ - Added Info node support to Global Groups.
+ - Fixed an error on 'manucheckv'. If the users doesn't have the variable it fell through causing an exception.
+ - Added checking of subgroups for Info nodes.
+ - Expanded 'canUserBuild()' to include inheritance and subgroups.
+ - Added a config.yml setting of 'validate_toggle' for those who prefer 'mantogglevalidate' to always be off.
+ - Prevent setting 'minutes' in the config to zero causing an error.
+ - GM will now check to see if it's data files have been changed at each scheduled save.
+ 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.
+ 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. \ No newline at end of file
diff --git a/EssentialsGroupManager/src/config.yml b/EssentialsGroupManager/src/config.yml
index 6bea3e3e0..d9f469477 100644
--- a/EssentialsGroupManager/src/config.yml
+++ b/EssentialsGroupManager/src/config.yml
@@ -8,6 +8,10 @@ settings:
# If the player is op any permissions set to Op will follow suit.
bukkit_perms_override: false
+ # Default setting for 'mantoglevalidate'
+ # true will cause GroupManager to attempt name matching by default.
+ validate_toggle: true
+
data:
save:
# How often GroupManager will save it's data back to groups and users.yml
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/groups.yml b/EssentialsGroupManager/src/groups.yml
index 6db09bdf2..ac4abeb4a 100644
--- a/EssentialsGroupManager/src/groups.yml
+++ b/EssentialsGroupManager/src/groups.yml
@@ -2,147 +2,42 @@ groups:
Default:
default: true
permissions:
- - essentials.help
- - essentials.helpop
- - essentials.list
- - essentials.motd
- - essentials.rules
- - essentials.spawn
- - groupmanager.notify.self
- inheritance: []
+ - -bukkit.command.kill
+ inheritance:
+ - g:essentials_default
+ - g:bukkit_default
info:
prefix: '&e'
build: false
suffix: ''
Builder:
default: false
- 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
+ permissions: []
inheritance:
- default
+ - g:essentials_builder
info:
prefix: '&2'
build: true
suffix: ''
Moderator:
default: false
- 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
+ permissions: []
inheritance:
- builder
+ - g:essentials_moderator
+ - g:bukkit_moderator
info:
prefix: '&5'
build: true
suffix: ''
Admin:
default: false
- permissions:
- - -essentials.backup
- - -essentials.essentials
- - -essentials.setspawn
- - -essentials.reloadall
- - -essentials.plugin
- - essentials.*
- - groupmanager.mantogglevalidate
- - groupmanager.mansave
- - groupmanager.mangcheckp
- - groupmanager.manglistp
- - groupmanager.manucheckp
- - groupmanager.manulistp
+ permissions: []
inheritance:
- moderator
+ - g:essentials_admin
+ - g:bukkit_admin
info:
prefix: '&c'
build: true
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
index 521b8c1fb..591afe3fa 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
@@ -48,7 +48,10 @@ public class GMConfiguration {
} catch (Exception ex) {
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
}
+
+ // Setup defaults
adjustLoggerLevel();
+ plugin.setValidateOnlinePlayer(isToggleValidate());
}
public boolean isOpOverride() {
@@ -57,6 +60,9 @@ public class GMConfiguration {
public boolean isBukkitPermsOverride() {
return GMconfig.getBoolean("settings.config.bukkit_perms_override", false);
}
+ public boolean isToggleValidate() {
+ return GMconfig.getBoolean("settings.config.validate_toggle", true);
+ }
public Map<String, Object> getMirrorsMap() {
// Try to fetch the old mirror path first
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java
new file mode 100644
index 000000000..eef5ba59e
--- /dev/null
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java
@@ -0,0 +1,393 @@
+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.MemorySection;
+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 long timeStampGroups = 0;
+ protected boolean haveGroupsChanged = false;
+ protected File GlobalGroupsFile = null;
+
+ 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;
+ }
+
+ /**
+ * @return the timeStampGroups
+ */
+ public long getTimeStampGroups() {
+ return timeStampGroups;
+ }
+ /**
+ * @param timeStampGroups the timeStampGroups to set
+ */
+ protected void setTimeStampGroups(long timeStampGroups) {
+ this.timeStampGroups = timeStampGroups;
+ }
+
+ /**
+ * @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>();
+
+ GroupManager.setLoaded(false);
+
+ // READ globalGroups FILE
+ if (GlobalGroupsFile == null)
+ 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 element;
+
+ // Permission nodes
+ element = GGroups.get("groups." + groupName + ".permissions");
+
+ if (element != null)
+ if (element instanceof List) {
+ for (String node : (List<String>) element) {
+ newGroup.addPermission(node);
+ }
+ } else if (element instanceof String) {
+ newGroup.addPermission((String) element);
+ } else
+ throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName);
+
+ // Info nodes
+ element = GGroups.get("groups." + groupName + ".info");
+
+ if (element != null)
+ if (element instanceof MemorySection) {
+ Map<String, Object> vars = new HashMap<String, Object>();
+ for (String key : ((MemorySection) element).getKeys(false)) {
+ vars.put(key, ((MemorySection) element).get(key));
+ }
+ newGroup.setVariables(vars);
+ } else
+ throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName);
+
+ // Push a new group
+ addGroup(newGroup);
+ }
+
+ removeGroupsChangedFlag();
+ setTimeStampGroups(GlobalGroupsFile.lastModified());
+ GroupManager.setLoaded(true);
+ //GlobalGroupsFile = null;
+
+ }
+
+ /**
+ * Write the globalgroups.yml file
+ */
+
+ public void writeGroups(boolean overwrite) {
+
+ //File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
+
+ if (haveGroupsChanged()) {
+ if (overwrite || (!overwrite && (getTimeStampGroups() >= GlobalGroupsFile.lastModified()))) {
+ 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);
+
+ // Group header
+ Map<String, Object> aGroupMap = new HashMap<String, Object>();
+ groupsMap.put(group.getName(), aGroupMap);
+
+ // Info nodes
+ Map<String, Object> infoMap = new HashMap<String, Object>();
+ aGroupMap.put("info", infoMap);
+
+ for (String infoKey : group.getVariables().getVarKeyList()) {
+ infoMap.put(infoKey, group.getVariables().getVarObject(infoKey));
+ }
+
+ // Permission nodes
+ 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) {
+ }
+ }
+ setTimeStampGroups(GlobalGroupsFile.lastModified());
+ } else {
+ // Newer file found.
+ GroupManager.logger.log(Level.WARNING, "Newer GlobalGroups file found, but we have local changes!");
+ throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
+ }
+ removeGroupsChangedFlag();
+ } else {
+ //Check for newer file as no local changes.
+ if (getTimeStampGroups() < GlobalGroupsFile.lastModified()) {
+ System.out.print("Newer GlobalGroups file found (Loading changes)!");
+ // Backup GlobalGroups file
+ backupFile();
+ load();
+ }
+ }
+
+ }
+
+ /**
+ * Backup the BlobalGroups file
+ * @param w
+ */
+ private void backupFile() {
+
+ File backupFile = new File(plugin.getBackupFolder(), "bkp_ggroups_" + Tasks.getDateString() + ".yml");
+ try {
+ Tasks.copy(GlobalGroupsFile, backupFile);
+ } catch (IOException ex) {
+ GroupManager.logger.log(Level.SEVERE, null, ex);
+ }
+ }
+
+ /**
+ * Adds a group, or replaces an existing one.
+ *
+ * @param groupToAdd
+ */
+ public void addGroup(Group groupToAdd) {
+ // Create a new group if it already exists
+ if (hasGroup(groupToAdd.getName())) {
+ groupToAdd = groupToAdd.clone();
+ removeGroup(groupToAdd.getName());
+ }
+
+ newGroup(groupToAdd);
+ haveGroupsChanged = true;
+ }
+
+ /**
+ * Creates a new group if it doesn't already exist.
+ *
+ * @param newGroup
+ */
+ public Group newGroup(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 groupName
+ */
+ 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 true if the group exists
+ */
+ 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 true if node exists
+ */
+ 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 PermissionCheckResult object
+ */
+ 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 List of all group names
+ */
+ 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 Set containing all group names.
+ */
+ 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 Group object
+ */
+ public Group getGroup(String groupName) {
+ if (!hasGroup(groupName.toLowerCase()))
+ return null;
+
+ return groups.get(groupName.toLowerCase());
+
+ }
+
+ /**
+ * @return the globalGroupsFile
+ */
+ public File getGlobalGroupsFile() {
+ return GlobalGroupsFile;
+ }
+
+ /**
+ *
+ */
+ public void removeGroupsChangedFlag() {
+ setGroupsChanged(false);
+ for (Group g : groups.values()) {
+ g.flagAsSaved();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
index a450b4bee..d2d8d3b27 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
@@ -47,85 +47,110 @@ import org.bukkit.plugin.java.JavaPlugin;
*/
public class GroupManager extends JavaPlugin {
- private File configFile;
- private File backupFolder;
- private Runnable commiter;
- private ScheduledThreadPoolExecutor scheduler;
- private Map<String, ArrayList<User>> overloadedUsers = new HashMap<String, ArrayList<User>>();
- private Map<CommandSender, String> selectedWorlds = new HashMap<CommandSender, String>();
- private WorldsHolder worldsHolder;
- private boolean validateOnlinePlayer = true;
- private boolean isReady = false;
- private static boolean isLoaded = false;
- protected GMConfiguration config;
- private GMLoggerHandler ch;
- public static BukkitPermissions BukkitPermissions;
- private static WorldListener WorldEvents;
- public static final Logger logger = Logger.getLogger(GroupManager.class.getName());
-
- //PERMISSIONS FOR COMMAND BEING LOADED
- OverloadedWorldHolder dataHolder = null;
- AnjoPermissionsHandler permissionHandler = null;
-
- @Override
- public void onDisable() {
- setLoaded(false);
-
- if (worldsHolder != null) {
- worldsHolder.saveChanges();
- }
- disableScheduler();
-
- WorldEvents = null;
- BukkitPermissions = null;
-
- // EXAMPLE: Custom code, here we just output some info so we can check all is well
- PluginDescriptionFile pdfFile = this.getDescription();
- System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
- GroupManager.logger.removeHandler(ch);
- }
-
- @Override
- public void onEnable() {
- GroupManager.logger.setUseParentHandlers(false);
- ch = new GMLoggerHandler();
- GroupManager.logger.addHandler(ch);
- logger.setLevel(Level.ALL);
- if (worldsHolder == null) {
- prepareFileFields();
- prepareConfig();
- worldsHolder = new WorldsHolder(this);
- }
-
- PluginDescriptionFile pdfFile = this.getDescription();
- if (worldsHolder == null) {
- GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!");
- this.getServer().getPluginManager().disablePlugin(this);
- throw new IllegalStateException("An error ocurred while loading GroupManager");
- }
-
- // Initialize the world listener and bukkit permissions to handle events.
- WorldEvents = new GMWorldListener(this);
- BukkitPermissions = new BukkitPermissions(this);
-
- enableScheduler();
-
- /*
- * Schedule a Bukiit Permissions update for 1 tick later.
- * All plugins will be loaded by then
- */
-
- if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(),1) == -1) {
- GroupManager.logger.severe("Could not schedule superperms Update.");
- setLoaded(true);
- }
-
- System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
- }
-
-
-
- public static boolean isLoaded() {
+ // private File configFile;
+ private File backupFolder;
+ private Runnable commiter;
+ private ScheduledThreadPoolExecutor scheduler;
+ private Map<String, ArrayList<User>> overloadedUsers = new HashMap<String, ArrayList<User>>();
+ private Map<CommandSender, String> selectedWorlds = new HashMap<CommandSender, String>();
+ private WorldsHolder worldsHolder;
+ private boolean validateOnlinePlayer = true;
+ /**
+ * @return the validateOnlinePlayer
+ */
+ public boolean isValidateOnlinePlayer() {
+ return validateOnlinePlayer;
+ }
+
+ /**
+ * @param validateOnlinePlayer the validateOnlinePlayer to set
+ */
+ public void setValidateOnlinePlayer(boolean validateOnlinePlayer) {
+ this.validateOnlinePlayer = validateOnlinePlayer;
+ }
+
+ 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;
+ public static final Logger logger = Logger.getLogger(GroupManager.class.getName());
+
+ // PERMISSIONS FOR COMMAND BEING LOADED
+ OverloadedWorldHolder dataHolder = null;
+ AnjoPermissionsHandler permissionHandler = null;
+
+ @Override
+ public void onDisable() {
+ setLoaded(false);
+
+ disableScheduler(); // Shutdown before we save, so it doesn't interfere.
+ if (worldsHolder != null) {
+ try {
+ worldsHolder.saveChanges(false);
+ } catch (IllegalStateException ex) {
+ GroupManager.logger.log(Level.WARNING, ex.getMessage());
+ }
+ }
+
+ WorldEvents = null;
+ BukkitPermissions = null;
+
+ // EXAMPLE: Custom code, here we just output some info so we can check
+ // all is well
+ PluginDescriptionFile pdfFile = this.getDescription();
+ System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
+ GroupManager.logger.removeHandler(ch);
+ }
+
+ @Override
+ public void onEnable() {
+ GroupManager.logger.setUseParentHandlers(false);
+ ch = new GMLoggerHandler();
+ 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);
+ }
+
+ PluginDescriptionFile pdfFile = this.getDescription();
+ if (worldsHolder == null) {
+ GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!");
+ this.getServer().getPluginManager().disablePlugin(this);
+ throw new IllegalStateException("An error ocurred while loading GroupManager");
+ }
+
+ // Initialize the world listener and bukkit permissions to handle
+ // events.
+ WorldEvents = new GMWorldListener(this);
+ BukkitPermissions = new BukkitPermissions(this);
+
+ enableScheduler();
+
+ /*
+ * Schedule a Bukiit Permissions update for 1 tick later. All plugins
+ * will be loaded by then
+ */
+
+ if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) {
+ GroupManager.logger.severe("Could not schedule superperms Update.");
+ setLoaded(true);
+ }
+
+ System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
+ }
+
+ public static boolean isLoaded() {
return isLoaded;
}
@@ -134,1666 +159,1702 @@ public class GroupManager extends JavaPlugin {
}
public InputStream getResourceAsStream(String fileName) {
- return this.getClassLoader().getResourceAsStream(fileName);
- }
-
- private void prepareFileFields() {
- configFile = new File(this.getDataFolder(), "config.yml");
- backupFolder = new File(this.getDataFolder(), "backup");
- if (!backupFolder.exists()) {
- getBackupFolder().mkdirs();
- }
- }
-
- private void prepareConfig() {
- config = new GMConfiguration(this);
- }
-
- public void enableScheduler() {
- if (worldsHolder != null) {
- disableScheduler();
- commiter = new Runnable() {
-
- @Override
- public void run() {
- worldsHolder.saveChanges();
- }
- };
- scheduler = new ScheduledThreadPoolExecutor(1);
- int minutes = getGMConfig().getSaveInterval();
- scheduler.scheduleAtFixedRate(commiter, minutes, minutes, TimeUnit.MINUTES);
- GroupManager.logger.info("Scheduled Data Saving is set for every " + minutes + " minutes!");
- GroupManager.logger.info("Backups will be retained for " + getGMConfig().getBackupDuration() + " hours!");
- }
- }
-
- public void disableScheduler() {
- if (scheduler != null) {
- try {
- scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
- scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
- scheduler.shutdown();
- } catch (Exception e) {
- }
- scheduler = null;
- GroupManager.logger.info("Scheduled Data Saving is disabled!");
- }
- }
-
- /**
- * Use the WorldsHolder saveChanges directly instead
- * Saves the data on file
- */
- @Deprecated
- public void commit() {
- if (worldsHolder != null) {
- worldsHolder.saveChanges();
- }
- }
-
- /**
- * Use worlds holder to reload a specific world
- * Reloads the data
- */
- @Deprecated
- public void reload() {
- worldsHolder.reloadAll();
- }
-
- public WorldsHolder getWorldsHolder() {
- return worldsHolder;
- }
-
- /**
- * The handler in the interface created by AnjoCaido
- * @return
- */
- @Deprecated
- public AnjoPermissionsHandler getPermissionHandler() {
- return worldsHolder.getDefaultWorld().getPermissionsHandler();
- }
-
- /**
- * A simple interface, for ones that don't want to mess with overloading.
- * Yet it is affected by overloading. But seamless.
- * @return the dataholder with all information
- */
- @Deprecated
- public WorldDataHolder getData() {
- return worldsHolder.getDefaultWorld();
- }
-
- /**
- * Use this if you want to play with overloading.
- * @return a dataholder with overloading interface
- */
- @Deprecated
- public OverloadedWorldHolder getOverloadedClassData() {
- return worldsHolder.getDefaultWorld();
- }
-
- /**
- * Called when a command registered by this plugin is received.
- * @param sender
- * @param cmd
- * @param args
- */
- @SuppressWarnings({"deprecation"})
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- boolean playerCanDo = false;
- boolean isConsole = false;
- Player senderPlayer = null, targetPlayer = null;
- Group senderGroup = null;
- User senderUser = null;
- boolean isOpOverride = config.isOpOverride();
-
-
- //DETERMINING PLAYER INFORMATION
- if (sender instanceof Player) {
- senderPlayer = (Player) sender;
- senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName());
- senderGroup = senderUser.getGroup();
- isOpOverride = (isOpOverride && senderPlayer.isOp());
-
- System.out.println("[PLAYER_COMMAND] " + senderPlayer.getName() + ": /" + commandLabel + " " + Tasks.join(args, " "));
- if (isOpOverride || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager." + cmd.getName())) {
- playerCanDo = true;
- }
- } else if (sender instanceof ConsoleCommandSender) {
- isConsole = true;
- }
-
- //PERMISSIONS FOR COMMAND BEING LOADED
- dataHolder = null;
- permissionHandler = null;
-
- if (senderPlayer != null) {
- dataHolder = worldsHolder.getWorldData(senderPlayer);
- }
-
- String selectedWorld = selectedWorlds.get(sender);
- if (selectedWorld != null) {
- dataHolder = worldsHolder.getWorldData(selectedWorld);
- }
-
- if (dataHolder != null) {
- permissionHandler = dataHolder.getPermissionsHandler();
- }
-
- //VARIABLES USED IN COMMANDS
-
-
- int count;
- PermissionCheckResult permissionResult = null;
- ArrayList<User> removeList = null;
- String auxString = null;
- List<Player> match = null;
- User auxUser = null;
- Group auxGroup = null;
- Group auxGroup2 = null;
-
- GroupManagerPermissions execCmd = null;
- try {
- execCmd = GroupManagerPermissions.valueOf(cmd.getName());
- } catch (Exception e) {
- //this error happened once with someone. now im prepared... i think
- GroupManager.logger.severe("===================================================");
- GroupManager.logger.severe("= ERROR REPORT START =");
- GroupManager.logger.severe("===================================================");
- GroupManager.logger.severe("= COPY AND PASTE THIS TO GROUPMANAGER DEVELOPER =");
- GroupManager.logger.severe("===================================================");
- GroupManager.logger.severe(this.getDescription().getName());
- GroupManager.logger.severe(this.getDescription().getVersion());
- GroupManager.logger.severe("An error occured while trying to execute command:");
- GroupManager.logger.severe(cmd.getName());
- GroupManager.logger.severe("With " + args.length + " arguments:");
- for (String ar : args) {
- GroupManager.logger.severe(ar);
- }
- GroupManager.logger.severe("The field '" + cmd.getName() + "' was not found in enum.");
- GroupManager.logger.severe("And could not be parsed.");
- GroupManager.logger.severe("FIELDS FOUND IN ENUM:");
- for (GroupManagerPermissions val : GroupManagerPermissions.values()) {
- GroupManager.logger.severe(val.name());
- }
- GroupManager.logger.severe("===================================================");
- GroupManager.logger.severe("= ERROR REPORT ENDED =");
- GroupManager.logger.severe("===================================================");
- sender.sendMessage("An error occurred. Ask the admin to take a look at the console.");
- }
-
- if (isConsole || playerCanDo) {
- switch (execCmd) {
- case manuadd:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- auxGroup = dataHolder.getGroup(args[1]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group not found!");
- return false;
- }
-
- //VALIDANDO PERMISSAO
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) {
- sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
- return false;
- }
- if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) {
- sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit.");
- return false;
- }
-
- //PARECE OK
- auxUser.setGroup(auxGroup);
- if (!sender.hasPermission("groupmanager.notify.other"))
- sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'.");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- //break;
- case manudel:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- //PARECE OK
- dataHolder.removeUser(auxUser.getName());
- sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' to default settings.");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- case manuaddsub:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender)) {
- sender.sendMessage(ChatColor.RED + "Couldn't retrieve your world. World selection is needed.");
- sender.sendMessage(ChatColor.RED + "Use /manselect <world>");
- return true;
- }
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- auxGroup = dataHolder.getGroup(args[1]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group not found!");
- return false;
- }
- //VALIDANDO PERMISSAO
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- //PARECE OK
- auxUser.addSubGroup(auxGroup);
- sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'.");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- case manudelsub:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/manudelsub <user> <group>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- auxGroup = dataHolder.getGroup(args[1]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group not found!");
- return false;
- }
-
- //VALIDANDO PERMISSAO
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- //PARECE OK
- auxUser.removeSubGroup(auxGroup);
- sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list.");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- case mangadd:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup != null) {
- sender.sendMessage(ChatColor.RED + "Group already exists!");
- return false;
- }
- //PARECE OK
- auxGroup = dataHolder.createGroup(args[0]);
- sender.sendMessage(ChatColor.YELLOW + "You created a group named: " + auxGroup.getName());
-
- return true;
- case mangdel:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group not exists!");
- return false;
- }
- //PARECE OK
- dataHolder.removeGroup(auxGroup.getName());
- sender.sendMessage(ChatColor.YELLOW + "You deleted a group named " + auxGroup.getName() + ", it's users are default group now.");
-
- BukkitPermissions.updateAllPlayers();
-
- return true;
- case manuaddp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <permission>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO SUA PERMISSAO
- if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
- return false;
- }
- permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
- if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)
- || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
- sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have.");
- return false;
- }
- //VALIDANDO PERMISSAO DO DESTINO
- permissionResult = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
- if (args[1].startsWith("+")) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
- sender.sendMessage(ChatColor.RED + "The user already has direct access to that permission.");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- }
- } else if (args[1].startsWith("-")) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
- sender.sendMessage(ChatColor.RED + "The user already has an exception for this node.");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- } else if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- sender.sendMessage(ChatColor.RED + "The user already has a matching node ");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- }
- } else {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.FOUND)) {
- sender.sendMessage(ChatColor.RED + "The user already has direct access to that permission.");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- }
- }
- //PARECE OK
- auxUser.addPermission(args[1]);
- sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to player '" + auxUser.getName() + "' permissions.");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- //break;
- case manudelp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <permission>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO SUA PERMISSAO
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
- return false;
- }
- permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
- if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)
- || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
- sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have.");
- return false;
- }
- //VALIDANDO PERMISSAO DO DESTINO
- permissionResult = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- sender.sendMessage(ChatColor.RED + "The user doesn't have direct access to that permission.");
- return false;
- }
- if (!auxUser.hasSamePermissionNode(args[1])) {
- sender.sendMessage(ChatColor.RED + "This permission node doesn't match any node.");
- sender.sendMessage(ChatColor.RED + "But might match node: " + permissionResult.accessLevel);
- return false;
- }
- //PARECE OK
- auxUser.removePermission(args[1]);
- sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from player '" + auxUser.getName() + "' permissions.");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- //break;
- case manulistp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if ((args.length == 0) || (args.length > 2)) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> (+))");
- return false;
- }
-
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- } else
- targetPlayer = this.getServer().getPlayer(match.get(0).getName());
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- //PARECE OK
- auxString = "";
- for (String perm : auxUser.getPermissionList()) {
- auxString += perm + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- sender.sendMessage(ChatColor.YELLOW + "The player '" + auxUser.getName() + "' has following permissions: " + ChatColor.WHITE + auxString);
- sender.sendMessage(ChatColor.YELLOW + "And all permissions from group: " + auxUser.getGroupName());
- auxString = "";
- for (String subGroup : auxUser.subGroupListStringCopy()) {
- auxString += subGroup + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- sender.sendMessage(ChatColor.YELLOW + "And all permissions from subgroups: " + auxString);
- }
- } else {
- sender.sendMessage(ChatColor.YELLOW + "The player '" + auxUser.getName() + "' has no specific permissions.");
- sender.sendMessage(ChatColor.YELLOW + "Only all permissions from group: " + auxUser.getGroupName());
- auxString = "";
- for (String subGroup : auxUser.subGroupListStringCopy()) {
- auxString += subGroup + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- sender.sendMessage(ChatColor.YELLOW + "And all permissions from subgroups: " + auxString);
- }
- }
-
- //bukkit perms
- if ((args.length == 2) && (args[1].equalsIgnoreCase("+"))) {
- if (targetPlayer != null) {
- sender.sendMessage(ChatColor.YELLOW + "Superperms reports: ");
- for(String line: BukkitPermissions.listPerms(targetPlayer))
- sender.sendMessage(ChatColor.YELLOW + line);
-
- }
- }
-
-
- return true;
- case manucheckp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <permission>)");
- return false;
- }
-
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- } else
- targetPlayer = this.getServer().getPlayer(match.get(0).getName());
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- permissionResult = permissionHandler.checkFullUserPermission(auxUser, args[1]);
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- sender.sendMessage(ChatColor.RED + "The player doesn't have access to that permission");
- sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1]));
- return false;
- }
- //PARECE OK
- //auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
- if (permissionResult.owner instanceof User) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- sender.sendMessage(ChatColor.RED + "The user has directly a negation node for that permission.");
- } else {
- sender.sendMessage(ChatColor.YELLOW + "The user has directly this permission.");
- }
- sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
- } else if (permissionResult.owner instanceof Group) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- sender.sendMessage(ChatColor.RED + "The user inherits the a negation permission from group: " + permissionResult.owner.getName());
- } else {
- sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName());
- }
- sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
- }
-
- // superperms
- if (targetPlayer != null) {
- sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1]));
- }
-
-
- return true;
- case mangaddp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <permission>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO SUA PERMISSAO
- permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
- if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)
- || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
- sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have.");
- return false;
- }
- //VALIDANDO PERMISSAO DO DESTINO
- permissionResult = permissionHandler.checkGroupOnlyPermission(auxGroup, args[1]);
- if (args[1].startsWith("+")) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
- sender.sendMessage(ChatColor.RED + "The group already has direct access to that permission.");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- }
- } else if (args[1].startsWith("-")) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
- sender.sendMessage(ChatColor.RED + "The group already has an exception for this node.");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- } else if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- sender.sendMessage(ChatColor.RED + "The group already has a matching node.");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- }
- } else {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.FOUND)) {
- sender.sendMessage(ChatColor.RED + "The user already has direct access to that permission.");
- sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
- return false;
- }
- }
- //PARECE OK
- auxGroup.addPermission(args[1]);
- sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to group '" + auxGroup.getName() + "' permissions.");
-
- BukkitPermissions.updateAllPlayers();
-
- return true;
- case mangdelp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <permission>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO SUA PERMISSAO
- permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
- if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)
- || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
- sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have.");
- return false;
- }
- //VALIDANDO PERMISSAO DO DESTINO
- permissionResult = permissionHandler.checkGroupOnlyPermission(auxGroup, args[1]);
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- sender.sendMessage(ChatColor.RED + "The group doesn't have direct access to that permission.");
- return false;
- }
- if (!auxGroup.hasSamePermissionNode(args[1])) {
- sender.sendMessage(ChatColor.RED + "This permission node doesn't match any node.");
- sender.sendMessage(ChatColor.RED + "But might match node: " + permissionResult.accessLevel);
- return false;
- }
- //PARECE OK
- auxGroup.removePermission(args[1]);
- sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from group '" + auxGroup.getName() + "' permissions.");
-
- BukkitPermissions.updateAllPlayers();
-
- return true;
- case manglistp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
-
- //PARECE OK
- auxString = "";
- for (String perm : auxGroup.getPermissionList()) {
- auxString += perm + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- sender.sendMessage(ChatColor.YELLOW + "The group '" + auxGroup.getName() + "' has following permissions: " + ChatColor.WHITE + auxString);
- auxString = "";
- for (String grp : auxGroup.getInherits()) {
- auxString += grp + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- sender.sendMessage(ChatColor.YELLOW + "And all permissions from groups: " + auxString);
- }
-
- } else {
- sender.sendMessage(ChatColor.YELLOW + "The grpup '" + auxGroup.getName() + "' has no specific permissions.");
- auxString = "";
- for (String grp : auxGroup.getInherits()) {
- auxString += grp + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- sender.sendMessage(ChatColor.YELLOW + "Only all permissions from groups: " + auxString);
- }
-
- }
- return true;
- case mangcheckp:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <permission>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
- permissionResult = permissionHandler.checkGroupPermissionWithInheritance(auxGroup, args[1]);
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- sender.sendMessage(ChatColor.RED + "The group doesn't have access to that permission");
- return false;
- }
- //PARECE OK
- //auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
- if (permissionResult.owner instanceof Group) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- sender.sendMessage(ChatColor.RED + "The group inherits the a negation permission from group: " + permissionResult.owner.getName());
- } else {
- sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName());
- }
- sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
-
- }
- return true;
- case mangaddi:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group1> <group2>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group 1 does not exists!");
- return false;
- }
- auxGroup2 = dataHolder.getGroup(args[1]);
- if (auxGroup2 == null) {
- sender.sendMessage(ChatColor.RED + "Group 2 does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
- if (permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) {
- sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " already inherits " + auxGroup2.getName() + " (might not be directly)");
- return false;
- }
- //PARECE OK
- auxGroup.addInherits(auxGroup2);
- sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " is now in " + auxGroup.getName() + " inheritance list.");
-
- BukkitPermissions.updateAllPlayers();
-
- return true;
- case mangdeli:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group1> <group2>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group 1 does not exists!");
- return false;
- }
- auxGroup2 = dataHolder.getGroup(args[1]);
- if (auxGroup2 == null) {
- sender.sendMessage(ChatColor.RED + "Group 2 does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
- if (!permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) {
- sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + ".");
- return false;
- }
- if (!auxGroup.getInherits().contains(auxGroup2.getName())) {
- sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + " directly.");
- return false;
- }
- //PARECE OK
- auxGroup.removeInherits(auxGroup2.getName());
- sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " was removed from " + auxGroup.getName() + " inheritance list.");
-
- BukkitPermissions.updateAllPlayers();
-
- return true;
- case manuaddv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length < 3) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user> <variable> <value>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- //PARECE OK
- auxString = "";
- for (int i = 2; i < args.length; i++) {
- auxString += args[i];
- if ((i + 1) < args.length) {
- auxString += " ";
- }
- }
- auxUser.getVariables().addVar(args[1], Variables.parseVariableValue(auxString));
- sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the user " + auxUser.getName());
- return true;
- case manudelv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user> <variable>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- if (!auxUser.getVariables().hasVar(args[1])) {
- sender.sendMessage(ChatColor.RED + "The user doesn't have directly that variable!");
- }
- //PARECE OK
- auxUser.getVariables().removeVar(args[1]);
- sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the user " + ChatColor.GREEN + auxUser.getName());
- return true;
- case manulistv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- //PARECE OK
- auxString = "";
- for (String varKey : auxUser.getVariables().getVarKeyList()) {
- Object o = auxUser.getVariables().getVarObject(varKey);
- auxString += ChatColor.GOLD + varKey + ChatColor.WHITE + ":'" + ChatColor.GREEN + o.toString() + ChatColor.WHITE + "', ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- }
- sender.sendMessage(ChatColor.YELLOW + "Variables of user " + auxUser.getName() + ": ");
- sender.sendMessage(auxString + ".");
- sender.sendMessage(ChatColor.YELLOW + "Plus all variables from group: " + auxUser.getGroupName());
- return true;
- case manucheckv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user> <variable>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- auxGroup = auxUser.getGroup();
- auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1], null);
-
- if (!auxUser.getVariables().hasVar(args[1])) {
- if (auxGroup2 == null) {
- sender.sendMessage(ChatColor.RED + "The user doesn't have access to that variable!");
- }
- }
- //PARECE OK
- if (auxUser.getVariables().hasVar(auxString)) {
- sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxUser.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'");
- sender.sendMessage(ChatColor.YELLOW + "This user own directly the variable");
- }
- sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxGroup2.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'");
- if (!auxGroup.equals(auxGroup2)) {
- sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName());
- }
- return true;
- case mangaddv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length < 3) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <variable> <value>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
- //PARECE OK
- auxString = "";
- for (int i = 2; i < args.length; i++) {
- auxString += args[i];
- if ((i + 1) < args.length) {
- auxString += " ";
- }
- }
- auxGroup.getVariables().addVar(args[1], Variables.parseVariableValue(auxString));
- sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the group " + auxGroup.getName());
-
- return true;
- case mangdelv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <variable>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
- if (!auxGroup.getVariables().hasVar(args[1])) {
- sender.sendMessage(ChatColor.RED + "The group doesn't have directly that variable!");
- }
- //PARECE OK
- auxGroup.getVariables().removeVar(args[1]);
- sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the group " + ChatColor.GREEN + auxGroup.getName());
-
- return true;
- case manglistv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
- //PARECE OK
- auxString = "";
- for (String varKey : auxGroup.getVariables().getVarKeyList()) {
- Object o = auxGroup.getVariables().getVarObject(varKey);
- auxString += ChatColor.GOLD + varKey + ChatColor.WHITE + ":'" + ChatColor.GREEN + o.toString() + ChatColor.WHITE + "', ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- }
- sender.sendMessage(ChatColor.YELLOW + "Variables of group " + auxGroup.getName() + ": ");
- sender.sendMessage(auxString + ".");
- auxString = "";
- for (String grp : auxGroup.getInherits()) {
- auxString += grp + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- sender.sendMessage(ChatColor.YELLOW + "Plus all variables from groups: " + auxString);
- }
- return true;
- case mangcheckv:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <variable>)");
- return false;
- }
- auxGroup = dataHolder.getGroup(args[0]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group does not exists!");
- return false;
- }
- //VALIDANDO PERMISSAO
- auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1], null);
- if (auxGroup2 == null) {
- sender.sendMessage(ChatColor.RED + "The group doesn't have access to that variable!");
- }
- //PARECE OK
- sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxGroup2.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'");
- if (!auxGroup.equals(auxGroup2)) {
- sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName());
- }
- return true;
- case manwhois:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //PARECE OK
- sender.sendMessage(ChatColor.YELLOW + "Name: " + ChatColor.GREEN + auxUser.getName());
- sender.sendMessage(ChatColor.YELLOW + "Group: " + ChatColor.GREEN + auxUser.getGroup().getName());
- sender.sendMessage(ChatColor.YELLOW + "Overloaded: " + ChatColor.GREEN + dataHolder.isOverloaded(auxUser.getName()));
- auxGroup = dataHolder.surpassOverload(auxUser.getName()).getGroup();
- if (!auxGroup.equals(auxUser.getGroup())) {
- sender.sendMessage(ChatColor.YELLOW + "Original Group: " + ChatColor.GREEN + auxGroup.getName());
- }
- //victim.permissions.add(args[1]);
- return true;
- //break;
- case tempadd:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- //PARECE OK
- if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
- overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
- }
- dataHolder.overloadUser(auxUser.getName());
- overloadedUsers.get(dataHolder.getName().toLowerCase()).add(dataHolder.getUser(auxUser.getName()));
- sender.sendMessage(ChatColor.YELLOW + "Player overloaded!");
-
- return true;
- //break;
- case tempdel:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- //VALIDANDO PERMISSAO
- if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- //PARECE OK
- if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
- overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
- }
- dataHolder.removeOverload(auxUser.getName());
- if (overloadedUsers.get(dataHolder.getName().toLowerCase()).contains(auxUser)) {
- overloadedUsers.get(dataHolder.getName().toLowerCase()).remove(auxUser);
- }
- sender.sendMessage(ChatColor.YELLOW + "You removed that player overload. He's back to normal!");
-
- return true;
- //break;
- case templist:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //WORKING
- auxString = "";
- removeList = new ArrayList<User>();
- count = 0;
- for (User u : overloadedUsers.get(dataHolder.getName().toLowerCase())) {
- if (!dataHolder.isOverloaded(u.getName())) {
- removeList.add(u);
- } else {
- auxString += u.getName() + ", ";
- count++;
- }
- }
- if (count == 0) {
- sender.sendMessage(ChatColor.YELLOW + "There is no users in overload mode");
- return true;
- }
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
- overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
- }
- overloadedUsers.get(dataHolder.getName().toLowerCase()).removeAll(removeList);
- sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode: " + ChatColor.WHITE + auxString);
- return true;
- case tempdelall:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //WORKING
- removeList = new ArrayList<User>();
- count = 0;
- for (User u : overloadedUsers.get(dataHolder.getName().toLowerCase())) {
- if (dataHolder.isOverloaded(u.getName())) {
- dataHolder.removeOverload(u.getName());
- count++;
- }
- }
- if (count == 0) {
- sender.sendMessage(ChatColor.YELLOW + "There is no users in overload mode");
- return true;
- }
- if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
- overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
- }
- overloadedUsers.get(dataHolder.getName().toLowerCase()).clear();
- sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode. Now they are normal again.");
-
- return true;
- case mansave:
- worldsHolder.saveChanges();
- sender.sendMessage(ChatColor.YELLOW + " The changes were saved.");
- return true;
- case manload:
- //THIS CASE DONT NEED SENDER
- if (args.length > 0) {
- auxString = "";
- for (int i = 0; i < args.length; i++) {
- auxString += args[i];
- if ((i + 1) < args.length) {
- auxString += " ";
- }
- }
-
- isLoaded = false; // Disable Bukkit Perms update
-
- worldsHolder.loadWorld(auxString);
- sender.sendMessage("The request to world '" + auxString + "' was sent.");
-
- isLoaded = true;
-
- BukkitPermissions.updateAllPlayers();
-
- return true;
- }
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //WORKING
- config.load();
-
- isLoaded = false;
-
- if (args.length > 0) {
- auxString = "";
- for (int i = 0; i < args.length; i++) {
- auxString += args[i];
- if ((i + 1) < args.length) {
- auxString += " ";
- }
- }
- worldsHolder.loadWorld(auxString);
- sender.sendMessage("The request to world '" + auxString + "' was sent.");
- } else {
- worldsHolder.reloadAll();
- sender.sendMessage(ChatColor.YELLOW + " The current world was reloaded.");
- }
- worldsHolder.mirrorSetUp();
-
- isLoaded = true;
-
- BukkitPermissions.updateAllPlayers();
-
- return true;
- case listgroups:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //WORKING
- auxString = "";
- for (Group g : dataHolder.getGroupList()) {
- auxString += g.getName() + ", ";
- }
- if (auxString.lastIndexOf(",") > 0) {
- auxString = auxString.substring(0, auxString.lastIndexOf(","));
- }
- sender.sendMessage(ChatColor.YELLOW + " Groups Available: " + ChatColor.WHITE + auxString);
- return true;
- case manpromote:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- auxGroup = dataHolder.getGroup(args[1]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group not found!");
- return false;
- }
- //VALIDANDO PERMISSAO
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) {
- sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
- return false;
- }
- if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) {
- sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit.");
- return false;
- }
- if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
- sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line.");
- return false;
- }
- if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
- sender.sendMessage(ChatColor.RED + "The new group must be a higher rank.");
- return false;
- }
- //PARECE OK
- auxUser.setGroup(auxGroup);
- if (!sender.hasPermission("groupmanager.notify.other"))
- sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- //break;
- case mandemote:
- //VALIDANDO ESTADO DO SENDER
- if (dataHolder == null || permissionHandler == null) {
- if (!setDefaultWorldHandler(sender))
- return true;
- }
- //VALIDANDO ARGUMENTOS
- if (args.length != 2) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
- return false;
- }
- if (validateOnlinePlayer) {
- match = this.getServer().matchPlayer(args[0]);
- if (match.size() != 1) {
- sender.sendMessage(ChatColor.RED + "Player not found!");
- return false;
- }
- }
- if (match != null) {
- auxUser = dataHolder.getUser(match.get(0).getName());
- } else {
- auxUser = dataHolder.getUser(args[0]);
- }
- auxGroup = dataHolder.getGroup(args[1]);
- if (auxGroup == null) {
- sender.sendMessage(ChatColor.RED + "Group not found!");
- return false;
- }
- //VALIDANDO PERMISSAO
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
- sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
- return false;
- }
- if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) {
- sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
- return false;
- }
- if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) {
- sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don' inherit.");
- return false;
- }
- if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
- sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line.");
- return false;
- }
- if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
- sender.sendMessage(ChatColor.RED + "The new group must be a lower rank.");
- return false;
- }
- //PARECE OK
- auxUser.setGroup(auxGroup);
- if (!sender.hasPermission("groupmanager.notify.other"))
- sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
-
- targetPlayer = this.getServer().getPlayer(auxUser.getName());
- if (targetPlayer != null) BukkitPermissions.updatePermissions(targetPlayer);
-
- return true;
- //break;
- case mantogglevalidate:
- validateOnlinePlayer = !validateOnlinePlayer;
- sender.sendMessage(ChatColor.YELLOW + "Validade if player is online, now set to: " + Boolean.toString(validateOnlinePlayer));
- if (!validateOnlinePlayer) {
- sender.sendMessage(ChatColor.GOLD + "From now on you can edit players not connected... BUT:");
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "From now on you should type the whole name of the player, correctly.");
- }
- return true;
- case mantogglesave:
- if (scheduler == null) {
- enableScheduler();
- sender.sendMessage(ChatColor.YELLOW + "The auto-saving is enabled!");
- } else {
- disableScheduler();
- sender.sendMessage(ChatColor.YELLOW + "The auto-saving is disabled!");
- }
- return true;
- case manworld:
- auxString = selectedWorlds.get(sender);
- if (auxString != null) {
- sender.sendMessage(ChatColor.YELLOW + "You have the world '" + dataHolder.getName() + "' in your selection.");
- } else {
- if (dataHolder == null) {
- sender.sendMessage(ChatColor.YELLOW + "There is no world selected. And no world is available now.");
- } else {
- sender.sendMessage(ChatColor.YELLOW + "You don't have a world in your selection..");
- sender.sendMessage(ChatColor.YELLOW + "Working with the direct world where your player is.");
- sender.sendMessage(ChatColor.YELLOW + "Your world now uses permissions of world name: '" + dataHolder.getName() + "' ");
- }
- }
- return true;
- case manselect:
- if (args.length < 1) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <world>)");
- sender.sendMessage(ChatColor.YELLOW + "Worlds available: ");
- ArrayList<OverloadedWorldHolder> worlds = worldsHolder.allWorldsDataList();
- auxString = "";
- for (int i = 0; i < worlds.size(); i++) {
- auxString += worlds.get(i).getName();
- if ((i + 1) < worlds.size()) {
- auxString += ", ";
- }
- }
- sender.sendMessage(ChatColor.YELLOW + auxString);
- return false;
- }
- auxString = "";
- for (int i = 0; i < args.length; i++) {
- if (args[i] == null) {
- logger.warning("Bukkit gave invalid arguments array! Cmd: " + cmd.getName() + " args.length: " + args.length);
- return false;
- }
- auxString += args[i];
- if (i < (args.length - 1)) {
- auxString += " ";
- }
- }
- dataHolder = worldsHolder.getWorldData(auxString);
- permissionHandler = dataHolder.getPermissionsHandler();
- selectedWorlds.put(sender, dataHolder.getName());
- sender.sendMessage(ChatColor.YELLOW + "You have selected world '" + dataHolder.getName() + "'.");
- return true;
- case manclear:
- if (args.length != 0) {
- sender.sendMessage(ChatColor.RED + "Review your arguments count!");
- return false;
- }
- selectedWorlds.remove(sender);
- sender.sendMessage(ChatColor.YELLOW + "You have removed your world selection. Working with current world(if possible).");
- return true;
- default:
- break;
- }
- }
- sender.sendMessage(ChatColor.RED + "You are not allowed to use that command.");
- return false;
- }
-
- /**
- * Sets up the default world for use.
- */
- private boolean setDefaultWorldHandler(CommandSender sender) {
-
- dataHolder = worldsHolder.getWorldData(worldsHolder.getDefaultWorld().getName());
- permissionHandler = dataHolder.getPermissionsHandler();
- selectedWorlds.put(sender, dataHolder.getName());
-
- if ((dataHolder != null) && (permissionHandler != null)) {
- sender.sendMessage(ChatColor.RED + "Couldn't retrieve your world. Default world '" + worldsHolder.getDefaultWorld().getName() + "' selected.");
- return true;
- }
-
- sender.sendMessage(ChatColor.RED + "Couldn't retrieve your world. World selection is needed.");
+ return this.getClassLoader().getResourceAsStream(fileName);
+ }
+
+ private void prepareFileFields() {
+ // configFile = new File(this.getDataFolder(), "config.yml");
+ backupFolder = new File(this.getDataFolder(), "backup");
+ if (!backupFolder.exists()) {
+ getBackupFolder().mkdirs();
+ }
+ }
+
+ private void prepareConfig() {
+ config = new GMConfiguration(this);
+ }
+
+ public void enableScheduler() {
+ if (worldsHolder != null) {
+ disableScheduler();
+ commiter = new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ worldsHolder.saveChanges(false);
+ GroupManager.logger.log(Level.INFO, " Data files refreshed.");
+ } catch (IllegalStateException ex) {
+ GroupManager.logger.log(Level.WARNING, ex.getMessage());
+ }
+ }
+ };
+ scheduler = new ScheduledThreadPoolExecutor(1);
+ long minutes = (long)getGMConfig().getSaveInterval();
+ if (minutes > 0) {
+ scheduler.scheduleAtFixedRate(commiter, minutes, minutes, TimeUnit.MINUTES);
+ GroupManager.logger.info("Scheduled Data Saving is set for every " + minutes + " minutes!");
+ } else
+ GroupManager.logger.info("Scheduled Data Saving is Disabled!");
+
+ GroupManager.logger.info("Backups will be retained for " + getGMConfig().getBackupDuration() + " hours!");
+ }
+ }
+
+ public void disableScheduler() {
+ if (scheduler != null) {
+ try {
+ scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
+ scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
+ scheduler.shutdown();
+ } catch (Exception e) {
+ }
+ scheduler = null;
+ GroupManager.logger.info("Scheduled Data Saving is disabled!");
+ }
+ }
+
+ /**
+ * Use the WorldsHolder saveChanges directly instead Saves the data on file
+ */
+ @Deprecated
+ public void commit() {
+ if (worldsHolder != null) {
+ worldsHolder.saveChanges();
+ }
+ }
+
+ /**
+ * Use worlds holder to reload a specific world Reloads the data
+ */
+ @Deprecated
+ public void reload() {
+ worldsHolder.reloadAll();
+ }
+
+ public WorldsHolder getWorldsHolder() {
+ return worldsHolder;
+ }
+
+ /**
+ * The handler in the interface created by AnjoCaido
+ *
+ * @return AnjoPermissionsHandler
+ */
+ @Deprecated
+ public AnjoPermissionsHandler getPermissionHandler() {
+ return worldsHolder.getDefaultWorld().getPermissionsHandler();
+ }
+
+ /**
+ * A simple interface, for ones that don't want to mess with overloading.
+ * Yet it is affected by overloading. But seamless.
+ *
+ * @return the dataholder with all information
+ */
+ @Deprecated
+ public WorldDataHolder getData() {
+ return worldsHolder.getDefaultWorld();
+ }
+
+ /**
+ * Use this if you want to play with overloading.
+ *
+ * @return a dataholder with overloading interface
+ */
+ @Deprecated
+ public OverloadedWorldHolder getOverloadedClassData() {
+ return worldsHolder.getDefaultWorld();
+ }
+
+ /**
+ * Called when a command registered by this plugin is received.
+ *
+ * @param sender
+ * @param cmd
+ * @param args
+ */
+ @SuppressWarnings({ "deprecation" })
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
+ boolean playerCanDo = false;
+ boolean isConsole = false;
+ Player senderPlayer = null, targetPlayer = null;
+ Group senderGroup = null;
+ User senderUser = null;
+ boolean isOpOverride = config.isOpOverride();
+
+ // DETERMINING PLAYER INFORMATION
+ if (sender instanceof Player) {
+ senderPlayer = (Player) sender;
+ senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName());
+ senderGroup = senderUser.getGroup();
+ isOpOverride = (isOpOverride && senderPlayer.isOp());
+
+ System.out.println("[PLAYER_COMMAND] " + senderPlayer.getName() + ": /" + commandLabel + " " + Tasks.join(args, " "));
+ if (isOpOverride || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager." + cmd.getName())) {
+ playerCanDo = true;
+ }
+ } else if (sender instanceof ConsoleCommandSender) {
+ isConsole = true;
+ }
+
+ // PERMISSIONS FOR COMMAND BEING LOADED
+ dataHolder = null;
+ permissionHandler = null;
+
+ if (senderPlayer != null) {
+ dataHolder = worldsHolder.getWorldData(senderPlayer);
+ }
+
+ String selectedWorld = selectedWorlds.get(sender);
+ if (selectedWorld != null) {
+ dataHolder = worldsHolder.getWorldData(selectedWorld);
+ }
+
+ if (dataHolder != null) {
+ permissionHandler = dataHolder.getPermissionsHandler();
+ }
+
+ // VARIABLES USED IN COMMANDS
+
+ int count;
+ PermissionCheckResult permissionResult = null;
+ ArrayList<User> removeList = null;
+ String auxString = null;
+ List<Player> match = null;
+ User auxUser = null;
+ Group auxGroup = null;
+ Group auxGroup2 = null;
+
+ GroupManagerPermissions execCmd = null;
+ try {
+ execCmd = GroupManagerPermissions.valueOf(cmd.getName());
+ } catch (Exception e) {
+ // this error happened once with someone. now im prepared... i think
+ GroupManager.logger.severe("===================================================");
+ GroupManager.logger.severe("= ERROR REPORT START =");
+ GroupManager.logger.severe("===================================================");
+ GroupManager.logger.severe("= COPY AND PASTE THIS TO GROUPMANAGER DEVELOPER =");
+ GroupManager.logger.severe("===================================================");
+ GroupManager.logger.severe(this.getDescription().getName());
+ GroupManager.logger.severe(this.getDescription().getVersion());
+ GroupManager.logger.severe("An error occured while trying to execute command:");
+ GroupManager.logger.severe(cmd.getName());
+ GroupManager.logger.severe("With " + args.length + " arguments:");
+ for (String ar : args) {
+ GroupManager.logger.severe(ar);
+ }
+ GroupManager.logger.severe("The field '" + cmd.getName() + "' was not found in enum.");
+ GroupManager.logger.severe("And could not be parsed.");
+ GroupManager.logger.severe("FIELDS FOUND IN ENUM:");
+ for (GroupManagerPermissions val : GroupManagerPermissions.values()) {
+ GroupManager.logger.severe(val.name());
+ }
+ GroupManager.logger.severe("===================================================");
+ GroupManager.logger.severe("= ERROR REPORT ENDED =");
+ GroupManager.logger.severe("===================================================");
+ sender.sendMessage("An error occurred. Ask the admin to take a look at the console.");
+ }
+
+ if (isConsole || playerCanDo) {
+ switch (execCmd) {
+ case manuadd:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ auxGroup = dataHolder.getGroup(args[1]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group not found!");
+ return false;
+ }
+
+ // VALIDANDO PERMISSAO
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) {
+ sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit.");
+ return false;
+ }
+
+ // PARECE OK
+ auxUser.setGroup(auxGroup);
+ if (!sender.hasPermission("groupmanager.notify.other"))
+ sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'.");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ // break;
+ case manudel:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ // PARECE OK
+ dataHolder.removeUser(auxUser.getName());
+ sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' to default settings.");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ case manuaddsub:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender)) {
+ sender.sendMessage(ChatColor.RED + "Couldn't retrieve your world. World selection is needed.");
+ sender.sendMessage(ChatColor.RED + "Use /manselect <world>");
+ return true;
+ }
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ auxGroup = dataHolder.getGroup(args[1]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group not found!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ // PARECE OK
+ auxUser.addSubGroup(auxGroup);
+ sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'.");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ case manudelsub:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/manudelsub <user> <group>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ auxGroup = dataHolder.getGroup(args[1]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group not found!");
+ return false;
+ }
+
+ // VALIDANDO PERMISSAO
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ // PARECE OK
+ auxUser.removeSubGroup(auxGroup);
+ sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list.");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ case mangadd:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup != null) {
+ sender.sendMessage(ChatColor.RED + "Group already exists!");
+ return false;
+ }
+ // PARECE OK
+ auxGroup = dataHolder.createGroup(args[0]);
+ sender.sendMessage(ChatColor.YELLOW + "You created a group named: " + auxGroup.getName());
+
+ return true;
+ case mangdel:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group not exists!");
+ return false;
+ }
+ // PARECE OK
+ dataHolder.removeGroup(auxGroup.getName());
+ sender.sendMessage(ChatColor.YELLOW + "You deleted a group named " + auxGroup.getName() + ", it's users are default group now.");
+
+ BukkitPermissions.updateAllPlayers();
+
+ return true;
+ case manuaddp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <permission>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO SUA PERMISSAO
+ if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
+ return false;
+ }
+ permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
+ if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
+ sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have.");
+ return false;
+ }
+ // VALIDANDO PERMISSAO DO DESTINO
+ permissionResult = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
+ if (args[1].startsWith("+")) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
+ sender.sendMessage(ChatColor.RED + "The user already has direct access to that permission.");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ }
+ } else if (args[1].startsWith("-")) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
+ sender.sendMessage(ChatColor.RED + "The user already has an exception for this node.");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ } else if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ sender.sendMessage(ChatColor.RED + "The user already has a matching node ");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ }
+ } else {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.FOUND)) {
+ sender.sendMessage(ChatColor.RED + "The user already has direct access to that permission.");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ }
+ }
+ // PARECE OK
+ auxUser.addPermission(args[1]);
+ sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to player '" + auxUser.getName() + "' permissions.");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ // break;
+ case manudelp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <permission>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO SUA PERMISSAO
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
+ return false;
+ }
+ permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
+ if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
+ sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have.");
+ return false;
+ }
+ // VALIDANDO PERMISSAO DO DESTINO
+ permissionResult = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ sender.sendMessage(ChatColor.RED + "The user doesn't have direct access to that permission.");
+ return false;
+ }
+ if (!auxUser.hasSamePermissionNode(args[1])) {
+ sender.sendMessage(ChatColor.RED + "This permission node doesn't match any node.");
+ sender.sendMessage(ChatColor.RED + "But might match node: " + permissionResult.accessLevel);
+ return false;
+ }
+ // PARECE OK
+ auxUser.removePermission(args[1]);
+ sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from player '" + auxUser.getName() + "' permissions.");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ // break;
+ case manulistp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if ((args.length == 0) || (args.length > 2)) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> (+))");
+ return false;
+ }
+
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ } else
+ targetPlayer = this.getServer().getPlayer(match.get(0).getName());
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ // PARECE OK
+ auxString = "";
+ for (String perm : auxUser.getPermissionList()) {
+ auxString += perm + ", ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ sender.sendMessage(ChatColor.YELLOW + "The player '" + auxUser.getName() + "' has following permissions: " + ChatColor.WHITE + auxString);
+ sender.sendMessage(ChatColor.YELLOW + "And all permissions from group: " + auxUser.getGroupName());
+ auxString = "";
+ for (String subGroup : auxUser.subGroupListStringCopy()) {
+ auxString += subGroup + ", ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ sender.sendMessage(ChatColor.YELLOW + "And all permissions from subgroups: " + auxString);
+ }
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "The player '" + auxUser.getName() + "' has no specific permissions.");
+ sender.sendMessage(ChatColor.YELLOW + "Only all permissions from group: " + auxUser.getGroupName());
+ auxString = "";
+ for (String subGroup : auxUser.subGroupListStringCopy()) {
+ auxString += subGroup + ", ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ sender.sendMessage(ChatColor.YELLOW + "And all permissions from subgroups: " + auxString);
+ }
+ }
+
+ // bukkit perms
+ if ((args.length == 2) && (args[1].equalsIgnoreCase("+"))) {
+ if (targetPlayer != null) {
+ sender.sendMessage(ChatColor.YELLOW + "Superperms reports: ");
+ for (String line : BukkitPermissions.listPerms(targetPlayer))
+ sender.sendMessage(ChatColor.YELLOW + line);
+
+ }
+ }
+
+ return true;
+ case manucheckp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <permission>)");
+ return false;
+ }
+
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ } else
+ targetPlayer = this.getServer().getPlayer(match.get(0).getName());
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ permissionResult = permissionHandler.checkFullUserPermission(auxUser, args[1]);
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ sender.sendMessage(ChatColor.RED + "The player doesn't have access to that permission");
+ sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1]));
+ return false;
+ }
+ // PARECE OK
+ // auxString =
+ // permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
+ if (permissionResult.owner instanceof User) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ sender.sendMessage(ChatColor.RED + "The user has directly a negation node for that permission.");
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "The user has directly this permission.");
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
+ } else if (permissionResult.owner instanceof Group) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ sender.sendMessage(ChatColor.RED + "The user inherits the a negation permission from group: " + permissionResult.owner.getName());
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName());
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
+ }
+
+ // superperms
+ if (targetPlayer != null) {
+ sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1]));
+ }
+
+ return true;
+ case mangaddp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <permission>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO SUA PERMISSAO
+ permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
+ if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
+ sender.sendMessage(ChatColor.RED + "Can't add a permission you don't have.");
+ return false;
+ }
+ // VALIDANDO PERMISSAO DO DESTINO
+ permissionResult = permissionHandler.checkGroupOnlyPermission(auxGroup, args[1]);
+ if (args[1].startsWith("+")) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
+ sender.sendMessage(ChatColor.RED + "The group already has direct access to that permission.");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ }
+ } else if (args[1].startsWith("-")) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.EXCEPTION)) {
+ sender.sendMessage(ChatColor.RED + "The group already has an exception for this node.");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ } else if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ sender.sendMessage(ChatColor.RED + "The group already has a matching node.");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ }
+ } else {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.FOUND)) {
+ sender.sendMessage(ChatColor.RED + "The user already has direct access to that permission.");
+ sender.sendMessage(ChatColor.RED + "Node: " + permissionResult.accessLevel);
+ return false;
+ }
+ }
+ // PARECE OK
+ auxGroup.addPermission(args[1]);
+ sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to group '" + auxGroup.getName() + "' permissions.");
+
+ BukkitPermissions.updateAllPlayers();
+
+ return true;
+ case mangdelp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <permission>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO SUA PERMISSAO
+ permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
+ if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
+ sender.sendMessage(ChatColor.RED + "Can't remove a permission you don't have.");
+ return false;
+ }
+ // VALIDANDO PERMISSAO DO DESTINO
+ permissionResult = permissionHandler.checkGroupOnlyPermission(auxGroup, args[1]);
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ sender.sendMessage(ChatColor.RED + "The group doesn't have direct access to that permission.");
+ return false;
+ }
+ if (!auxGroup.hasSamePermissionNode(args[1])) {
+ sender.sendMessage(ChatColor.RED + "This permission node doesn't match any node.");
+ sender.sendMessage(ChatColor.RED + "But might match node: " + permissionResult.accessLevel);
+ return false;
+ }
+ // PARECE OK
+ auxGroup.removePermission(args[1]);
+ sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from group '" + auxGroup.getName() + "' permissions.");
+
+ BukkitPermissions.updateAllPlayers();
+
+ return true;
+ case manglistp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+
+ // PARECE OK
+ auxString = "";
+ for (String perm : auxGroup.getPermissionList()) {
+ auxString += perm + ", ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ sender.sendMessage(ChatColor.YELLOW + "The group '" + auxGroup.getName() + "' has following permissions: " + ChatColor.WHITE + auxString);
+ auxString = "";
+ for (String grp : auxGroup.getInherits()) {
+ auxString += grp + ", ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ sender.sendMessage(ChatColor.YELLOW + "And all permissions from groups: " + auxString);
+ }
+
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "The grpup '" + auxGroup.getName() + "' has no specific permissions.");
+ auxString = "";
+ for (String grp : auxGroup.getInherits()) {
+ auxString += grp + ", ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ sender.sendMessage(ChatColor.YELLOW + "Only all permissions from groups: " + auxString);
+ }
+
+ }
+ return true;
+ case mangcheckp:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <permission>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ permissionResult = permissionHandler.checkGroupPermissionWithInheritance(auxGroup, args[1]);
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ sender.sendMessage(ChatColor.RED + "The group doesn't have access to that permission");
+ return false;
+ }
+ // PARECE OK
+ // auxString =
+ // permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
+ if (permissionResult.owner instanceof Group) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ sender.sendMessage(ChatColor.RED + "The group inherits the a negation permission from group: " + permissionResult.owner.getName());
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName());
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
+
+ }
+ return true;
+ case mangaddi:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group1> <group2>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group 1 does not exists!");
+ return false;
+ }
+ auxGroup2 = dataHolder.getGroup(args[1]);
+ if (auxGroup2 == null) {
+ sender.sendMessage(ChatColor.RED + "Group 2 does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ if (permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) {
+ sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " already inherits " + auxGroup2.getName() + " (might not be directly)");
+ return false;
+ }
+ // PARECE OK
+ auxGroup.addInherits(auxGroup2);
+ sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " is now in " + auxGroup.getName() + " inheritance list.");
+
+ BukkitPermissions.updateAllPlayers();
+
+ return true;
+ case mangdeli:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group1> <group2>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group 1 does not exists!");
+ return false;
+ }
+ auxGroup2 = dataHolder.getGroup(args[1]);
+ if (auxGroup2 == null) {
+ sender.sendMessage(ChatColor.RED + "Group 2 does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ if (!permissionHandler.searchGroupInInheritance(auxGroup, auxGroup2.getName(), null)) {
+ sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + ".");
+ return false;
+ }
+ if (!auxGroup.getInherits().contains(auxGroup2.getName())) {
+ sender.sendMessage(ChatColor.RED + "Group " + auxGroup.getName() + " does not inherits " + auxGroup2.getName() + " directly.");
+ return false;
+ }
+ // PARECE OK
+ auxGroup.removeInherits(auxGroup2.getName());
+ sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " was removed from " + auxGroup.getName() + " inheritance list.");
+
+ BukkitPermissions.updateAllPlayers();
+
+ return true;
+ case manuaddv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length < 3) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user> <variable> <value>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ // PARECE OK
+ auxString = "";
+ for (int i = 2; i < args.length; i++) {
+ auxString += args[i];
+ if ((i + 1) < args.length) {
+ auxString += " ";
+ }
+ }
+ auxUser.getVariables().addVar(args[1], Variables.parseVariableValue(auxString));
+ sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the user " + auxUser.getName());
+ return true;
+ case manudelv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user> <variable>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ if (!auxUser.getVariables().hasVar(args[1])) {
+ sender.sendMessage(ChatColor.RED + "The user doesn't have directly that variable!");
+ }
+ // PARECE OK
+ auxUser.getVariables().removeVar(args[1]);
+ sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the user " + ChatColor.GREEN + auxUser.getName());
+ return true;
+ case manulistv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ // PARECE OK
+ auxString = "";
+ for (String varKey : auxUser.getVariables().getVarKeyList()) {
+ Object o = auxUser.getVariables().getVarObject(varKey);
+ auxString += ChatColor.GOLD + varKey + ChatColor.WHITE + ":'" + ChatColor.GREEN + o.toString() + ChatColor.WHITE + "', ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Variables of user " + auxUser.getName() + ": ");
+ sender.sendMessage(auxString + ".");
+ sender.sendMessage(ChatColor.YELLOW + "Plus all variables from group: " + auxUser.getGroupName());
+ return true;
+ case manucheckv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <user> <variable>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ auxGroup = auxUser.getGroup();
+ auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1]);
+
+ if (!auxUser.getVariables().hasVar(args[1])) {
+ // Check sub groups
+ if (!auxUser.isSubGroupsEmpty() && auxGroup2 == null)
+ for (Group subGroup : auxUser.subGroupListCopy()) {
+ auxGroup2 = permissionHandler.nextGroupWithVariable(subGroup, args[1]);
+ if (auxGroup2 != null) continue;
+ }
+ if (auxGroup2 == null) {
+ sender.sendMessage(ChatColor.RED + "The user doesn't have access to that variable!");
+ return false;
+ }
+ }
+ // PARECE OK
+ if (auxUser.getVariables().hasVar(auxString)) {
+ sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxUser.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'");
+ sender.sendMessage(ChatColor.YELLOW + "This user own directly the variable");
+ }
+ sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxGroup2.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'");
+ if (!auxGroup.equals(auxGroup2)) {
+ sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName());
+ }
+ return true;
+ case mangaddv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length < 3) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <variable> <value>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ // PARECE OK
+ auxString = "";
+ for (int i = 2; i < args.length; i++) {
+ auxString += args[i];
+ if ((i + 1) < args.length) {
+ auxString += " ";
+ }
+ }
+ auxGroup.getVariables().addVar(args[1], Variables.parseVariableValue(auxString));
+ sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + ":'" + ChatColor.GREEN + auxString + ChatColor.YELLOW + "' added to the group " + auxGroup.getName());
+
+ return true;
+ case mangdelv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <variable>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ if (!auxGroup.getVariables().hasVar(args[1])) {
+ sender.sendMessage(ChatColor.RED + "The group doesn't have directly that variable!");
+ }
+ // PARECE OK
+ auxGroup.getVariables().removeVar(args[1]);
+ sender.sendMessage(ChatColor.YELLOW + "Variable " + ChatColor.GOLD + args[1] + ChatColor.YELLOW + " removed from the group " + ChatColor.GREEN + auxGroup.getName());
+
+ return true;
+ case manglistv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ // PARECE OK
+ auxString = "";
+ for (String varKey : auxGroup.getVariables().getVarKeyList()) {
+ Object o = auxGroup.getVariables().getVarObject(varKey);
+ auxString += ChatColor.GOLD + varKey + ChatColor.WHITE + ":'" + ChatColor.GREEN + o.toString() + ChatColor.WHITE + "', ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Variables of group " + auxGroup.getName() + ": ");
+ sender.sendMessage(auxString + ".");
+ auxString = "";
+ for (String grp : auxGroup.getInherits()) {
+ auxString += grp + ", ";
+ }
+ if (auxString.lastIndexOf(",") > 0) {
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ sender.sendMessage(ChatColor.YELLOW + "Plus all variables from groups: " + auxString);
+ }
+ return true;
+ case mangcheckv:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <group> <variable>)");
+ return false;
+ }
+ auxGroup = dataHolder.getGroup(args[0]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group does not exists!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ auxGroup2 = permissionHandler.nextGroupWithVariable(auxGroup, args[1], null);
+ if (auxGroup2 == null) {
+ sender.sendMessage(ChatColor.RED + "The group doesn't have access to that variable!");
+ }
+ // PARECE OK
+ sender.sendMessage(ChatColor.YELLOW + "The value of variable '" + ChatColor.GOLD + args[1] + ChatColor.YELLOW + "' is: '" + ChatColor.GREEN + auxGroup2.getVariables().getVarObject(args[1]).toString() + ChatColor.WHITE + "'");
+ if (!auxGroup.equals(auxGroup2)) {
+ sender.sendMessage(ChatColor.YELLOW + "And the value was inherited from group: " + ChatColor.GREEN + auxGroup2.getName());
+ }
+ return true;
+ case manwhois:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // PARECE OK
+ sender.sendMessage(ChatColor.YELLOW + "Name: " + ChatColor.GREEN + auxUser.getName());
+ sender.sendMessage(ChatColor.YELLOW + "Group: " + ChatColor.GREEN + auxUser.getGroup().getName());
+ sender.sendMessage(ChatColor.YELLOW + "Overloaded: " + ChatColor.GREEN + dataHolder.isOverloaded(auxUser.getName()));
+ auxGroup = dataHolder.surpassOverload(auxUser.getName()).getGroup();
+ if (!auxGroup.equals(auxUser.getGroup())) {
+ sender.sendMessage(ChatColor.YELLOW + "Original Group: " + ChatColor.GREEN + auxGroup.getName());
+ }
+ // victim.permissions.add(args[1]);
+ return true;
+ // break;
+ case tempadd:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ // PARECE OK
+ if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
+ overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
+ }
+ dataHolder.overloadUser(auxUser.getName());
+ overloadedUsers.get(dataHolder.getName().toLowerCase()).add(dataHolder.getUser(auxUser.getName()));
+ sender.sendMessage(ChatColor.YELLOW + "Player overloaded!");
+
+ return true;
+ // break;
+ case tempdel:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ // VALIDANDO PERMISSAO
+ if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ // PARECE OK
+ if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
+ overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
+ }
+ dataHolder.removeOverload(auxUser.getName());
+ if (overloadedUsers.get(dataHolder.getName().toLowerCase()).contains(auxUser)) {
+ overloadedUsers.get(dataHolder.getName().toLowerCase()).remove(auxUser);
+ }
+ sender.sendMessage(ChatColor.YELLOW + "You removed that player overload. He's back to normal!");
+
+ return true;
+ // break;
+ case templist:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // WORKING
+ auxString = "";
+ removeList = new ArrayList<User>();
+ count = 0;
+ for (User u : overloadedUsers.get(dataHolder.getName().toLowerCase())) {
+ if (!dataHolder.isOverloaded(u.getName())) {
+ removeList.add(u);
+ } else {
+ auxString += u.getName() + ", ";
+ count++;
+ }
+ }
+ if (count == 0) {
+ sender.sendMessage(ChatColor.YELLOW + "There is no users in overload mode");
+ return true;
+ }
+ auxString = auxString.substring(0, auxString.lastIndexOf(","));
+ if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
+ overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
+ }
+ overloadedUsers.get(dataHolder.getName().toLowerCase()).removeAll(removeList);
+ sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode: " + ChatColor.WHITE + auxString);
+ return true;
+ case tempdelall:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // WORKING
+ removeList = new ArrayList<User>();
+ count = 0;
+ for (User u : overloadedUsers.get(dataHolder.getName().toLowerCase())) {
+ if (dataHolder.isOverloaded(u.getName())) {
+ dataHolder.removeOverload(u.getName());
+ count++;
+ }
+ }
+ if (count == 0) {
+ sender.sendMessage(ChatColor.YELLOW + "There is no users in overload mode");
+ return true;
+ }
+ if (overloadedUsers.get(dataHolder.getName().toLowerCase()) == null) {
+ overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
+ }
+ overloadedUsers.get(dataHolder.getName().toLowerCase()).clear();
+ sender.sendMessage(ChatColor.YELLOW + " " + count + " Users in overload mode. Now they are normal again.");
+
+ return true;
+ case mansave:
+
+ boolean forced = false;
+
+ if ((args.length == 1) && (args[0].equalsIgnoreCase("force")))
+ forced = true;
+
+ try {
+ worldsHolder.saveChanges(forced);
+ sender.sendMessage(ChatColor.YELLOW + " The changes were saved.");
+ } catch (IllegalStateException ex) {
+ sender.sendMessage(ChatColor.RED + ex.getMessage());
+ }
+ return true;
+
+ case manload:
+ // THIS CASE DONT NEED SENDER
+ if (args.length > 0) {
+ auxString = "";
+ for (int i = 0; i < args.length; i++) {
+ auxString += args[i];
+ if ((i + 1) < args.length) {
+ auxString += " ";
+ }
+ }
+
+ isLoaded = false; // Disable Bukkit Perms update
+
+ worldsHolder.loadWorld(auxString);
+ sender.sendMessage("The request to world '" + auxString + "' was sent.");
+
+ isLoaded = true;
+
+ BukkitPermissions.updateAllPlayers();
+
+ return true;
+ }
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // WORKING
+ config.load();
+
+ isLoaded = false;
+
+ if (args.length > 0) {
+ auxString = "";
+ for (int i = 0; i < args.length; i++) {
+ auxString += args[i];
+ if ((i + 1) < args.length) {
+ auxString += " ";
+ }
+ }
+ worldsHolder.loadWorld(auxString);
+ sender.sendMessage("The request to world '" + auxString + "' was sent.");
+ } else {
+ worldsHolder.reloadAll();
+ sender.sendMessage(ChatColor.YELLOW + " The current world was reloaded.");
+ }
+ worldsHolder.mirrorSetUp();
+
+ isLoaded = true;
+
+ BukkitPermissions.updateAllPlayers();
+
+ return true;
+ case listgroups:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // WORKING
+ auxString = "";
+ 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(","));
+ }
+ sender.sendMessage(ChatColor.YELLOW + " Groups Available: " + ChatColor.WHITE + auxString);
+ return true;
+ case manpromote:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ auxGroup = dataHolder.getGroup(args[1]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group not found!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) {
+ sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
+ sender.sendMessage(ChatColor.RED + "The new group must be a higher rank.");
+ return false;
+ }
+ // PARECE OK
+ auxUser.setGroup(auxGroup);
+ if (!sender.hasPermission("groupmanager.notify.other"))
+ sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ // break;
+ case mandemote:
+ // VALIDANDO ESTADO DO SENDER
+ if (dataHolder == null || permissionHandler == null) {
+ if (!setDefaultWorldHandler(sender))
+ return true;
+ }
+ // VALIDANDO ARGUMENTOS
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <player> <group>)");
+ return false;
+ }
+ if (validateOnlinePlayer) {
+ match = this.getServer().matchPlayer(args[0]);
+ if (match.size() != 1) {
+ sender.sendMessage(ChatColor.RED + "Player not found!");
+ return false;
+ }
+ }
+ if (match != null) {
+ auxUser = dataHolder.getUser(match.get(0).getName());
+ } else {
+ auxUser = dataHolder.getUser(args[0]);
+ }
+ auxGroup = dataHolder.getGroup(args[1]);
+ if (auxGroup == null) {
+ sender.sendMessage(ChatColor.RED + "Group not found!");
+ return false;
+ }
+ // VALIDANDO PERMISSAO
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, senderGroup.getName()))) {
+ sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getName(), auxGroup.getName()))) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don' inherit.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
+ sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line.");
+ return false;
+ }
+ if (!isConsole && !isOpOverride && (permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) {
+ sender.sendMessage(ChatColor.RED + "The new group must be a lower rank.");
+ return false;
+ }
+ // PARECE OK
+ auxUser.setGroup(auxGroup);
+ if (!sender.hasPermission("groupmanager.notify.other"))
+ sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
+
+ targetPlayer = this.getServer().getPlayer(auxUser.getName());
+ if (targetPlayer != null)
+ BukkitPermissions.updatePermissions(targetPlayer);
+
+ return true;
+ // break;
+ case mantogglevalidate:
+ validateOnlinePlayer = !validateOnlinePlayer;
+ sender.sendMessage(ChatColor.YELLOW + "Validade if player is online, now set to: " + Boolean.toString(validateOnlinePlayer));
+ if (!validateOnlinePlayer) {
+ sender.sendMessage(ChatColor.GOLD + "From now on you can edit players not connected... BUT:");
+ sender.sendMessage(ChatColor.LIGHT_PURPLE + "From now on you should type the whole name of the player, correctly.");
+ }
+ return true;
+ case mantogglesave:
+ if (scheduler == null) {
+ enableScheduler();
+ sender.sendMessage(ChatColor.YELLOW + "The auto-saving is enabled!");
+ } else {
+ disableScheduler();
+ sender.sendMessage(ChatColor.YELLOW + "The auto-saving is disabled!");
+ }
+ return true;
+ case manworld:
+ auxString = selectedWorlds.get(sender);
+ if (auxString != null) {
+ sender.sendMessage(ChatColor.YELLOW + "You have the world '" + dataHolder.getName() + "' in your selection.");
+ } else {
+ if (dataHolder == null) {
+ sender.sendMessage(ChatColor.YELLOW + "There is no world selected. And no world is available now.");
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "You don't have a world in your selection..");
+ sender.sendMessage(ChatColor.YELLOW + "Working with the direct world where your player is.");
+ sender.sendMessage(ChatColor.YELLOW + "Your world now uses permissions of world name: '" + dataHolder.getName() + "' ");
+ }
+ }
+ return true;
+ case manselect:
+ if (args.length < 1) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count! (/<command> <world>)");
+ sender.sendMessage(ChatColor.YELLOW + "Worlds available: ");
+ ArrayList<OverloadedWorldHolder> worlds = worldsHolder.allWorldsDataList();
+ auxString = "";
+ for (int i = 0; i < worlds.size(); i++) {
+ auxString += worlds.get(i).getName();
+ if ((i + 1) < worlds.size()) {
+ auxString += ", ";
+ }
+ }
+ sender.sendMessage(ChatColor.YELLOW + auxString);
+ return false;
+ }
+ auxString = "";
+ for (int i = 0; i < args.length; i++) {
+ if (args[i] == null) {
+ logger.warning("Bukkit gave invalid arguments array! Cmd: " + cmd.getName() + " args.length: " + args.length);
+ return false;
+ }
+ auxString += args[i];
+ if (i < (args.length - 1)) {
+ auxString += " ";
+ }
+ }
+ dataHolder = worldsHolder.getWorldData(auxString);
+ permissionHandler = dataHolder.getPermissionsHandler();
+ selectedWorlds.put(sender, dataHolder.getName());
+ sender.sendMessage(ChatColor.YELLOW + "You have selected world '" + dataHolder.getName() + "'.");
+ return true;
+ case manclear:
+ if (args.length != 0) {
+ sender.sendMessage(ChatColor.RED + "Review your arguments count!");
+ return false;
+ }
+ selectedWorlds.remove(sender);
+ sender.sendMessage(ChatColor.YELLOW + "You have removed your world selection. Working with current world(if possible).");
+ return true;
+ default:
+ break;
+ }
+ }
+ sender.sendMessage(ChatColor.RED + "You are not allowed to use that command.");
+ return false;
+ }
+
+ /**
+ * Sets up the default world for use.
+ */
+ private boolean setDefaultWorldHandler(CommandSender sender) {
+
+ dataHolder = worldsHolder.getWorldData(worldsHolder.getDefaultWorld().getName());
+ permissionHandler = dataHolder.getPermissionsHandler();
+ selectedWorlds.put(sender, dataHolder.getName());
+
+ if ((dataHolder != null) && (permissionHandler != null)) {
+ sender.sendMessage(ChatColor.RED + "Couldn't retrieve your world. Default world '" + worldsHolder.getDefaultWorld().getName() + "' selected.");
+ return true;
+ }
+
+ sender.sendMessage(ChatColor.RED + "Couldn't retrieve your world. World selection is needed.");
sender.sendMessage(ChatColor.RED + "Use /manselect <world>");
return false;
-
- }
-
- /**
- * Send confirmation of a group change.
- * using permission nodes...
- *
- * groupmanager.notify.self
- * groupmanager.notify.other
- *
- * @param name
- * @param msg
- */
- public static void notify(String name, String msg) {
-
- Player player = Bukkit.getServer().getPlayerExact(name);
-
- for(Player test: Bukkit.getServer().getOnlinePlayers()) {
- if (!test.equals(player)){
- if (test.hasPermission("groupmanager.notify.other"))
- test.sendMessage(ChatColor.YELLOW + name +" was" + msg);
- } else
- if ((player != null) && ((player.hasPermission("groupmanager.notify.self")) || (player.hasPermission("groupmanager.notify.other"))))
- player.sendMessage(ChatColor.YELLOW + "You were" + msg);
- }
-
- }
-
- /**
- * @return the config
- */
- public GMConfiguration getGMConfig() {
- return config;
- }
-
- /**
- * @return the backupFolder
- */
- public File getBackupFolder() {
- return backupFolder;
- }
+
+ }
+
+ /**
+ * Send confirmation of a group change. using permission nodes...
+ *
+ * groupmanager.notify.self groupmanager.notify.other
+ *
+ * @param name
+ * @param msg
+ */
+ public static void notify(String name, String msg) {
+
+ Player player = Bukkit.getServer().getPlayerExact(name);
+
+ for (Player test : Bukkit.getServer().getOnlinePlayers()) {
+ if (!test.equals(player)) {
+ if (test.hasPermission("groupmanager.notify.other"))
+ test.sendMessage(ChatColor.YELLOW + name + " was" + msg);
+ } else if ((player != null) && ((player.hasPermission("groupmanager.notify.self")) || (player.hasPermission("groupmanager.notify.other"))))
+ player.sendMessage(ChatColor.YELLOW + "You were" + msg);
+ }
+
+ }
+
+ /**
+ * @return the config
+ */
+ public GMConfiguration getGMConfig() {
+ return config;
+ }
+
+ /**
+ * @return the backupFolder
+ */
+ 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..e580918e7 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
@@ -40,8 +50,15 @@ public class Group extends DataUnit implements Cloneable {
*/
@Override
public Group clone() {
- Group clone = new Group(getDataSource(), this.getName());
- clone.inherits = new ArrayList<String>(this.getInherits());
+ Group clone;
+
+ if (getDataSource() == null) {
+ clone = new Group(this.getName());
+ } else {
+ clone = new Group(getDataSource(), this.getName());
+ clone.inherits = new ArrayList<String>(this.getInherits());
+ }
+
for (String perm : this.getPermissionList()) {
clone.addPermission(perm);
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java
index 4775eac1f..19db58851 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java
@@ -46,7 +46,7 @@ public class GroupVariables extends Variables implements Cloneable {
/**
* A clone of all vars here.
- * @return
+ * @return GroupVariables clone
*/
protected GroupVariables clone(Group newOwner) {
GroupVariables clone = new GroupVariables(newOwner);
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java
index 8a0e6cdbb..bcfa8e01b 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java
@@ -40,7 +40,7 @@ public class User extends DataUnit implements Cloneable {
/**
*
- * @return
+ * @return User clone
*/
@Override
public User clone() {
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java
index 3f3a6c374..0b3948cab 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java
@@ -27,7 +27,7 @@ public class UserVariables extends Variables {
/**
* A clone of all vars here.
- * @return
+ * @return UserVariables clone
*/
protected UserVariables clone(User newOwner) {
UserVariables clone = new UserVariables(newOwner);
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java
index 547e6266d..e97b01a48 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java
@@ -115,7 +115,7 @@ public abstract class Variables implements Cloneable {
/**
* All variable keys this is holding
- * @return
+ * @return Set of all variable names.
*/
public Set<String> getVarKeyList() {
return variables.keySet();
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
index 42c78cccf..e7fa81627 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
@@ -39,7 +39,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
/**
*
* @param userName
- * @return
+ * @return user object or a new user if none exists.
*/
@Override
public User getUser(String userName) {
@@ -86,7 +86,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
/**
*
* @param userName
- * @return
+ * @return true if removed/false if not found.
*/
@Override
public boolean removeUser(String userName) {
@@ -137,7 +137,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
/**
*
- * @return
+ * @return Collection of all users
*/
@Override
public Collection<User> getUserList() {
@@ -156,7 +156,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
/**
*
* @param userName
- * @return
+ * @return true if user is overloaded.
*/
public boolean isOverloaded(String userName) {
return overloadedUsers.containsKey(userName.toLowerCase());
@@ -189,8 +189,9 @@ public class OverloadedWorldHolder extends WorldDataHolder {
* Gets the user in normal state. Surpassing the overload state.
* It doesn't affect permissions. But it enables plugins change the
* actual user permissions even in overload mode.
+ *
* @param userName
- * @return
+ * @return user object
*/
public User surpassOverload(String userName) {
if (!isOverloaded(userName)) {
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
index 4a9f806d8..4140cbfea 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
@@ -45,20 +45,23 @@ public class WorldDataHolder {
* The actual groups holder
*/
protected Map<String, Group> groups = new HashMap<String, Group>();
- /**
+ /**
* The actual users holder
*/
protected Map<String, User> users = new HashMap<String, User>();
- /**
+
+ /**
* Points to the default group
*/
protected Group defaultGroup = null;
+
/**
* The file, which this class loads/save data from/to
* @deprecated
*/
@Deprecated
protected File f;
+
/**
*
*/
@@ -79,8 +82,17 @@ public class WorldDataHolder {
*
*/
protected boolean haveGroupsChanged = false;
-
/**
+ *
+ */
+ protected long timeStampGroups = 0;
+ /**
+ *
+ */
+ protected long timeStampUsers = 0;
+
+
+ /**
* Prevent direct instantiation
* @param worldName
*/
@@ -151,7 +163,7 @@ public class WorldDataHolder {
/**
*
* @param userName
- * @return
+ * @return true if we have data for this player.
*/
public boolean isUserDeclared(String userName) {
return users.containsKey(userName.toLowerCase());
@@ -183,7 +195,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 +208,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());
}
/**
@@ -201,6 +219,11 @@ public class WorldDataHolder {
* @param groupToAdd
*/
public void addGroup(Group groupToAdd) {
+ if (groupToAdd.getName().startsWith("g:")) {
+ GroupManager.getGlobalGroups().addGroup(groupToAdd);
+ return;
+ }
+
if (groupToAdd.getDataSource() != this) {
groupToAdd = groupToAdd.clone(this);
}
@@ -215,6 +238,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 +278,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().newGroup(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;
@@ -281,14 +314,34 @@ public class WorldDataHolder {
*/
public void reload() {
try {
- WorldDataHolder ph = load(this.getName(), getGroupsFile(), getUsersFile());
- this.defaultGroup = ph.defaultGroup;
- this.groups = ph.groups;
- this.users = ph.users;
+ reloadGroups();
+ reloadUsers();
} catch (Exception ex) {
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex);
}
}
+
+ public void reloadGroups() {
+ GroupManager.setLoaded(false);
+ try {
+ resetGroups();
+ loadGroups(this, getGroupsFile());
+ } catch (Exception ex) {
+ Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ GroupManager.setLoaded(true);
+ }
+
+ public void reloadUsers() {
+ GroupManager.setLoaded(false);
+ try {
+ resetUsers();
+ loadUsers(this, getUsersFile());
+ } catch (Exception ex) {
+ Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ GroupManager.setLoaded(true);
+ }
/**
* Save by yourself!
@@ -302,9 +355,11 @@ public class WorldDataHolder {
/**
* Returns a data holder for the given file
+ *
* @param worldName
* @param file
- * @return
+ * @return a new WorldDataHolder
+ *
* @throws Exception
* @deprecated
*/
@@ -448,26 +503,66 @@ public class WorldDataHolder {
}
/**
- * Returns a data holder for the given file
+ * Returns a NEW data holder containing data read from the files
+ *
* @param worldName
* @param groupsFile
* @param usersFile
- * @return
+ *
* @throws FileNotFoundException
* @throws IOException
*/
- @SuppressWarnings({"rawtypes", "unchecked"})
public static WorldDataHolder load(String worldName, File groupsFile, File usersFile) throws FileNotFoundException, IOException {
- WorldDataHolder ph = new WorldDataHolder(worldName);
- ph.groupsFile = groupsFile;
- ph.usersFile = usersFile;
+ WorldDataHolder ph = new WorldDataHolder(worldName);
+
+ GroupManager.setLoaded(false);
+ loadGroups(ph, groupsFile);
+ loadUsers(ph, usersFile);
+ GroupManager.setLoaded(true);
+
+ 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
+ *
+ * @param ph
+ * @param groupsFile
+ *
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ protected static void loadGroups(WorldDataHolder ph, File groupsFile) throws FileNotFoundException, IOException {
//READ GROUPS FILE
Yaml yamlGroups = new Yaml(new SafeConstructor());
Map<String, Object> groupsRootDataNode;
if (!groupsFile.exists()) {
- throw new IllegalArgumentException("The file which should contain permissions does not exist!\n" + groupsFile.getPath());
+ throw new IllegalArgumentException("The file which should contain groups does not exist!\n" + groupsFile.getPath());
}
FileInputStream groupsInputStream = new FileInputStream(groupsFile);
try {
@@ -483,7 +578,7 @@ public class WorldDataHolder {
//PROCESS GROUPS FILE
Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
- try {
+ //try {
Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
for (String groupKey : allGroupsNode.keySet()) {
Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
@@ -513,36 +608,43 @@ public class WorldDataHolder {
} else if (thisGroupNode.get("permissions") instanceof String) {
thisGrp.addPermission((String) thisGroupNode.get("permissions"));
} else {
- throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>): " + thisGroupNode.get("permissions").getClass().getName());
+ throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>) for group: " + thisGrp.getName());
}
//INFO NODE
- Map<String, Object> infoNode = (Map<String, Object>) thisGroupNode.get("info");
- if (infoNode != null) {
- thisGrp.setVariables(infoNode);
- }
+ if (thisGroupNode.get("info") instanceof Map) {
+ Map<String, Object> infoNode = (Map<String, Object>) thisGroupNode.get("info");
+ if (infoNode != null) {
+ thisGrp.setVariables(infoNode);
+ }
+ } else
+ throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName());
+
//END INFO NODE
- Object inheritNode = thisGroupNode.get("inheritance");
- if (inheritNode == null) {
- thisGroupNode.put("inheritance", new ArrayList<String>());
- } else if (inheritNode instanceof List) {
- List<String> groupsInh = (List<String>) inheritNode;
- for (String grp : groupsInh) {
- if (inheritance.get(groupKey) == null) {
- List<String> thisInherits = new ArrayList<String>();
- inheritance.put(groupKey, thisInherits);
- }
- inheritance.get(groupKey).add(grp);
-
- }
- }
+ if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) {
+ Object inheritNode = thisGroupNode.get("inheritance");
+ if (inheritNode == null) {
+ thisGroupNode.put("inheritance", new ArrayList<String>());
+ } else if (inheritNode instanceof List) {
+ List<String> groupsInh = (List<String>) inheritNode;
+ for (String grp : groupsInh) {
+ if (inheritance.get(groupKey) == null) {
+ List<String> thisInherits = new ArrayList<String>();
+ inheritance.put(groupKey, thisInherits);
+ }
+ inheritance.get(groupKey).add(grp);
+
+ }
+ }
+ }else
+ throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName());
}
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new IllegalArgumentException("Your Permissions config file is invalid. See console for details.");
- }
+ //} catch (Exception ex) {
+ // ex.printStackTrace();
+ // throw new IllegalArgumentException("Your Permissions config file is invalid. See console for details.");
+ //}
if (ph.defaultGroup == null) {
throw new IllegalArgumentException("There was no Default Group declared.");
}
@@ -556,13 +658,32 @@ public class WorldDataHolder {
}
}
}
+
+ ph.removeGroupsChangedFlag();
+ // Update the LastModified time.
+ ph.groupsFile = groupsFile;
+ ph.setTimeStamps();
-
+ //return ph;
+ }
+
+ /**
+ * Updates the WorldDataHolder from the Users file
+ *
+ * @param ph
+ * @param usersFile
+ *
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ protected static void loadUsers(WorldDataHolder ph, File usersFile) throws FileNotFoundException, IOException {
+
//READ USERS FILE
Yaml yamlUsers = new Yaml(new SafeConstructor());
Map<String, Object> usersRootDataNode;
- if (!groupsFile.exists()) {
- throw new IllegalArgumentException("The file which should contain permissions does not exist!\n" + usersFile.getPath());
+ if (!usersFile.exists()) {
+ throw new IllegalArgumentException("The file which should contain users does not exist!\n" + usersFile.getPath());
}
FileInputStream usersInputStream = new FileInputStream(usersFile);
try {
@@ -581,7 +702,7 @@ public class WorldDataHolder {
// Stop loading if the file is empty
if (allUsersNode == null)
- return ph;
+ return ;
for (String usersKey : allUsersNode.keySet()) {
Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
@@ -644,7 +765,13 @@ public class WorldDataHolder {
thisUser.setGroup(ph.defaultGroup);
}
}
- return ph;
+
+ ph.removeUsersChangedFlag();
+ // Update the LastModified time.
+ ph.usersFile = usersFile;
+ ph.setTimeStamps();
+
+ //return ph;
}
/**
@@ -777,6 +904,11 @@ public class WorldDataHolder {
} catch (FileNotFoundException ex) {
}
}
+
+ // Update the LastModified time.
+ ph.groupsFile = groupsFile;
+ ph.setTimeStampGroups(groupsFile.lastModified());
+ ph.removeGroupsChangedFlag();
/*FileWriter tx = null;
try {
@@ -842,6 +974,12 @@ public class WorldDataHolder {
} catch (FileNotFoundException ex) {
}
}
+
+ // Update the LastModified time.
+ ph.usersFile = usersFile;
+ ph.setTimeStampUsers(usersFile.lastModified());
+ ph.removeUsersChangedFlag();
+
/*FileWriter tx = null;
try {
tx = new FileWriter(usersFile, false);
@@ -894,7 +1032,7 @@ public class WorldDataHolder {
/**
*
- * @return
+ * @return true if any user data has changed
*/
public boolean haveUsersChanged() {
if (haveUsersChanged) {
@@ -910,7 +1048,7 @@ public class WorldDataHolder {
/**
*
- * @return
+ * @return true if any group data has changed.
*/
public boolean haveGroupsChanged() {
if (haveGroupsChanged) {
@@ -964,4 +1102,64 @@ public class WorldDataHolder {
public String getName() {
return name;
}
+
+ /**
+ * Resets Groups.
+ */
+ public void resetGroups() {
+ this.defaultGroup = null;
+ this.groups = new HashMap<String, Group>();
+ }
+ /**
+ * Resets Users
+ */
+ public void resetUsers() {
+ this.users = new HashMap<String, User>();
+ }
+
+ /**
+ * @return the groups
+ */
+ public Map<String, Group> getGroups() {
+ return groups;
+ }
+ /**
+ * @return the users
+ */
+ public Map<String, User> getUsers() {
+ return users;
+ }
+
+ /**
+ * @return the timeStampGroups
+ */
+ public long getTimeStampGroups() {
+ return timeStampGroups;
+ }
+ /**
+ * @return the timeStampUsers
+ */
+ public long getTimeStampUsers() {
+ return timeStampUsers;
+ }
+
+ /**
+ * @param timeStampGroups the timeStampGroups to set
+ */
+ protected void setTimeStampGroups(long timeStampGroups) {
+ this.timeStampGroups = timeStampGroups;
+ }
+ /**
+ * @param timeStampUsers the timeStampUsers to set
+ */
+ protected void setTimeStampUsers(long timeStampUsers) {
+ this.timeStampUsers = timeStampUsers;
+ }
+
+ public void setTimeStamps() {
+ if (groupsFile != null)
+ setTimeStampGroups(groupsFile.lastModified());
+ if (usersFile != null)
+ setTimeStampUsers(usersFile.lastModified());
+ }
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
index 7cbe4f65c..bf7b290ae 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
@@ -100,7 +100,7 @@ public class WorldsHolder {
* or mirrored worlds that don't need data.
*/
if (!worldsData.containsKey(folder.getName().toLowerCase())
- || !mirrors.containsKey(folder.getName().toLowerCase())) {
+ && !mirrors.containsKey(folder.getName().toLowerCase())) {
loadWorld(folder.getName());
}
@@ -149,6 +149,8 @@ public class WorldsHolder {
w.reload();
alreadyDone.add(w);
}
+ // Load global groups
+ GroupManager.getGlobalGroups().load();
}
/**
@@ -158,44 +160,98 @@ public class WorldsHolder {
public void reloadWorld(String worldName) {
getWorldData(worldName).reload();
}
+
+ /**
+ * Wrapper to retain backwards compatibility
+ * (call this function to auto overwrite files)
+ */
+ public void saveChanges() {
+ saveChanges(true);
+ }
/**
*
*/
- public void saveChanges() {
+ public void saveChanges(boolean overwrite) {
ArrayList<WorldDataHolder> alreadyDone = new ArrayList<WorldDataHolder>();
+ Tasks.removeOldFiles(plugin, plugin.getBackupFolder());
+
for (OverloadedWorldHolder w : worldsData.values()) {
if (alreadyDone.contains(w)) {
continue;
}
- Tasks.removeOldFiles(plugin, plugin.getBackupFolder());
if (w == null) {
GroupManager.logger.severe("WHAT HAPPENED?");
continue;
}
if (w.haveGroupsChanged()) {
- //String groupsFolderName = w.getGroupsFile().getParentFile().getName();
- File backupGroups = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + "_g_" + Tasks.getDateString() + ".yml");
- try {
- Tasks.copy(w.getGroupsFile(), backupGroups);
- } catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- }
- WorldDataHolder.writeGroups(w, w.getGroupsFile());
- w.removeGroupsChangedFlag();
+ if (overwrite || (!overwrite && (w.getTimeStampGroups() >= w.getGroupsFile().lastModified()))) {
+ // Backup Groups file
+ backupFile(w,true);
+
+ WorldDataHolder.writeGroups(w, w.getGroupsFile());
+ //w.removeGroupsChangedFlag();
+ } else {
+ // Newer file found.
+ GroupManager.logger.log(Level.WARNING, "Newer Groups file found for " + w.getName() + ", but we have local changes!");
+ throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
+ }
+ } else {
+ //Check for newer file as no local changes.
+ if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) {
+ System.out.print("Newer Groups file found (Loading changes)!");
+ // Backup Users file
+ backupFile(w,false);
+ w.reloadGroups();
+ }
}
if (w.haveUsersChanged()) {
- File backupUsers = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + "_u_" + Tasks.getDateString() + ".yml");
- try {
- Tasks.copy(w.getUsersFile(), backupUsers);
- } catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- }
- WorldDataHolder.writeUsers(w, w.getUsersFile());
- w.removeUsersChangedFlag();
+ if (overwrite || (!overwrite && (w.getTimeStampUsers() >= w.getUsersFile().lastModified()))) {
+ // Backup Users file
+ backupFile(w,false);
+
+ WorldDataHolder.writeUsers(w, w.getUsersFile());
+ //w.removeUsersChangedFlag();
+ } else {
+ // Newer file found.
+ GroupManager.logger.log(Level.WARNING, "Newer Users file found for " + w.getName() + ", but we have local changes!");
+ throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
+ }
+ } else {
+ //Check for newer file as no local changes.
+ if (w.getTimeStampUsers() < w.getUsersFile().lastModified()) {
+ System.out.print("Newer Users file found (Loading changes)!");
+ // Backup Users file
+ backupFile(w,false);
+ w.reloadUsers();
+ }
}
alreadyDone.add(w);
}
+ // Write Global Groups
+ if (GroupManager.getGlobalGroups().haveGroupsChanged()) {
+ GroupManager.getGlobalGroups().writeGroups(overwrite);
+ } else {
+ if (GroupManager.getGlobalGroups().getTimeStampGroups() < GroupManager.getGlobalGroups().getGlobalGroupsFile().lastModified()) {
+ System.out.print("Newer GlobalGroups file found (Loading changes)!");
+ GroupManager.getGlobalGroups().load();
+ }
+ }
+ }
+
+ /**
+ * Backup the Groups/Users file
+ * @param w
+ * @param groups
+ */
+ private void backupFile(OverloadedWorldHolder w, Boolean groups) {
+
+ File backupFile = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + (groups ? "_g_" : "_u_") + Tasks.getDateString() + ".yml");
+ try {
+ Tasks.copy((groups ? w.getGroupsFile() : w.getUsersFile()), backupFile);
+ } catch (IOException ex) {
+ GroupManager.logger.log(Level.SEVERE, null, ex);
+ }
}
/**
@@ -209,7 +265,7 @@ public class WorldsHolder {
* Mirrors prevails original data.
*
* @param worldName
- * @return
+ * @return OverloadedWorldHolder
*/
public OverloadedWorldHolder getWorldData(String worldName) {
OverloadedWorldHolder data = worldsData.get(worldName.toLowerCase());
@@ -239,31 +295,31 @@ public class WorldsHolder {
}
/**
- * Retrieves the field p.getWorld().getName() and do
+ * Retrieves the field player.getWorld().getName() and do
* getWorld(worldName)
- * @param p
- * @return
+ * @param player
+ * @return OverloadedWorldHolder
*/
- public OverloadedWorldHolder getWorldData(Player p) {
- return getWorldData(p.getWorld().getName());
+ public OverloadedWorldHolder getWorldData(Player player) {
+ return getWorldData(player.getWorld().getName());
}
/**
* It does getWorld(worldName).getPermissionsHandler()
* @param worldName
- * @return
+ * @return AnjoPermissionsHandler
*/
public AnjoPermissionsHandler getWorldPermissions(String worldName) {
return getWorldData(worldName).getPermissionsHandler();
}
/**
- *It does getWorldData(p).getPermission
- * @param p
- * @return
+ * Returns the PermissionsHandler for this player data
+ * @param player
+ * @return AnjoPermissionsHandler
*/
- public AnjoPermissionsHandler getWorldPermissions(Player p) {
- return getWorldData(p).getPermissionsHandler();
+ public AnjoPermissionsHandler getWorldPermissions(Player player) {
+ return getWorldData(player).getPermissionsHandler();
}
/**
@@ -352,7 +408,7 @@ public class WorldsHolder {
* Copies the specified world data to another world
* @param fromWorld
* @param toWorld
- * @return
+ * @return true if successfully copied.
*/
public boolean cloneWorld(String fromWorld, String toWorld) {
File fromWorldFolder = new File(worldsFolder, fromWorld);
@@ -401,6 +457,10 @@ public class WorldsHolder {
}
try {
OverloadedWorldHolder thisWorldData = new OverloadedWorldHolder(WorldDataHolder.load(worldName, groupsFile, usersFile));
+
+ // Set the file TimeStamps as it will be default from the initial load.
+ thisWorldData.setTimeStamps();
+
if (thisWorldData != null) {
GroupManager.logger.finest("Successful load of world " + worldName + "...");
worldsData.put(worldName.toLowerCase(), thisWorldData);
@@ -454,7 +514,7 @@ public class WorldsHolder {
/**
* Returns all physically loaded worlds.
- * @return
+ * @return ArrayList<OverloadedWorldHolder> of all loaded worlds
*/
public ArrayList<OverloadedWorldHolder> allWorldsDataList() {
ArrayList<OverloadedWorldHolder> list = new ArrayList<OverloadedWorldHolder>();
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
index 203ac95a9..b858c2a6c 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
@@ -20,1059 +20,1144 @@ import org.bukkit.entity.Player;
/**
* Everything here maintains the model created by Nijikokun
- *
+ *
* But implemented to use GroupManager system. Which provides instant changes,
* without file access.
- *
+ *
* It holds permissions only for one single world.
- *
+ *
* @author gabrielcouto
*/
public class AnjoPermissionsHandler extends PermissionsReaderInterface {
- WorldDataHolder ph = null;
-
- /**
- * It needs a WorldDataHolder to work with.
- * @param holder
- */
- public AnjoPermissionsHandler(WorldDataHolder holder) {
- ph = holder;
- }
-
- /**
- * A short name method, for permission method.
- * @param player
- * @param permission
- * @return
- */
- @Override
- public boolean has(Player player, String permission) {
- return permission(player, permission);
- }
-
- /**
- * Checks if a player can use that permission node.
- * @param player
- * @param permission
- * @return
- */
- @Override
- public boolean permission(Player player, String permission) {
- return checkUserPermission(ph.getUser(player.getName()), permission);
- }
-
- /**
- * Checks if a player can use that permission node.
- * @param playerName
- * @param permission
- * @return
- */
- public boolean permission(String playerName, String permission) {
- return checkUserPermission(ph.getUser(playerName), permission);
- }
-
- /**
- * Returns the name of the group of that player name.
- * @param userName
- * @return
- */
- @Override
- public String getGroup(String userName) {
- return ph.getUser(userName).getGroup().getName();
- }
-
- /**
- * Returns All permissions (including inheritance and sub groups) for the player.
- *
- * @param userName
- * @return
- */
- @Override
- public List<String> getAllPlayersPermissions(String userName) {
-
- 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);
- }
- }
-
- }
- }
- }
-
- return playerPermArray;
- }
-
- /**
- * Verify if player is in suck group.
- * It will check it's groups inheritance.
- *
- * So if you have a group Admin > Moderator
- *
- * And verify the player 'MyAdmin', which is Admin, it will return true for both
- * Admin or Moderator groups.
- *
- * Mas if you have a player 'MyModerator', which is Moderator,
- * it will give false if you pass Admin in group parameter.
- *
- * @param name
- * @param group
- * @return
- */
- @Override
- public boolean inGroup(String name, String group) {
- if (hasGroupInInheritance(ph.getUser(name).getGroup(), group)) {
- return true;
- }
- for (Group subGroup : ph.getUser(name).subGroupListCopy()) {
- if (hasGroupInInheritance(subGroup, group)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Gets the appropriate prefix for the user.
- * This method is a utility method for chat plugins to get the user's prefix
- * without having to look at every one of the user's ancestors.
- * Returns an empty string if user has no parent groups.
- * @param user Player's name
- * @return Player's prefix
- */
- @Override
- public String getUserPrefix(String user) {
-
- String prefix = ph.getUser(user).getVariables().getVarString("prefix");
- if (prefix.length() != 0) {
- return prefix;
- }
-
- return getGroupPrefix(getGroup(user));
- }
-
- /**
- * Gets the appropriate prefix for the user.
- * This method is a utility method for chat plugins to get the user's prefix
- * without having to look at every one of the user's ancestors.
- * Returns an empty string if user has no parent groups.
- * @param user Player's name
- * @return Player's prefix
- */
- @Override
- public String getUserSuffix(String user) {
-
- String suffix = ph.getUser(user).getVariables().getVarString("suffix");
- if (suffix.length() != 0) {
- return suffix;
- }
-
- return getGroupSuffix(getGroup(user));
-
- }
-
- /**
- * Gets name of the primary group of the user.
- * Returns the name of the default group if user has no parent groups,
- * or "Default" if there is no default group for that world.
- * @param user Player's name
- * @return Name of player's primary group
- */
- public String getPrimaryGroup(String user) {
-
- return getGroup(user);
-
- }
-
- /**
- * Check if user can build.
- * @param world Player's world
- * @param user Player's name
- * @return Whether the user can build
- */
- public boolean canUserBuild(String user) {
- boolean test = ph.getUser(user).getVariables().getVarBoolean("build");
-
- if (test) {
- return test;
- }
-
- return canGroupBuild(getGroup(user));
-
- }
-
- /**
- * Returns the String prefix for the given group
- * @param groupName
- * @return empty string if found none.
- */
- @Override
- public String getGroupPrefix(String groupName) {
- Group g = ph.getGroup(groupName);
- if (g == null) {
- return "";
- }
- return g.getVariables().getVarString("prefix");
- }
-
- /**
- * Return the suffix for the given group name
- * @param groupName
- * @return
- */
- @Override
- public String getGroupSuffix(String groupName) {
- Group g = ph.getGroup(groupName);
- if (g == null) {
- return "";
- }
- return g.getVariables().getVarString("suffix");
- }
-
- /**
- *
- * @param groupName
- * @return
- */
- @Override
- public boolean canGroupBuild(String groupName) {
- Group g = ph.getGroup(groupName);
- if (g == null) {
- return false;
- }
- return g.getVariables().getVarBoolean("build");
- }
-
- /**
- * It returns a string variable value, set in the INFO node of the group.
- * It will harvest inheritance for value.
- * @param groupName
- * @param variable
- * @return null if no group with that variable is found.
- */
- @Override
- public String getGroupPermissionString(String groupName, String variable) {
- Group start = ph.getGroup(groupName);
- if (start == null) {
- return null;
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return null;
- }
- return result.getVariables().getVarString(variable);
- }
-
- /**
- * It returns a Integer variable value
- * It will harvest inheritance for value.
- * @param groupName
- * @param variable
- * @return -1 if none found or not parseable.
- */
- @Override
- public int getGroupPermissionInteger(String groupName, String variable) {
- Group start = ph.getGroup(groupName);
- if (start == null) {
- return -1;
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return -1;
- }
- return result.getVariables().getVarInteger(variable);
- }
-
- /**
- * Returns a boolean for given variable in INFO node.
- * It will harvest inheritance for value.
- * @param group
- * @param variable
- * @return false if not found/not parseable.
- */
- @Override
- public boolean getGroupPermissionBoolean(String group, String variable) {
- Group start = ph.getGroup(group);
- if (start == null) {
- return false;
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return false;
- }
- return result.getVariables().getVarBoolean(variable);
- }
-
- /**
- * Returns a double value for the given variable name in INFO node.
- * It will harvest inheritance for value.
- * @param group
- * @param variable
- * @return -1 if not found / not parseable.
- */
- @Override
- public double getGroupPermissionDouble(String group, String variable) {
- Group start = ph.getGroup(group);
- if (start == null) {
- return -1;
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return -1;
- }
- return result.getVariables().getVarDouble(variable);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * @param user
- * @param variable
- * @return
- */
- @Override
- public String getUserPermissionString(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return "";
- }
- return auser.getVariables().getVarString(variable);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * @param user
- * @param variable
- * @return
- */
- @Override
- public int getUserPermissionInteger(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return -1;
- }
- return auser.getVariables().getVarInteger(variable);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * @param user
- * @param variable
- * @return
- */
- @Override
- public boolean getUserPermissionBoolean(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return false;
- }
- return auser.getVariables().getVarBoolean(variable);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * @param user
- * @param variable
- * @return
- */
- @Override
- public double getUserPermissionDouble(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return -1;
- }
- return auser.getVariables().getVarDouble(variable);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * If not found, it will search for his Group variables.
- * It will harvest the inheritance.
- * @param user
- * @param variable
- * @return empty string if not found
- */
- @Override
- public String getPermissionString(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return "";
- }
- if (auser.getVariables().hasVar(variable)) {
- return auser.getVariables().getVarString(variable);
- }
- Group start = auser.getGroup();
- if (start == null) {
- return "";
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return "";
- }
- return result.getVariables().getVarString(variable);
- //return getUserPermissionString(user, variable);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * If not found, it will search for his Group variables.
- * It will harvest the inheritance.
- * @param user
- * @param variable
- * @return -1 if not found
- */
- @Override
- public int getPermissionInteger(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return -1;
- }
- if (auser.getVariables().hasVar(variable)) {
- return auser.getVariables().getVarInteger(variable);
- }
- Group start = auser.getGroup();
- if (start == null) {
- return -1;
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return -1;
- }
- return result.getVariables().getVarInteger(variable);
- //return getUserPermissionInteger(string, string1);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * If not found, it will search for his Group variables.
- * It will harvest the inheritance.
- * @param user
- * @param variable
- * @return false if not found or not parseable to true.
- */
- @Override
- public boolean getPermissionBoolean(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return false;
- }
- if (auser.getVariables().hasVar(variable)) {
- return auser.getVariables().getVarBoolean(variable);
- }
- Group start = auser.getGroup();
- if (start == null) {
- return false;
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return false;
- }
- return result.getVariables().getVarBoolean(variable);
- //return getUserPermissionBoolean(user, string1);
- }
-
- /**
- * Returns the variable value of the user, in INFO node.
- * If not found, it will search for his Group variables.
- * It will harvest the inheritance.
- * @param user
- * @param variable
- * @return -1 if not found.
- */
- @Override
- public double getPermissionDouble(String user, String variable) {
- User auser = ph.getUser(user);
- if (auser == null) {
- return -1.0D;
- }
- if (auser.getVariables().hasVar(variable)) {
- return auser.getVariables().getVarDouble(variable);
- }
- Group start = auser.getGroup();
- if (start == null) {
- return -1.0D;
- }
- Group result = nextGroupWithVariable(start, variable);
- if (result == null) {
- return -1.0D;
- }
- return result.getVariables().getVarDouble(variable);
- //return getUserPermissionDouble(string, string1);
- }
-
- /**
- * Does not include User's group permission
- * @param user
- * @param permission
- * @return
- */
- public PermissionCheckResult checkUserOnlyPermission(User user, String permission) {
- user.sortPermissions();
- PermissionCheckResult result = new PermissionCheckResult();
- result.askedPermission = permission;
- result.owner = user;
- for (String access : user.getPermissionList()) {
- if (comparePermissionString(access, permission)) {
- result.accessLevel = access;
- if (access.startsWith("-")) {
- result.resultType = PermissionCheckResult.Type.NEGATION;
- } else if (access.startsWith("+")) {
- result.resultType = PermissionCheckResult.Type.EXCEPTION;
- } else {
- result.resultType = PermissionCheckResult.Type.FOUND;
- }
- return result;
- }
- }
- result.resultType = PermissionCheckResult.Type.NOTFOUND;
- return result;
- }
-
- /**
- * Returns the node responsible for that permission.
- * Does not include User's group permission.
- * @param group
- * @param permission
- * @return the node if permission is found. if not found, return null
- */
- public PermissionCheckResult checkGroupOnlyPermission(Group group, String permission) {
- group.sortPermissions();
- PermissionCheckResult result = new PermissionCheckResult();
- result.owner = group;
- result.askedPermission = permission;
- for (String access : group.getPermissionList()) {
- if (comparePermissionString(access, permission)) {
- result.accessLevel = access;
- if (access.startsWith("-")) {
- result.resultType = PermissionCheckResult.Type.NEGATION;
- } else if (access.startsWith("+")) {
- result.resultType = PermissionCheckResult.Type.EXCEPTION;
- } else {
- result.resultType = PermissionCheckResult.Type.FOUND;
- }
- return result;
- }
- }
- result.resultType = PermissionCheckResult.Type.NOTFOUND;
- return result;
- }
-
- /**
- * Check permissions, including it's group and inheritance.
- * @param user
- * @param permission
- * @return true if permission was found. false if not, or was negated.
- */
- public boolean checkUserPermission(User user, String permission) {
- PermissionCheckResult result = checkFullUserPermission(user, permission);
- if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION)
- || result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
- return true;
- }
- if (Bukkit.getPlayer(user.getName()).hasPermission(permission))
- return true;
-
- return false;
- }
-
- /**
- * Do what checkUserPermission did before. But now returning a PermissionCheckResult.
- * @param user
- * @param targetPermission
- * @return
- */
- public PermissionCheckResult checkFullUserPermission(User user, String targetPermission) {
- PermissionCheckResult result = new PermissionCheckResult();
- result.askedPermission = targetPermission;
- result.resultType = PermissionCheckResult.Type.NOTFOUND;
-
- if (user == null || targetPermission == null) {
- return result;
- }
-
- PermissionCheckResult resultUser = checkUserOnlyPermission(user, targetPermission);
- if (!resultUser.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- return resultUser;
- }
-
- //IT ONLY CHECKS GROUPS PERMISSIONS IF RESULT FOR USER IS NOT FOUND
- PermissionCheckResult resultGroup = checkGroupPermissionWithInheritance(user.getGroup(), targetPermission);
- if (!resultGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- return resultGroup;
- }
-
- //SUBGROUPS CHECK
- for (Group subGroup : user.subGroupListCopy()) {
- PermissionCheckResult resultSubGroup = checkGroupPermissionWithInheritance(subGroup, targetPermission);
- if (!resultSubGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- return resultSubGroup;
- }
- }
-
- if (Bukkit.getPlayer(user.getName()).hasPermission(targetPermission)) {
- result.resultType = PermissionCheckResult.Type.FOUND;
- result.owner = user;
- return result;
- }
-
- //THEN IT RETURNS A NOT FOUND
- return result;
- }
-
- /**
- * Verifies if a given group has a variable. Including it's inheritance.
- *
- * it redirects to the other method now. This one was deprecated, and will
- * be gone in a future release.
- *
- * @param start
- * @param variable
- * @param alreadyChecked
- * @return returns the closest inherited group with the variable.
- * @deprecated use now nextGroupWithVariable(Group start, String targetVariable)
- */
- @Deprecated
- public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) {
- return nextGroupWithVariable(start, variable);
- }
-
- /**
- * Returns the next group, including inheritance, which contains that
- * variable name.
- *
- * It does Breadth-first search
- *
- * @param start the starting group to look for
- * @param targetVariable the variable name
- * @return The group if found. Null if not.
- */
- public Group nextGroupWithVariable(Group start, String targetVariable) {
- if (start == null || targetVariable == null) {
- return null;
- }
- LinkedList<Group> stack = new LinkedList<Group>();
- ArrayList<Group> alreadyVisited = new ArrayList<Group>();
- stack.push(start);
- alreadyVisited.add(start);
- while (!stack.isEmpty()) {
- Group now = stack.pop();
- if (now.getVariables().hasVar(targetVariable)) {
- return now;
- }
- for (String sonName : now.getInherits()) {
- Group son = ph.getGroup(sonName);
- if (son != null && !alreadyVisited.contains(son)) {
- stack.push(son);
- alreadyVisited.add(son);
- }
- }
- }
- return null;
- }
-
- /**
- * Check if given group inherits another group.
- *
- * redirected to the other method. this is deprecated now. and will be gone
- * in the future releases.
- *
- * @param start The group to start the search.
- * @param askedGroup Name of the group you're looking for
- * @param alreadyChecked groups to ignore(pass null on it, please)
- * @return true if it inherits the group.
- * @deprecated prefer using hasGroupInInheritance(Group start, String askedGroup)
- */
- @Deprecated
- public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) {
- return hasGroupInInheritance(start, askedGroup);
- }
-
- /**
- * Check if given group inherits another group.
- *
- * It does Breadth-first search
- *
- * @param start The group to start the search.
- * @param askedGroup Name of the group you're looking for
- * @return true if it inherits the group.
- */
- public boolean hasGroupInInheritance(Group start, String askedGroup) {
- if (start == null || askedGroup == null) {
- return false;
- }
- LinkedList<Group> stack = new LinkedList<Group>();
- ArrayList<Group> alreadyVisited = new ArrayList<Group>();
- stack.push(start);
- alreadyVisited.add(start);
- while (!stack.isEmpty()) {
- Group now = stack.pop();
- if (now.getName().equalsIgnoreCase(askedGroup)) {
- return true;
- }
- for (String sonName : now.getInherits()) {
- Group son = ph.getGroup(sonName);
- if (son != null && !alreadyVisited.contains(son)) {
- stack.push(son);
- alreadyVisited.add(son);
- }
- }
- }
- return false;
- }
-
- /**
- * Check if the group has given permission. Including it's inheritance
- * @param start
- * @param permission
- * @param alreadyChecked
- * @return true if PermissionCheckResult is EXCEPTION or FOUND
- * @deprecated use the other checkGroupPermissionWithInheritance for everything
- */
- @Deprecated
- public boolean checkGroupPermissionWithInheritance(Group start, String permission, List<Group> alreadyChecked) {
- PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
- if (result.resultType.equals(Type.EXCEPTION)
- || result.resultType.equals(Type.FOUND)) {
- return true;
- }
- return false;
- }
-
- /**
- * Returns the result of permission check. Including inheritance.
- * If found anything, the PermissionCheckResult that retuns will
- * include the Group name, and the result type.
- * Result types will be EXCEPTION, NEGATION, FOUND.
- *
- * If returned type NOTFOUND, the owner will be null,
- * and ownerType too.
- *
- * It does Breadth-first search
- *
- * @param start
- * @param targetPermission
- * @return
- */
- public PermissionCheckResult checkGroupPermissionWithInheritance(Group start, String targetPermission) {
- if (start == null || targetPermission == null) {
- return null;
- }
- LinkedList<Group> stack = new LinkedList<Group>();
- List<Group> alreadyVisited = new ArrayList<Group>();
- stack.push(start);
- alreadyVisited.add(start);
- while (!stack.isEmpty()) {
- Group now = stack.pop();
- PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targetPermission);
- if (!resultNow.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
- return resultNow;
- }
- for (String sonName : now.getInherits()) {
- Group son = ph.getGroup(sonName);
- if (son != null && !alreadyVisited.contains(son)) {
- stack.push(son);
- alreadyVisited.add(son);
- }
- }
- }
- PermissionCheckResult result = new PermissionCheckResult();
- result.askedPermission = targetPermission;
- result.resultType = PermissionCheckResult.Type.NOTFOUND;
- return result;
- }
-
- /**
- * It uses checkGroupPermissionWithInheritance
- * and cast the owner to Group type if result type was EXCEPTION or FOUND.
- *
- * @param start
- * @param permission
- * @param alreadyChecked
- * @return the group that passed on test. null if no group passed.
- * @deprecated use checkGroupPermissionWithInheritance for everything now.
- */
- @Deprecated
- public Group nextGroupWithPermission(Group start, String permission, List<Group> alreadyChecked) {
- PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
- if (result.resultType.equals(Type.EXCEPTION)
- || result.resultType.equals(Type.FOUND)) {
- return (Group) checkGroupPermissionWithInheritance(start, permission).owner;
- }
- return null;
- }
-
- /**
- * Return whole list of names of groups in a inheritance chain. Including a
- * starting group.
- *
- * it now redirects to the other method. but get away from this one,
- * it will disappear in a future release.
- *
- * @param start
- * @param alreadyChecked
- * @return the group that passed on test. null if no group passed.
- * @deprecated use the other method with same name, instead
- */
- @Deprecated
- public ArrayList<String> listAllGroupsInherited(Group start, ArrayList<String> alreadyChecked) {
- return listAllGroupsInherited(start);
- }
-
- /**
- * Return whole list of names of groups in a inheritance chain. Including a
- * starting group.
- *
- * It does Breadth-first search. So closer groups will appear first in list.
- *
- * @param start
- * @return the group that passed on test. null if no group passed.
- */
- public ArrayList<String> listAllGroupsInherited(Group start) {
- if (start == null) {
- return null;
- }
- LinkedList<Group> stack = new LinkedList<Group>();
- ArrayList<String> alreadyVisited = new ArrayList<String>();
- stack.push(start);
- alreadyVisited.add(start.getName());
- while (!stack.isEmpty()) {
- Group now = stack.pop();
- for (String sonName : now.getInherits()) {
- Group son = ph.getGroup(sonName);
- if (son != null && !alreadyVisited.contains(son.getName())) {
- stack.push(son);
- alreadyVisited.add(son.getName());
- }
- }
- }
- return alreadyVisited;
- }
-
- /**
- * Compare a user permission like 'myplugin.*' against a full plugin
- * permission name, like 'myplugin.dosomething'.
- * As the example above, will return true.
- *
- * Please sort permissions before sending them here. So negative tokens
- * get priority.
- *
- * You must test if it start with negative outside this method. It will
- * only tell if the nodes are matching or not.
- *
- * Every '-' or '+' in the beginning is ignored. It will match only
- * node names.
- *
- * @param userAcessLevel
- * @param fullPermissionName
- * @return true if found a matching token. false if not.
- */
- public boolean comparePermissionString(String userAcessLevel, String fullPermissionName) {
- if (userAcessLevel == null || fullPermissionName == null) {
- return false;
- }
- GroupManager.logger.finest("COMPARING " + userAcessLevel + " WITH " + fullPermissionName);
-
- if (userAcessLevel.startsWith("+")) {
- userAcessLevel = userAcessLevel.substring(1);
- } else if (userAcessLevel.startsWith("-")) {
- userAcessLevel = userAcessLevel.substring(1);
- }
-
- if (fullPermissionName.startsWith("+")) {
- fullPermissionName = fullPermissionName.substring(1);
- } else if (fullPermissionName.startsWith("-")) {
- fullPermissionName = fullPermissionName.substring(1);
- }
-
-
- StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, ".");
- StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, ".");
- while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) {
- String levelA = levelATokenizer.nextToken();
- String levelB = levelBTokenizer.nextToken();
- GroupManager.logger.finest("ROUND " + levelA + " AGAINST " + levelB);
- if (levelA.contains("*")) {
- GroupManager.logger.finest("WIN");
- return true;
- }
- if (levelA.equalsIgnoreCase(levelB)) {
- if (!levelATokenizer.hasMoreTokens() && !levelBTokenizer.hasMoreTokens()) {
- GroupManager.logger.finest("WIN");
- return true;
- }
- GroupManager.logger.finest("NEXT");
- continue;
- } else {
- GroupManager.logger.finest("FAIL");
- return false;
- }
-
- }
- GroupManager.logger.finest("FAIL");
- return false;
- }
-
- /**
- * Returns a list of all groups.
- *
- * Including subgroups.
- * @param userName
- * @return
- */
- @Override
- public String[] getGroups(String userName) {
- ArrayList<String> allGroups = listAllGroupsInherited(ph.getUser(userName).getGroup());
- for (Group subg : ph.getUser(userName).subGroupListCopy()) {
- allGroups.addAll(listAllGroupsInherited(subg));
- }
- String[] arr = new String[allGroups.size()];
- return allGroups.toArray(arr);
- }
-
- /**
- * A Breadth-first search thru inheritance model.
- *
- * Just a model to copy and paste.
- * This will guarantee the closer groups will be checked first.
- * @param start
- * @param targerPermission
- * @return
- */
- @SuppressWarnings("unused")
- private Group breadthFirstSearch(Group start, String targerPermission) {
- if (start == null || targerPermission == null) {
- return null;
- }
- LinkedList<Group> stack = new LinkedList<Group>();
- ArrayList<Group> alreadyVisited = new ArrayList<Group>();
- stack.push(start);
- alreadyVisited.add(start);
- while (!stack.isEmpty()) {
- Group now = stack.pop();
- PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targerPermission);
- if (resultNow.resultType.equals(PermissionCheckResult.Type.EXCEPTION)
- || resultNow.resultType.equals(PermissionCheckResult.Type.FOUND)) {
- return now;
- }
- if (resultNow.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- return null;
- }
- for (String sonName : now.getInherits()) {
- Group son = ph.getGroup(sonName);
- if (son != null && !alreadyVisited.contains(son)) {
- stack.push(son);
- alreadyVisited.add(son);
- }
- }
- }
- return null;
- }
-
- @Override
- public Group getDefaultGroup() {
- return ph.getDefaultGroup();
- }
-
- @Override
- public String getInfoString(String entryName, String path,
- boolean isGroup) {
- if (isGroup) {
- Group data = ph.getGroup(entryName);
- if (data == null) {
- return null;
- }
- return data.getVariables().getVarString(path);
- } else {
- User data = ph.getUser(entryName);
- if (data == null) {
- return null;
- }
- return data.getVariables().getVarString(path);
- }
- }
-
- @Override
- public int getInfoInteger(String entryName, String path,
- boolean isGroup) {
- if (isGroup) {
- Group data = ph.getGroup(entryName);
- if (data == null) {
- return -1;
- }
- return data.getVariables().getVarInteger(path);
- } else {
- User data = ph.getUser(entryName);
- if (data == null) {
- return -1;
- }
- return data.getVariables().getVarInteger(path);
- }
- }
-
- @Override
- public double getInfoDouble(String entryName, String path,
- boolean isGroup) {
- if (isGroup) {
- Group data = ph.getGroup(entryName);
- if (data == null) {
- return -1;
- }
- return data.getVariables().getVarDouble(path);
- } else {
- User data = ph.getUser(entryName);
- if (data == null) {
- return -1;
- }
- return data.getVariables().getVarDouble(path);
- }
-
- }
-
- @Override
- public boolean getInfoBoolean(String entryName, String path,
- boolean isGroup) {
- if (isGroup) {
- Group data = ph.getGroup(entryName);
- if (data == null) {
- return false;
- }
- return data.getVariables().getVarBoolean(path);
- } else {
- User data = ph.getUser(entryName);
- if (data == null) {
- return false;
- }
- return data.getVariables().getVarBoolean(path);
- }
- }
-
- @Override
- public void addUserInfo(String name, String path, Object data) {
- ph.getUser(name).getVariables().addVar(path, data);
- }
-
- @Override
- public void removeUserInfo(String name, String path) {
- ph.getUser(name).getVariables().removeVar(path);
- }
-
- @Override
- public void addGroupInfo(String name, String path, Object data) {
- ph.getGroup(name).getVariables().addVar(path, data);
- }
-
- @Override
- public void removeGroupInfo(String name, String path) {
- ph.getGroup(name).getVariables().removeVar(path);
- }
+ WorldDataHolder ph = null;
+
+ /**
+ * It needs a WorldDataHolder to work with.
+ *
+ * @param holder
+ */
+ public AnjoPermissionsHandler(WorldDataHolder holder) {
+ ph = holder;
+ }
+
+ /**
+ * A short name method, for permission method.
+ *
+ * @param player
+ * @param permission
+ * @return true if the player has the permission
+ */
+ @Override
+ public boolean has(Player player, String permission) {
+ return permission(player, permission);
+ }
+
+ /**
+ * Checks if a player can use that permission node.
+ *
+ * @param player
+ * @param permission
+ * @return true if the player has the permission
+ */
+ @Override
+ public boolean permission(Player player, String permission) {
+ return checkUserPermission(ph.getUser(player.getName()), permission);
+ }
+
+ /**
+ * Checks if a player can use that permission node.
+ *
+ * @param playerName
+ * @param permission
+ * @return true if the player has the permission
+ */
+ public boolean permission(String playerName, String permission) {
+ return checkUserPermission(ph.getUser(playerName), permission);
+ }
+
+ /**
+ * Returns the name of the group of that player name.
+ *
+ * @param userName
+ * @return String of players group name.
+ */
+ @Override
+ public String getGroup(String userName) {
+ return ph.getUser(userName).getGroup().getName();
+ }
+
+ /**
+ * Returns All permissions (including inheritance and sub groups) for the
+ * player.
+ *
+ * @param userName
+ * @return List<String> of all players permissions.
+ */
+ @Override
+ public List<String> getAllPlayersPermissions(String userName) {
+
+ List<String> playerPermArray = new ArrayList<String>(ph.getUser(userName).getPermissionList());
+
+ 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;
+ }
+
+ /**
+ * Verify if player is in such group. It will check it's groups inheritance.
+ *
+ * So if you have a group Admin > Moderator
+ *
+ * And verify the player 'MyAdmin', which is Admin, it will return true for
+ * both Admin or Moderator groups.
+ *
+ * If you have a player 'MyModerator', which is Moderator, it will give
+ * false if you pass Admin in group parameter.
+ *
+ * @param name
+ * @param group
+ * @return true if in group (with inheritance)
+ */
+ @Override
+ public boolean inGroup(String name, String group) {
+ if (hasGroupInInheritance(ph.getUser(name).getGroup(), group)) {
+ return true;
+ }
+ for (Group subGroup : ph.getUser(name).subGroupListCopy()) {
+ if (hasGroupInInheritance(subGroup, group)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Gets the appropriate prefix for the user. This method is a utility method
+ * for chat plugins to get the user's prefix without having to look at every
+ * one of the user's ancestors. Returns an empty string if user has no
+ * parent groups.
+ *
+ * @param user
+ * Player's name
+ * @return Player's prefix
+ */
+ @Override
+ public String getUserPrefix(String user) {
+
+ String prefix = ph.getUser(user).getVariables().getVarString("prefix");
+ if (prefix.length() != 0) {
+ return prefix;
+ }
+
+ return getGroupPrefix(getGroup(user));
+ }
+
+ /**
+ * Gets the appropriate prefix for the user. This method is a utility method
+ * for chat plugins to get the user's prefix without having to look at every
+ * one of the user's ancestors. Returns an empty string if user has no
+ * parent groups.
+ *
+ * @param user
+ * Player's name
+ * @return Player's prefix
+ */
+ @Override
+ public String getUserSuffix(String user) {
+
+ String suffix = ph.getUser(user).getVariables().getVarString("suffix");
+ if (suffix.length() != 0) {
+ return suffix;
+ }
+
+ return getGroupSuffix(getGroup(user));
+
+ }
+
+ /**
+ * Gets name of the primary group of the user. Returns the name of the
+ * default group if user has no parent groups, or "Default" if there is no
+ * default group for that world.
+ *
+ * @param user
+ * Player's name
+ * @return Name of player's primary group
+ */
+ public String getPrimaryGroup(String user) {
+
+ return getGroup(user);
+
+ }
+
+ /**
+ * Check if user can build. Checks inheritance and subgroups.
+ *
+ * @param userName Player's name
+ * @return true if the user can build
+ */
+ public boolean canUserBuild(String userName) {
+
+ return getPermissionBoolean(userName, "build");
+
+ }
+
+ /**
+ * Returns the String prefix for the given group
+ *
+ * @param groupName
+ * @return empty string if found none.
+ */
+ @Override
+ public String getGroupPrefix(String groupName) {
+ Group g = ph.getGroup(groupName);
+ if (g == null) {
+ return "";
+ }
+ return g.getVariables().getVarString("prefix");
+ }
+
+ /**
+ * Return the suffix for the given group name
+ *
+ * @param groupName
+ * @return empty string if not found.
+ */
+ @Override
+ public String getGroupSuffix(String groupName) {
+ Group g = ph.getGroup(groupName);
+ if (g == null) {
+ return "";
+ }
+ return g.getVariables().getVarString("suffix");
+ }
+
+ /**
+ * Checks the specified group for the Info Build node.
+ * Does NOT check inheritance
+ *
+ * @param groupName
+ * @return true if can build
+ */
+ @Override
+ public boolean canGroupBuild(String groupName) {
+ Group g = ph.getGroup(groupName);
+ if (g == null) {
+ return false;
+ }
+ return g.getVariables().getVarBoolean("build");
+ }
+
+ /**
+ * It returns a string variable value, set in the INFO node of the group. It
+ * will harvest inheritance for value.
+ *
+ * @param groupName
+ * @param variable
+ * @return null if no group with that variable is found.
+ */
+ @Override
+ public String getGroupPermissionString(String groupName, String variable) {
+ Group start = ph.getGroup(groupName);
+ if (start == null) {
+ return null;
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ return null;
+ }
+ return result.getVariables().getVarString(variable);
+ }
+
+ /**
+ * It returns a Integer variable value It will harvest inheritance for
+ * value.
+ *
+ * @param groupName
+ * @param variable
+ * @return -1 if none found or not parseable.
+ */
+ @Override
+ public int getGroupPermissionInteger(String groupName, String variable) {
+ Group start = ph.getGroup(groupName);
+ if (start == null) {
+ return -1;
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ return -1;
+ }
+ return result.getVariables().getVarInteger(variable);
+ }
+
+ /**
+ * Returns a boolean for given variable in INFO node. It will harvest
+ * inheritance for value.
+ *
+ * @param group
+ * @param variable
+ * @return false if not found/not parseable.
+ */
+ @Override
+ public boolean getGroupPermissionBoolean(String group, String variable) {
+ Group start = ph.getGroup(group);
+ if (start == null) {
+ return false;
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ return false;
+ }
+ return result.getVariables().getVarBoolean(variable);
+ }
+
+ /**
+ * Returns a double value for the given variable name in INFO node. It will
+ * harvest inheritance for value.
+ *
+ * @param group
+ * @param variable
+ * @return -1 if not found / not parseable.
+ */
+ @Override
+ public double getGroupPermissionDouble(String group, String variable) {
+ Group start = ph.getGroup(group);
+ if (start == null) {
+ return -1;
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ return -1;
+ }
+ return result.getVariables().getVarDouble(variable);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node.
+ *
+ * @param user
+ * @param variable
+ * @return empty string if not found
+ */
+ @Override
+ public String getUserPermissionString(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return "";
+ }
+ return auser.getVariables().getVarString(variable);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node.
+ *
+ * @param user
+ * @param variable
+ * @return -1 if not found
+ */
+ @Override
+ public int getUserPermissionInteger(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return -1;
+ }
+ return auser.getVariables().getVarInteger(variable);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node.
+ *
+ * @param user
+ * @param variable
+ * @return boolean value
+ */
+ @Override
+ public boolean getUserPermissionBoolean(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return false;
+ }
+ return auser.getVariables().getVarBoolean(variable);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node.
+ *
+ * @param user
+ * @param variable
+ * @return -1 if not found
+ */
+ @Override
+ public double getUserPermissionDouble(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return -1;
+ }
+ return auser.getVariables().getVarDouble(variable);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node. If not found, it
+ * will search for his Group variables. It will harvest the inheritance and
+ * subgroups.
+ *
+ * @param user
+ * @param variable
+ * @return empty string if not found
+ */
+ @Override
+ public String getPermissionString(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return "";
+ }
+ if (auser.getVariables().hasVar(variable)) {
+ return auser.getVariables().getVarString(variable);
+ }
+ Group start = auser.getGroup();
+ if (start == null) {
+ return "";
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ // Check sub groups
+ if (!auser.isSubGroupsEmpty())
+ for (Group subGroup : auser.subGroupListCopy()) {
+ result = nextGroupWithVariable(subGroup, variable);
+ // Found value?
+ if (result != null)
+ continue;
+ }
+ if (result == null)
+ return "";
+ }
+ return result.getVariables().getVarString(variable);
+ // return getUserPermissionString(user, variable);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node. If not found, it
+ * will search for his Group variables. It will harvest the inheritance and
+ * subgroups.
+ *
+ * @param user
+ * @param variable
+ * @return -1 if not found
+ */
+ @Override
+ public int getPermissionInteger(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return -1;
+ }
+ if (auser.getVariables().hasVar(variable)) {
+ return auser.getVariables().getVarInteger(variable);
+ }
+ Group start = auser.getGroup();
+ if (start == null) {
+ return -1;
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ // Check sub groups
+ if (!auser.isSubGroupsEmpty())
+ for (Group subGroup : auser.subGroupListCopy()) {
+ result = nextGroupWithVariable(subGroup, variable);
+ // Found value?
+ if (result != null)
+ continue;
+ }
+ if (result == null)
+ return -1;
+ }
+ return result.getVariables().getVarInteger(variable);
+ // return getUserPermissionInteger(string, string1);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node. If not found, it
+ * will search for his Group variables. It will harvest the inheritance and
+ * subgroups.
+ *
+ * @param user
+ * @param variable
+ * @return false if not found or not parseable to true.
+ */
+ @Override
+ public boolean getPermissionBoolean(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return false;
+ }
+ if (auser.getVariables().hasVar(variable)) {
+ return auser.getVariables().getVarBoolean(variable);
+ }
+ Group start = auser.getGroup();
+ if (start == null) {
+ return false;
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ // Check sub groups
+ if (!auser.isSubGroupsEmpty())
+ for (Group subGroup : auser.subGroupListCopy()) {
+ result = nextGroupWithVariable(subGroup, variable);
+ // Found value?
+ if (result != null)
+ continue;
+ }
+ if (result == null)
+ return false;
+ }
+ return result.getVariables().getVarBoolean(variable);
+ // return getUserPermissionBoolean(user, string1);
+ }
+
+ /**
+ * Returns the variable value of the user, in INFO node. If not found, it
+ * will search for his Group variables. It will harvest the inheritance and
+ * subgroups.
+ *
+ * @param user
+ * @param variable
+ * @return -1 if not found.
+ */
+ @Override
+ public double getPermissionDouble(String user, String variable) {
+ User auser = ph.getUser(user);
+ if (auser == null) {
+ return -1.0D;
+ }
+ if (auser.getVariables().hasVar(variable)) {
+ return auser.getVariables().getVarDouble(variable);
+ }
+ Group start = auser.getGroup();
+ if (start == null) {
+ return -1.0D;
+ }
+ Group result = nextGroupWithVariable(start, variable);
+ if (result == null) {
+ // Check sub groups
+ if (!auser.isSubGroupsEmpty())
+ for (Group subGroup : auser.subGroupListCopy()) {
+ result = nextGroupWithVariable(subGroup, variable);
+ // Found value?
+ if (result != null)
+ continue;
+ }
+ if (result == null)
+ return -1.0D;
+ }
+ return result.getVariables().getVarDouble(variable);
+ // return getUserPermissionDouble(string, string1);
+ }
+
+ /**
+ * Does not include User's group permission
+ *
+ * @param user
+ * @param permission
+ * @return PermissionCheckResult
+ */
+ public PermissionCheckResult checkUserOnlyPermission(User user, String permission) {
+ user.sortPermissions();
+ PermissionCheckResult result = new PermissionCheckResult();
+ result.askedPermission = permission;
+ result.owner = user;
+ for (String access : user.getPermissionList()) {
+ if (comparePermissionString(access, permission)) {
+ result.accessLevel = access;
+ if (access.startsWith("-")) {
+ result.resultType = PermissionCheckResult.Type.NEGATION;
+ } else if (access.startsWith("+")) {
+ result.resultType = PermissionCheckResult.Type.EXCEPTION;
+ } else {
+ result.resultType = PermissionCheckResult.Type.FOUND;
+ }
+ return result;
+ }
+ }
+ result.resultType = PermissionCheckResult.Type.NOTFOUND;
+ return result;
+ }
+
+ /**
+ * Returns the node responsible for that permission. Does not include User's
+ * group permission.
+ *
+ * @param group
+ * @param permission
+ * @return the node if permission is found. if not found, return null
+ */
+ public PermissionCheckResult checkGroupOnlyPermission(Group group, String permission) {
+ group.sortPermissions();
+ PermissionCheckResult result = new PermissionCheckResult();
+ result.owner = group;
+ result.askedPermission = permission;
+ for (String access : group.getPermissionList()) {
+ if (comparePermissionString(access, permission)) {
+ result.accessLevel = access;
+ if (access.startsWith("-")) {
+ result.resultType = PermissionCheckResult.Type.NEGATION;
+ } else if (access.startsWith("+")) {
+ result.resultType = PermissionCheckResult.Type.EXCEPTION;
+ } else {
+ result.resultType = PermissionCheckResult.Type.FOUND;
+ }
+ return result;
+ }
+ }
+ result.resultType = PermissionCheckResult.Type.NOTFOUND;
+ return result;
+ }
+
+ /**
+ * Check permissions, including it's group and inheritance.
+ *
+ * @param user
+ * @param permission
+ * @return true if permission was found. false if not, or was negated.
+ */
+ public boolean checkUserPermission(User user, String permission) {
+ PermissionCheckResult result = checkFullUserPermission(user, permission);
+ if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
+ return true;
+ }
+ if ((Bukkit.getPlayer(user.getName()) != null) && (Bukkit.getPlayer(user.getName()).hasPermission(permission)))
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Do what checkUserPermission did before. But now returning a
+ * PermissionCheckResult.
+ *
+ * @param user
+ * @param targetPermission
+ * @return PermissionCheckResult
+ */
+ public PermissionCheckResult checkFullUserPermission(User user, String targetPermission) {
+ PermissionCheckResult result = new PermissionCheckResult();
+ result.askedPermission = targetPermission;
+ result.resultType = PermissionCheckResult.Type.NOTFOUND;
+
+ if (user == null || targetPermission == null || targetPermission.isEmpty()) {
+ return result;
+ }
+
+ PermissionCheckResult resultUser = checkUserOnlyPermission(user, targetPermission);
+ if (!resultUser.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ return resultUser;
+ }
+
+ // IT ONLY CHECKS GROUPS PERMISSIONS IF RESULT FOR USER IS NOT FOUND
+ PermissionCheckResult resultGroup = checkGroupPermissionWithInheritance(user.getGroup(), targetPermission);
+ if (!resultGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ return resultGroup;
+ }
+
+ // SUBGROUPS CHECK
+ for (Group subGroup : user.subGroupListCopy()) {
+ PermissionCheckResult resultSubGroup = checkGroupPermissionWithInheritance(subGroup, targetPermission);
+ if (!resultSubGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ return resultSubGroup;
+ }
+ }
+
+ if ((Bukkit.getPlayer(user.getName()) != null) && (Bukkit.getPlayer(user.getName()).hasPermission(targetPermission))) {
+ result.resultType = PermissionCheckResult.Type.FOUND;
+ result.owner = user;
+ return result;
+ }
+
+ // THEN IT RETURNS A NOT FOUND
+ return result;
+ }
+
+ /**
+ * Verifies if a given group has a variable. Including it's inheritance.
+ *
+ * it redirects to the other method now. This one was deprecated, and will
+ * be gone in a future release.
+ *
+ * @param start
+ * @param variable
+ * @param alreadyChecked
+ * @return returns the closest inherited group with the variable.
+ * @deprecated use now nextGroupWithVariable(Group start, String
+ * targetVariable)
+ */
+ @Deprecated
+ public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) {
+ return nextGroupWithVariable(start, variable);
+ }
+
+ /**
+ * Returns the next group, including inheritance, which contains that
+ * variable name.
+ *
+ * It does Breadth-first search
+ *
+ * @param start
+ * the starting group to look for
+ * @param targetVariable
+ * the variable name
+ * @return The group if found. Null if not.
+ */
+ public Group nextGroupWithVariable(Group start, String targetVariable) {
+ if (start == null || targetVariable == null) {
+ return null;
+ }
+ LinkedList<Group> stack = new LinkedList<Group>();
+ ArrayList<Group> alreadyVisited = new ArrayList<Group>();
+ stack.push(start);
+ alreadyVisited.add(start);
+ while (!stack.isEmpty()) {
+ Group now = stack.pop();
+ if (now.getVariables().hasVar(targetVariable)) {
+ return now;
+ }
+ for (String sonName : now.getInherits()) {
+ Group son = ph.getGroup(sonName);
+ if (son != null && !alreadyVisited.contains(son)) {
+ stack.push(son);
+ alreadyVisited.add(son);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Check if given group inherits another group.
+ *
+ * redirected to the other method. this is deprecated now. and will be gone
+ * in the future releases.
+ *
+ * @param start
+ * The group to start the search.
+ * @param askedGroup
+ * Name of the group you're looking for
+ * @param alreadyChecked
+ * groups to ignore(pass null on it, please)
+ * @return true if it inherits the group.
+ * @deprecated prefer using hasGroupInInheritance(Group start, String
+ * askedGroup)
+ */
+ @Deprecated
+ public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) {
+ return hasGroupInInheritance(start, askedGroup);
+ }
+
+ /**
+ * Check if given group inherits another group.
+ *
+ * It does Breadth-first search
+ *
+ * @param start
+ * The group to start the search.
+ * @param askedGroup
+ * Name of the group you're looking for
+ * @return true if it inherits the group.
+ */
+ public boolean hasGroupInInheritance(Group start, String askedGroup) {
+ if (start == null || askedGroup == null) {
+ return false;
+ }
+ LinkedList<Group> stack = new LinkedList<Group>();
+ ArrayList<Group> alreadyVisited = new ArrayList<Group>();
+ stack.push(start);
+ alreadyVisited.add(start);
+ while (!stack.isEmpty()) {
+ Group now = stack.pop();
+ if (now.getName().equalsIgnoreCase(askedGroup)) {
+ return true;
+ }
+ for (String sonName : now.getInherits()) {
+ Group son = ph.getGroup(sonName);
+ if (son != null && !alreadyVisited.contains(son)) {
+ stack.push(son);
+ alreadyVisited.add(son);
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check if the group has given permission. Including it's inheritance
+ *
+ * @param start
+ * @param permission
+ * @param alreadyChecked
+ * @return true if PermissionCheckResult is EXCEPTION or FOUND
+ * @deprecated use the other checkGroupPermissionWithInheritance for
+ * everything
+ */
+ @Deprecated
+ public boolean checkGroupPermissionWithInheritance(Group start, String permission, List<Group> alreadyChecked) {
+ PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
+ if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns the result of permission check. Including inheritance. If found
+ * anything, the PermissionCheckResult that retuns will include the Group
+ * name, and the result type. Result types will be EXCEPTION, NEGATION,
+ * FOUND.
+ *
+ * If returned type NOTFOUND, the owner will be null, and ownerType too.
+ *
+ * It does Breadth-first search
+ *
+ * @param start
+ * @param targetPermission
+ * @return PermissionCheckResult
+ */
+ public PermissionCheckResult checkGroupPermissionWithInheritance(Group start, String targetPermission) {
+ if (start == null || targetPermission == null) {
+ return null;
+ }
+ LinkedList<Group> stack = new LinkedList<Group>();
+ List<Group> alreadyVisited = new ArrayList<Group>();
+ stack.push(start);
+ alreadyVisited.add(start);
+ while (!stack.isEmpty()) {
+ Group now = stack.pop();
+ PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targetPermission);
+ if (!resultNow.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ return resultNow;
+ }
+ for (String sonName : now.getInherits()) {
+ Group son = ph.getGroup(sonName);
+ if (son != null && !alreadyVisited.contains(son)) {
+ stack.push(son);
+ alreadyVisited.add(son);
+ }
+ }
+ }
+ PermissionCheckResult result = new PermissionCheckResult();
+ result.askedPermission = targetPermission;
+ result.resultType = PermissionCheckResult.Type.NOTFOUND;
+ return result;
+ }
+
+ /**
+ * It uses checkGroupPermissionWithInheritance and cast the owner to Group
+ * type if result type was EXCEPTION or FOUND.
+ *
+ * @param start
+ * @param permission
+ * @param alreadyChecked
+ * @return the group that passed on test. null if no group passed.
+ * @deprecated use checkGroupPermissionWithInheritance for everything now.
+ */
+ @Deprecated
+ public Group nextGroupWithPermission(Group start, String permission, List<Group> alreadyChecked) {
+ PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
+ if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
+ return (Group) checkGroupPermissionWithInheritance(start, permission).owner;
+ }
+ return null;
+ }
+
+ /**
+ * Return whole list of names of groups in a inheritance chain. Including a
+ * starting group.
+ *
+ * it now redirects to the other method. but get away from this one, it will
+ * disappear in a future release.
+ *
+ * @param start
+ * @param alreadyChecked
+ * @return the group that passed on test. null if no group passed.
+ * @deprecated use the other method with same name, instead
+ */
+ @Deprecated
+ public ArrayList<String> listAllGroupsInherited(Group start, ArrayList<String> alreadyChecked) {
+ return listAllGroupsInherited(start);
+ }
+
+ /**
+ * Return whole list of names of groups in a inheritance chain. Including a
+ * starting group.
+ *
+ * It does Breadth-first search. So closer groups will appear first in list.
+ *
+ * @param start
+ * @return the group that passed on test. null if no group passed.
+ */
+ public ArrayList<String> listAllGroupsInherited(Group start) {
+ if (start == null) {
+ return null;
+ }
+ LinkedList<Group> stack = new LinkedList<Group>();
+ ArrayList<String> alreadyVisited = new ArrayList<String>();
+ stack.push(start);
+ alreadyVisited.add(start.getName());
+ while (!stack.isEmpty()) {
+ Group now = stack.pop();
+ for (String sonName : now.getInherits()) {
+ Group son = ph.getGroup(sonName);
+ if (son != null && !alreadyVisited.contains(son.getName())) {
+ stack.push(son);
+ alreadyVisited.add(son.getName());
+ }
+ }
+ }
+ return alreadyVisited;
+ }
+
+ /**
+ * Compare a user permission like 'myplugin.*' against a full plugin
+ * permission name, like 'myplugin.dosomething'. As the example above, will
+ * return true.
+ *
+ * Please sort permissions before sending them here. So negative tokens get
+ * priority.
+ *
+ * You must test if it start with negative outside this method. It will only
+ * tell if the nodes are matching or not.
+ *
+ * Every '-' or '+' in the beginning is ignored. It will match only node
+ * names.
+ *
+ * @param userAcessLevel
+ * @param fullPermissionName
+ * @return true if found a matching token. false if not.
+ */
+ public boolean comparePermissionString(String userAcessLevel, String fullPermissionName) {
+ if (userAcessLevel == null || fullPermissionName == null) {
+ return false;
+ }
+ GroupManager.logger.finest("COMPARING " + userAcessLevel + " WITH " + fullPermissionName);
+
+ if (userAcessLevel.startsWith("+")) {
+ userAcessLevel = userAcessLevel.substring(1);
+ } else if (userAcessLevel.startsWith("-")) {
+ userAcessLevel = userAcessLevel.substring(1);
+ }
+
+ if (fullPermissionName.startsWith("+")) {
+ fullPermissionName = fullPermissionName.substring(1);
+ } else if (fullPermissionName.startsWith("-")) {
+ fullPermissionName = fullPermissionName.substring(1);
+ }
+
+ StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, ".");
+ StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, ".");
+ while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) {
+ String levelA = levelATokenizer.nextToken();
+ String levelB = levelBTokenizer.nextToken();
+ GroupManager.logger.finest("ROUND " + levelA + " AGAINST " + levelB);
+ if (levelA.contains("*")) {
+ GroupManager.logger.finest("WIN");
+ return true;
+ }
+ if (levelA.equalsIgnoreCase(levelB)) {
+ if (!levelATokenizer.hasMoreTokens() && !levelBTokenizer.hasMoreTokens()) {
+ GroupManager.logger.finest("WIN");
+ return true;
+ }
+ GroupManager.logger.finest("NEXT");
+ continue;
+ } else {
+ GroupManager.logger.finest("FAIL");
+ return false;
+ }
+
+ }
+ GroupManager.logger.finest("FAIL");
+ return false;
+ }
+
+ /**
+ * Returns a list of all groups.
+ *
+ * Including subgroups.
+ *
+ * @param userName
+ * @return String[] of all group names.
+ */
+ @Override
+ public String[] getGroups(String userName) {
+ ArrayList<String> allGroups = listAllGroupsInherited(ph.getUser(userName).getGroup());
+ for (Group subg : ph.getUser(userName).subGroupListCopy()) {
+ allGroups.addAll(listAllGroupsInherited(subg));
+ }
+
+ String[] arr = new String[allGroups.size()];
+ return allGroups.toArray(arr);
+ }
+
+ /**
+ * A Breadth-first search thru inheritance model.
+ *
+ * Just a model to copy and paste. This will guarantee the closer groups
+ * will be checked first.
+ *
+ * @param start
+ * @param targerPermission
+ * @return
+ */
+ @SuppressWarnings("unused")
+ private Group breadthFirstSearch(Group start, String targerPermission) {
+ if (start == null || targerPermission == null) {
+ return null;
+ }
+ LinkedList<Group> stack = new LinkedList<Group>();
+ ArrayList<Group> alreadyVisited = new ArrayList<Group>();
+ stack.push(start);
+ alreadyVisited.add(start);
+ while (!stack.isEmpty()) {
+ Group now = stack.pop();
+ PermissionCheckResult resultNow = checkGroupOnlyPermission(now, targerPermission);
+ if (resultNow.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || resultNow.resultType.equals(PermissionCheckResult.Type.FOUND)) {
+ return now;
+ }
+ if (resultNow.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ return null;
+ }
+ for (String sonName : now.getInherits()) {
+ Group son = ph.getGroup(sonName);
+ if (son != null && !alreadyVisited.contains(son)) {
+ stack.push(son);
+ alreadyVisited.add(son);
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Group getDefaultGroup() {
+ return ph.getDefaultGroup();
+ }
+
+ @Override
+ public String getInfoString(String entryName, String path, boolean isGroup) {
+ if (isGroup) {
+ Group data = ph.getGroup(entryName);
+ if (data == null) {
+ return null;
+ }
+ return data.getVariables().getVarString(path);
+ } else {
+ User data = ph.getUser(entryName);
+ if (data == null) {
+ return null;
+ }
+ return data.getVariables().getVarString(path);
+ }
+ }
+
+ @Override
+ public int getInfoInteger(String entryName, String path, boolean isGroup) {
+ if (isGroup) {
+ Group data = ph.getGroup(entryName);
+ if (data == null) {
+ return -1;
+ }
+ return data.getVariables().getVarInteger(path);
+ } else {
+ User data = ph.getUser(entryName);
+ if (data == null) {
+ return -1;
+ }
+ return data.getVariables().getVarInteger(path);
+ }
+ }
+
+ @Override
+ public double getInfoDouble(String entryName, String path, boolean isGroup) {
+ if (isGroup) {
+ Group data = ph.getGroup(entryName);
+ if (data == null) {
+ return -1;
+ }
+ return data.getVariables().getVarDouble(path);
+ } else {
+ User data = ph.getUser(entryName);
+ if (data == null) {
+ return -1;
+ }
+ return data.getVariables().getVarDouble(path);
+ }
+
+ }
+
+ @Override
+ public boolean getInfoBoolean(String entryName, String path, boolean isGroup) {
+ if (isGroup) {
+ Group data = ph.getGroup(entryName);
+ if (data == null) {
+ return false;
+ }
+ return data.getVariables().getVarBoolean(path);
+ } else {
+ User data = ph.getUser(entryName);
+ if (data == null) {
+ return false;
+ }
+ return data.getVariables().getVarBoolean(path);
+ }
+ }
+
+ @Override
+ public void addUserInfo(String name, String path, Object data) {
+ ph.getUser(name).getVariables().addVar(path, data);
+ }
+
+ @Override
+ public void removeUserInfo(String name, String path) {
+ ph.getUser(name).getVariables().removeVar(path);
+ }
+
+ @Override
+ public void addGroupInfo(String name, String path, Object data) {
+ ph.getGroup(name).getVariables().addVar(path, data);
+ }
+
+ @Override
+ public void removeGroupInfo(String name, String path) {
+ ph.getGroup(name).getVariables().removeVar(path);
+ }
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
index 9bc38f933..abfb73bfd 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
@@ -187,7 +187,7 @@ public class BukkitPermissions {
* null is empty
*
* @param node
- * @return
+ * @return Map of child permissions
*/
public Map<String, Boolean> getChildren(String node) {
for (Permission permission : registeredPermissions) {
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java
index bdad6f186..c0383c160 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java
@@ -16,6 +16,7 @@ import org.bukkit.entity.Player;
*
* @author Nijikokun
* @author Gabriel Couto
+ * @author ElgarL
*/
public abstract class PermissionsReaderInterface {
@@ -23,7 +24,7 @@ public abstract class PermissionsReaderInterface {
*
* @param player
* @param string
- * @return
+ * @return true if has permission
*/
public abstract boolean has(Player player, String string);
@@ -31,141 +32,141 @@ public abstract class PermissionsReaderInterface {
*
* @param player
* @param string
- * @return
+ * @return true if has permission
*/
public abstract boolean permission(Player player, String string);
/**
*
- * @param string
- * @return
+ * @param userName
+ * @return group name for this player.
*/
- public abstract String getGroup(String string);
+ public abstract String getGroup(String userName);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param groupName
+ * @return true if in group
*/
- public abstract boolean inGroup(String string, String string1);
+ public abstract boolean inGroup(String userName, String groupName);
/**
*
- * @param string
- * @return
+ * @param groupName
+ * @return String of prefix
*/
- public abstract String getGroupPrefix(String string);
+ public abstract String getGroupPrefix(String groupName);
/**
*
- * @param string
- * @return
+ * @param groupName
+ * @return String of suffix
*/
- public abstract String getGroupSuffix(String string);
+ public abstract String getGroupSuffix(String groupName);
/**
*
- * @param string
- * @return
+ * @param groupName
+ * @return true if can build
*/
- public abstract boolean canGroupBuild(String string);
+ public abstract boolean canGroupBuild(String groupName);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param groupName
+ * @param node
+ * @return String value
*/
- public abstract String getGroupPermissionString(String string, String string1);
+ public abstract String getGroupPermissionString(String groupName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param groupName
+ * @param node
+ * @return integer value
*/
- public abstract int getGroupPermissionInteger(String string, String string1);
+ public abstract int getGroupPermissionInteger(String groupName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param groupName
+ * @param node
+ * @return boolean value
*/
- public abstract boolean getGroupPermissionBoolean(String string, String string1);
+ public abstract boolean getGroupPermissionBoolean(String groupName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param groupName
+ * @param node
+ * @return double value
*/
- public abstract double getGroupPermissionDouble(String string, String string1);
+ public abstract double getGroupPermissionDouble(String groupName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return String value
*/
- public abstract String getUserPermissionString(String string, String string1);
+ public abstract String getUserPermissionString(String userName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return integer value
*/
- public abstract int getUserPermissionInteger(String string, String string1);
+ public abstract int getUserPermissionInteger(String userName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return boolean value
*/
- public abstract boolean getUserPermissionBoolean(String string, String string1);
+ public abstract boolean getUserPermissionBoolean(String userName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return double value
*/
- public abstract double getUserPermissionDouble(String string, String string1);
+ public abstract double getUserPermissionDouble(String userName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return String value
*/
- public abstract String getPermissionString(String string, String string1);
+ public abstract String getPermissionString(String userName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return integer value
*/
- public abstract int getPermissionInteger(String string, String string1);
+ public abstract int getPermissionInteger(String userName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return boolean value
*/
- public abstract boolean getPermissionBoolean(String string, String string1);
+ public abstract boolean getPermissionBoolean(String userName, String node);
/**
*
- * @param string
- * @param string1
- * @return
+ * @param userName
+ * @param node
+ * @return double value
*/
- public abstract double getPermissionDouble(String string, String string1);
+ public abstract double getPermissionDouble(String userName, String node);
/////////////////////////////
/**
@@ -173,7 +174,7 @@ public abstract class PermissionsReaderInterface {
* This method is a utility method for chat plugins to get the user's prefix
* without having to look at every one of the user's ancestors.
* Returns an empty string if user has no parent groups.
- * @param world Player's world
+ *
* @param user Player's name
* @return Player's prefix
*/
@@ -184,7 +185,7 @@ public abstract class PermissionsReaderInterface {
* This method is a utility method for chat plugins to get the user's suffix
* without having to look at every one of the user's ancestors.
* Returns an empty string if user has no parent groups.
- * @param world Player's world
+ *
* @param user Player's name
* @return Player's suffix
*/
@@ -215,7 +216,7 @@ public abstract class PermissionsReaderInterface {
* @param entryName
* @param path
* @param isGroup
- * @return
+ * @return -1 if not found
*/
public abstract double getInfoDouble(String entryName, String path, boolean isGroup);
//public abstract double getInfoDouble(String entryName, String path, boolean isGroup, Comparator<Double> comparator);