diff options
author | ElgarL <ElgarL@palmergames.com> | 2012-04-13 14:40:26 +0100 |
---|---|---|
committer | ElgarL <ElgarL@palmergames.com> | 2012-04-13 14:40:26 +0100 |
commit | a028abe03630c1990105f5dbfef5ba44bf11602d (patch) | |
tree | c63635515b5d9138063b6520a62b06eab4e34a4f /EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions | |
parent | 677534c0b7319691c3139559943b2a5c4e8d2c88 (diff) | |
download | Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar.gz Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar.lz Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.tar.xz Essentials-a028abe03630c1990105f5dbfef5ba44bf11602d.zip |
Update all code formatting to use tabs for indentation.
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions')
3 files changed, 410 insertions, 335 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index b40694bb0..2f64e4d99 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -39,6 +39,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @param holder */ public AnjoPermissionsHandler(WorldDataHolder holder) { + ph = holder; } @@ -51,6 +52,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean has(Player player, String permission) { + return permission(player, permission); } @@ -63,6 +65,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean permission(Player player, String permission) { + return checkUserPermission(ph.getUser(player.getName()).updatePlayer(player), permission); } @@ -74,6 +77,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return true if the player has the permission */ public boolean permission(String playerName, String permission) { + return checkUserPermission(ph.getUser(playerName), permission); } @@ -85,6 +89,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroup(String userName) { + return ph.getUser(userName).getGroup().getName(); } @@ -97,10 +102,11 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public List<String> getAllPlayersPermissions(String userName) { + List<String> perms = new ArrayList<String>(); - + perms.addAll(getAllPlayersPermissions(userName, true)); - + return perms; } @@ -118,33 +124,32 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { // Add the players own permissions. playerPermArray.addAll(populatePerms(ph.getUser(userName).getPermissionList(), includeChildren)); - + ArrayList<String> alreadyProcessed = new ArrayList<String>(); - + // fetch all group permissions for (String group : getGroups(userName)) { // Don't process a group more than once. if (!alreadyProcessed.contains(group)) { alreadyProcessed.add(group); - + Set<String> groupPermArray = new HashSet<String>(); - + if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) { // GlobalGroups groupPermArray = populatePerms(GroupManager.getGlobalGroups().getGroupsPermissions(group), includeChildren); - + } else { // World Groups groupPermArray = populatePerms(ph.getGroup(group).getPermissionList(), includeChildren); } - + // Add all group permissions, unless negated by earlier permissions. for (String perm : groupPermArray) { boolean negated = (perm.startsWith("-")); // Perm doesn't already exists and there is no negation for it // or It's a negated perm where a normal perm doesn't exists (don't allow inheritance to negate higher perms) - if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm)) - || (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm))) + if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm)) || (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm))) playerPermArray.add(perm); } } @@ -154,68 +159,69 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { return playerPermArray; } - - private Set<String> populatePerms (List<String> permsList, boolean includeChildren) { - + + private Set<String> populatePerms(List<String> permsList, boolean includeChildren) { + // Create a new array so it's modifiable. List<String> perms = new ArrayList<String>(permsList); Set<String> permArray = new HashSet<String>(); Boolean allPerms = false; - + // Allow * node to populate ALL permissions to Bukkit. if (perms.contains("*")) { permArray.addAll(GroupManager.BukkitPermissions.getAllRegisteredPermissions(includeChildren)); allPerms = true; perms.remove("*"); } - + for (String perm : perms) { - + + /** + * all permission sets are passed here pre-sorted, alphabetically. + * This means negated nodes will be processed before all permissions + * other than *. + */ + boolean negated = perm.startsWith("-"); + + if (!permArray.contains(perm)) { + permArray.add(perm); + + if ((negated) && (permArray.contains(perm.substring(1)))) + permArray.remove(perm.substring(1)); + /** - * all permission sets are passed here pre-sorted, alphabetically. - * This means negated nodes will be processed before all permissions - * other than *. + * Process child nodes if required, + * or this is a negated node AND we used * to include all + * permissions, + * in which case we need to remove all children of that node. */ - boolean negated = perm.startsWith("-"); - - if (!permArray.contains(perm)) { - permArray.add(perm); - - if ((negated) && (permArray.contains(perm.substring(1)))) - permArray.remove(perm.substring(1)); - - /** - * Process child nodes if required, - * or this is a negated node AND we used * to include all permissions, - * in which case we need to remove all children of that node. - */ - if ((includeChildren) || (negated && allPerms)) { - - Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet<String>()); - - if (children != null) { - if (negated) - if (allPerms) { - - // Remove children of negated nodes - for (String child : children.keySet()) - if (children.get(child)) - if (permArray.contains(child)) - permArray.remove(child); - + if ((includeChildren) || (negated && allPerms)) { + + Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet<String>()); + + if (children != null) { + if (negated) + if (allPerms) { + + // Remove children of negated nodes + for (String child : children.keySet()) + if (children.get(child)) + if (permArray.contains(child)) + permArray.remove(child); + } else { - + // Add child nodes for (String child : children.keySet()) if (children.get(child)) if ((!permArray.contains(child)) && (!permArray.contains("-" + child))) permArray.add(child); } - } } } + } } - + return permArray; } @@ -236,6 +242,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean inGroup(String name, String group) { + if (hasGroupInInheritance(ph.getUser(name).getGroup(), group)) { return true; } @@ -326,6 +333,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroupPrefix(String groupName) { + Group g = ph.getGroup(groupName); if (g == null) { return ""; @@ -341,6 +349,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroupSuffix(String groupName) { + Group g = ph.getGroup(groupName); if (g == null) { return ""; @@ -357,6 +366,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean canGroupBuild(String groupName) { + Group g = ph.getGroup(groupName); if (g == null) { return false; @@ -374,6 +384,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getGroupPermissionString(String groupName, String variable) { + Group start = ph.getGroup(groupName); if (start == null) { return null; @@ -395,6 +406,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public int getGroupPermissionInteger(String groupName, String variable) { + Group start = ph.getGroup(groupName); if (start == null) { return -1; @@ -416,6 +428,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean getGroupPermissionBoolean(String group, String variable) { + Group start = ph.getGroup(group); if (start == null) { return false; @@ -437,6 +450,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public double getGroupPermissionDouble(String group, String variable) { + Group start = ph.getGroup(group); if (start == null) { return -1; @@ -457,6 +471,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getUserPermissionString(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return ""; @@ -473,6 +488,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public int getUserPermissionInteger(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1; @@ -489,6 +505,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean getUserPermissionBoolean(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return false; @@ -505,6 +522,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public double getUserPermissionDouble(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1; @@ -523,6 +541,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public String getPermissionString(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return ""; @@ -562,6 +581,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public int getPermissionInteger(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1; @@ -601,6 +621,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public boolean getPermissionBoolean(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return false; @@ -640,6 +661,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Override public double getPermissionDouble(String user, String variable) { + User auser = ph.getUser(user); if (auser == null) { return -1.0D; @@ -676,6 +698,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult */ public PermissionCheckResult checkUserOnlyPermission(User user, String permission) { + user.sortPermissions(); PermissionCheckResult result = new PermissionCheckResult(); result.askedPermission = permission; @@ -699,6 +722,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @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; @@ -721,6 +745,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return true if permission was found. false if not, or was negated. */ public boolean checkUserPermission(User user, String permission) { + PermissionCheckResult result = checkFullGMPermission(user, permission, true); if (result.resultType == PermissionCheckResult.Type.EXCEPTION || result.resultType == PermissionCheckResult.Type.FOUND) { return true; @@ -752,6 +777,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult */ public PermissionCheckResult checkFullGMPermission(User user, String targetPermission, Boolean checkBukkit) { + PermissionCheckResult result = new PermissionCheckResult(); result.accessLevel = targetPermission; result.resultType = PermissionCheckResult.Type.NOTFOUND; @@ -813,6 +839,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) { + return nextGroupWithVariable(start, variable); } @@ -829,6 +856,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return The group if found. Null if not. */ public Group nextGroupWithVariable(Group start, String targetVariable) { + if (start == null || targetVariable == null) { return null; } @@ -870,6 +898,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) { + return hasGroupInInheritance(start, askedGroup); } @@ -885,6 +914,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return true if it inherits the group. */ public boolean hasGroupInInheritance(Group start, String askedGroup) { + if (start == null || askedGroup == null) { return false; } @@ -920,6 +950,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @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; @@ -942,6 +973,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult */ public PermissionCheckResult checkGroupPermissionWithInheritance(Group start, String targetPermission) { + if (start == null || targetPermission == null) { return null; } @@ -982,6 +1014,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @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; @@ -1003,6 +1036,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @Deprecated public ArrayList<String> listAllGroupsInherited(Group start, ArrayList<String> alreadyChecked) { + return listAllGroupsInherited(start); } @@ -1016,6 +1050,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return the group that passed on test. null if no group passed. */ public ArrayList<String> listAllGroupsInherited(Group start) { + if (start == null) { return null; } @@ -1055,6 +1090,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { * @return PermissionCheckResult.Type */ public PermissionCheckResult.Type comparePermissionString(String userAccessLevel, String fullPermissionName) { + int userAccessLevelLength; if (userAccessLevel == null || fullPermissionName == null || fullPermissionName.length() == 0 || (userAccessLevelLength = userAccessLevel.length()) == 0) { return PermissionCheckResult.Type.NOTFOUND; @@ -1080,12 +1116,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { } if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') { - return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ? - result : PermissionCheckResult.Type.NOTFOUND; + return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ? result : PermissionCheckResult.Type.NOTFOUND; } else { - return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, - Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ? - result : PermissionCheckResult.Type.NOTFOUND; + return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ? result : PermissionCheckResult.Type.NOTFOUND; } } @@ -1099,6 +1132,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @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)); @@ -1120,6 +1154,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { */ @SuppressWarnings("unused") private Group breadthFirstSearch(Group start, String targerPermission) { + if (start == null || targerPermission == null) { return null; } @@ -1149,11 +1184,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @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) { @@ -1171,6 +1208,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public int getInfoInteger(String entryName, String path, boolean isGroup) { + if (isGroup) { Group data = ph.getGroup(entryName); if (data == null) { @@ -1188,6 +1226,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public double getInfoDouble(String entryName, String path, boolean isGroup) { + if (isGroup) { Group data = ph.getGroup(entryName); if (data == null) { @@ -1206,6 +1245,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @Override public boolean getInfoBoolean(String entryName, String path, boolean isGroup) { + if (isGroup) { Group data = ph.getGroup(entryName); if (data == null) { @@ -1223,21 +1263,25 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { @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 516679544..c366b65bf 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -1,18 +1,19 @@ /*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
package org.anjocaido.groupmanager.permissions;
@@ -47,7 +48,6 @@ import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.PluginManager;
-
/**
*
* BukkitPermissions overrides to force GM reponses to Superperms
@@ -62,11 +62,12 @@ public class BukkitPermissions { protected boolean dumpAllPermissions = true;
protected boolean dumpMatchedPermissions = true;
private boolean player_join = false;
-
+
/**
* @return the player_join
*/
public boolean isPlayer_join() {
+
return player_join;
}
@@ -74,6 +75,7 @@ public class BukkitPermissions { * @param player_join the player_join to set
*/
public void setPlayer_join(boolean player_join) {
+
this.player_join = player_join;
}
@@ -92,6 +94,7 @@ public class BukkitPermissions { }
public BukkitPermissions(GroupManager plugin) {
+
this.plugin = plugin;
this.collectPermissions();
this.registerEvents();
@@ -101,35 +104,38 @@ public class BukkitPermissions { }
private void registerEvents() {
+
PluginManager manager = plugin.getServer().getPluginManager();
manager.registerEvents(new PlayerEvents(), plugin);
manager.registerEvents(new BukkitEvents(), plugin);
}
-
public void collectPermissions() {
+
registeredPermissions.clear();
for (Permission perm : Bukkit.getPluginManager().getPermissions()) {
- registeredPermissions.put(perm.getName().toLowerCase(), perm);
+ registeredPermissions.put(perm.getName().toLowerCase(), perm);
}
-
+
}
public void updatePermissions(Player player) {
+
this.updatePermissions(player, null);
}
-
/**
- * Push all permissions which are registered with GM for this player, on this world to Bukkit
+ * Push all permissions which are registered with GM for this player, on
+ * this world to Bukkit
* and make it update for the child nodes.
*
* @param player
* @param world
*/
public void updatePermissions(Player player, String world) {
+
if (player == null || !GroupManager.isLoaded()) {
return;
}
@@ -155,17 +161,18 @@ public class BukkitPermissions { // Sort the perm list by parent/child, so it will push to superperms correctly.
playerPermArray = sort(playerPermArray);
-
+
Boolean value = false;
- for (String permission : playerPermArray) {
+ for (String permission : playerPermArray) {
value = (!permission.startsWith("-"));
- newPerms.put((value? permission : permission.substring(1)), value);
+ newPerms.put((value ? permission : permission.substring(1)), value);
}
/**
- * This is put in place until such a time as Bukkit pull 466 is implemented
- * https://github.com/Bukkit/Bukkit/pull/466
- */
+ * This is put in place until such a time as Bukkit pull 466 is
+ * implemented
+ * https://github.com/Bukkit/Bukkit/pull/466
+ */
try { // Codename_B source
@SuppressWarnings("unchecked")
Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(attachment);
@@ -182,7 +189,7 @@ public class BukkitPermissions { e.printStackTrace();
}
}
-
+
/**
* Sort a permission node list by parent/child
*
@@ -190,20 +197,20 @@ public class BukkitPermissions { * @return List sorted for priority
*/
private List<String> sort(List<String> permList) {
-
+
List<String> result = new ArrayList<String>();
-
+
for (String key : permList) {
- String a = key.charAt(0) == '-'? key.substring(1):key;
+ String a = key.charAt(0) == '-' ? key.substring(1) : key;
Map<String, Boolean> allchildren = GroupManager.BukkitPermissions.getAllChildren(a, new HashSet<String>());
if (allchildren != null) {
ListIterator<String> itr = result.listIterator();
-
- while (itr.hasNext()){
+
+ while (itr.hasNext()) {
String node = (String) itr.next();
- String b = node.charAt(0) == '-'? node.substring(1):node;
-
+ String b = node.charAt(0) == '-' ? node.substring(1) : node;
+
// Insert the parent node before the child
if (allchildren.containsKey(b)) {
itr.set(key);
@@ -215,11 +222,10 @@ public class BukkitPermissions { if (!result.contains(key))
result.add(key);
}
-
+
return result;
}
-
/**
* Fetch all permissions which are registered with superperms.
* {can include child nodes)
@@ -228,13 +234,13 @@ public class BukkitPermissions { * @return List of all permission nodes
*/
public List<String> getAllRegisteredPermissions(boolean includeChildren) {
-
+
List<String> perms = new ArrayList<String>();
-
+
for (String key : registeredPermissions.keySet()) {
if (!perms.contains(key)) {
perms.add(key);
-
+
if (includeChildren) {
Map<String, Boolean> children = getAllChildren(key, new HashSet<String>());
if (children != null) {
@@ -244,32 +250,33 @@ public class BukkitPermissions { }
}
}
-
+
}
return perms;
}
-
+
/**
* Returns a map of ALL child permissions registered with bukkit
* null is empty
*
* @param node
- * @param playerPermArray current list of perms to check against for negations
+ * @param playerPermArray current list of perms to check against for
+ * negations
* @return Map of child permissions
*/
public Map<String, Boolean> getAllChildren(String node, Set<String> playerPermArray) {
-
+
LinkedList<String> stack = new LinkedList<String>();
Map<String, Boolean> alreadyVisited = new HashMap<String, Boolean>();
stack.push(node);
alreadyVisited.put(node, true);
-
+
while (!stack.isEmpty()) {
String now = stack.pop();
-
+
Map<String, Boolean> children = getChildren(now);
-
- if ((children != null) && (!playerPermArray.contains("-"+now))) {
+
+ if ((children != null) && (!playerPermArray.contains("-" + now))) {
for (String childName : children.keySet()) {
if (!alreadyVisited.containsKey(childName)) {
stack.push(childName);
@@ -279,24 +286,26 @@ public class BukkitPermissions { }
}
alreadyVisited.remove(node);
- if (!alreadyVisited.isEmpty()) return alreadyVisited;
-
+ if (!alreadyVisited.isEmpty())
+ return alreadyVisited;
+
return null;
}
-
+
/**
- * Returns a map of the child permissions (1 node deep) as registered with Bukkit.
+ * Returns a map of the child permissions (1 node deep) as registered with
+ * Bukkit.
* null is empty
*
* @param node
* @return Map of child permissions
*/
public Map<String, Boolean> getChildren(String node) {
-
+
Permission perm = registeredPermissions.get(node.toLowerCase());
if (perm == null)
return null;
-
+
return perm.getChildren();
}
@@ -308,6 +317,7 @@ public class BukkitPermissions { * @return List<String> of permissions
*/
public List<String> listPerms(Player player) {
+
List<String> perms = new ArrayList<String>();
/*
@@ -332,25 +342,28 @@ public class BukkitPermissions { * force Bukkit to update every OnlinePlayers permissions.
*/
public void updateAllPlayers() {
+
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
updatePermissions(player);
}
}
-
+
/**
* force Bukkit to update this Players permissions.
*/
public void updatePlayer(Player player) {
+
if (player != null)
this.updatePermissions(player, null);
}
-
+
/**
* Force remove any attachments
*
* @param player
*/
private void removeAttachment(Player player) {
+
if (attachments.containsKey(player)) {
try {
player.removeAttachment(attachments.get(player));
@@ -363,15 +376,15 @@ public class BukkitPermissions { attachments.remove(player);
}
}
-
+
/**
* Remove all attachments in case of a restart or reload.
*/
public void removeAllAttachments() {
-
+
Iterator<Player> itr = attachments.keySet().iterator();
-
- while (itr.hasNext()){
+
+ while (itr.hasNext()) {
Player player = itr.next();
try {
player.removeAttachment(attachments.get(player));
@@ -389,20 +402,21 @@ public class BukkitPermissions { * Player events tracked to cause Superperms updates
*
* @author ElgarL
- *
+ *
*/
protected class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) {
+
setPlayer_join(true);
Player player = event.getPlayer();
-
+
/*
* Tidy up any lose ends
*/
removeAttachment(player);
-
+
// force GM to create the player if they are not already listed.
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
setPlayer_join(false);
@@ -410,29 +424,32 @@ public class BukkitPermissions { }
setPlayer_join(false);
}
-
+
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) { // has changed worlds
+
updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName());
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerKick(PlayerKickEvent event) {
+
Player player = event.getPlayer();
-
+
/*
* force remove any attachments as bukkit may not
*/
removeAttachment(player);
}
-
+
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerQuit(PlayerQuitEvent event) {
+
if (!GroupManager.isLoaded())
return;
Player player = event.getPlayer();
-
+
/*
* force remove any attachments as bukkit may not
*/
@@ -444,6 +461,7 @@ public class BukkitPermissions { @EventHandler(priority = EventPriority.NORMAL)
public void onPluginEnable(PluginEnableEvent event) {
+
if (!GroupManager.isLoaded())
return;
@@ -453,6 +471,7 @@ public class BukkitPermissions { @EventHandler(priority = EventPriority.NORMAL)
public void onPluginDisable(PluginDisableEvent event) {
+
collectPermissions();
// updateAllPlayers();
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java index 3f49757e2..69f098949 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java @@ -12,227 +12,239 @@ import org.bukkit.entity.Player; /** * Made by Nijikokun. Changed by Gabriel Couto - * + * * This class is intended to *read* permissions from a single world. - * + * * @author Nijikokun * @author Gabriel Couto * @author ElgarL */ public abstract class PermissionsReaderInterface { - /** - * - * @param player - * @param string - * @return true if has permission - */ - public abstract boolean has(Player player, String string); - - /** - * - * @param player - * @param string - * @return true if has permission - */ - public abstract boolean permission(Player player, String string); - - /** - * - * @param userName - * @return group name for this player. - */ - public abstract String getGroup(String userName); - - /** - * - * @param userName - * @param groupName - * @return true if in group - */ - public abstract boolean inGroup(String userName, String groupName); - - /** - * - * @param groupName - * @return String of prefix - */ - public abstract String getGroupPrefix(String groupName); - - /** - * - * @param groupName - * @return String of suffix - */ - public abstract String getGroupSuffix(String groupName); - - /** - * - * @param groupName - * @return true if can build - */ - public abstract boolean canGroupBuild(String groupName); - - /** - * - * @param groupName - * @param node - * @return String value - */ - public abstract String getGroupPermissionString(String groupName, String node); - - /** - * - * @param groupName - * @param node - * @return integer value - */ - public abstract int getGroupPermissionInteger(String groupName, String node); - - /** - * - * @param groupName - * @param node - * @return boolean value - */ - public abstract boolean getGroupPermissionBoolean(String groupName, String node); - - /** - * - * @param groupName - * @param node - * @return double value - */ - public abstract double getGroupPermissionDouble(String groupName, String node); - - /** - * - * @param userName - * @param node - * @return String value - */ - public abstract String getUserPermissionString(String userName, String node); - - /** - * - * @param userName - * @param node - * @return integer value - */ - public abstract int getUserPermissionInteger(String userName, String node); - - /** - * - * @param userName - * @param node - * @return boolean value - */ - public abstract boolean getUserPermissionBoolean(String userName, String node); - - /** - * - * @param userName - * @param node - * @return double value - */ - public abstract double getUserPermissionDouble(String userName, String node); - - /** - * - * @param userName - * @param node - * @return String value - */ - public abstract String getPermissionString(String userName, String node); - - /** - * - * @param userName - * @param node - * @return integer value - */ - public abstract int getPermissionInteger(String userName, String node); - - /** - * - * @param userName - * @param node - * @return boolean value - */ - public abstract boolean getPermissionBoolean(String userName, String node); - - /** - * - * @param userName - * @param node - * @return double value - */ - public abstract double getPermissionDouble(String userName, String node); - -///////////////////////////// - /** - * 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 - */ - public abstract String getUserPrefix(String user); - - /** - * Gets the appropriate suffix for the user. - * 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 user Player's name - * @return Player's suffix - */ - public abstract String getUserSuffix(String user); - - /** - * Returns the group object representing the default group of the given world. - * This method will return null if the object does not exist or the world has no default group. - * @return Group object representing default world, or null if it doesn't exist or is not defined. - */ - public abstract Group getDefaultGroup(); - - /** - * Gets a array of the names of all parent groups in the same world. - * @param name Target user's name - * @return An array containing the names of all parent groups (including ancestors) that are in the same world - */ - public abstract String[] getGroups(String name); - - public abstract String getInfoString(String entryName, String path, boolean isGroup); - //public abstract String getInfoString(String entryName, String path, boolean isGroup, Comparator<String> comparator); - - public abstract int getInfoInteger(String entryName, String path, boolean isGroup); - //public abstract int getInfoInteger(String entryName, String path, boolean isGroup, Comparator<Integer> comparator); - - /** - * Gets a double from the Info node without inheritance. - * @param entryName - * @param path - * @param isGroup - * @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); - - public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup); - //public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup, Comparator<Boolean> comparator); - - public abstract void addUserInfo(String name, String path, Object data); - - public abstract void removeUserInfo(String name, String path); - - public abstract void addGroupInfo(String name, String path, Object data); - - public abstract void removeGroupInfo(String name, String path); -////////////////////////////// + /** + * + * @param player + * @param string + * @return true if has permission + */ + public abstract boolean has(Player player, String string); + + /** + * + * @param player + * @param string + * @return true if has permission + */ + public abstract boolean permission(Player player, String string); + + /** + * + * @param userName + * @return group name for this player. + */ + public abstract String getGroup(String userName); + + /** + * + * @param userName + * @param groupName + * @return true if in group + */ + public abstract boolean inGroup(String userName, String groupName); + + /** + * + * @param groupName + * @return String of prefix + */ + public abstract String getGroupPrefix(String groupName); + + /** + * + * @param groupName + * @return String of suffix + */ + public abstract String getGroupSuffix(String groupName); + + /** + * + * @param groupName + * @return true if can build + */ + public abstract boolean canGroupBuild(String groupName); + + /** + * + * @param groupName + * @param node + * @return String value + */ + public abstract String getGroupPermissionString(String groupName, String node); + + /** + * + * @param groupName + * @param node + * @return integer value + */ + public abstract int getGroupPermissionInteger(String groupName, String node); + + /** + * + * @param groupName + * @param node + * @return boolean value + */ + public abstract boolean getGroupPermissionBoolean(String groupName, String node); + + /** + * + * @param groupName + * @param node + * @return double value + */ + public abstract double getGroupPermissionDouble(String groupName, String node); + + /** + * + * @param userName + * @param node + * @return String value + */ + public abstract String getUserPermissionString(String userName, String node); + + /** + * + * @param userName + * @param node + * @return integer value + */ + public abstract int getUserPermissionInteger(String userName, String node); + + /** + * + * @param userName + * @param node + * @return boolean value + */ + public abstract boolean getUserPermissionBoolean(String userName, String node); + + /** + * + * @param userName + * @param node + * @return double value + */ + public abstract double getUserPermissionDouble(String userName, String node); + + /** + * + * @param userName + * @param node + * @return String value + */ + public abstract String getPermissionString(String userName, String node); + + /** + * + * @param userName + * @param node + * @return integer value + */ + public abstract int getPermissionInteger(String userName, String node); + + /** + * + * @param userName + * @param node + * @return boolean value + */ + public abstract boolean getPermissionBoolean(String userName, String node); + + /** + * + * @param userName + * @param node + * @return double value + */ + public abstract double getPermissionDouble(String userName, String node); + + ///////////////////////////// + /** + * 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 + */ + public abstract String getUserPrefix(String user); + + /** + * Gets the appropriate suffix for the user. + * 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 user Player's name + * @return Player's suffix + */ + public abstract String getUserSuffix(String user); + + /** + * Returns the group object representing the default group of the given + * world. + * This method will return null if the object does not exist or the world + * has no default group. + * + * @return Group object representing default world, or null if it doesn't + * exist or is not defined. + */ + public abstract Group getDefaultGroup(); + + /** + * Gets a array of the names of all parent groups in the same world. + * + * @param name Target user's name + * @return An array containing the names of all parent groups (including + * ancestors) that are in the same world + */ + public abstract String[] getGroups(String name); + + public abstract String getInfoString(String entryName, String path, boolean isGroup); + + //public abstract String getInfoString(String entryName, String path, boolean isGroup, Comparator<String> comparator); + + public abstract int getInfoInteger(String entryName, String path, boolean isGroup); + + //public abstract int getInfoInteger(String entryName, String path, boolean isGroup, Comparator<Integer> comparator); + + /** + * Gets a double from the Info node without inheritance. + * + * @param entryName + * @param path + * @param isGroup + * @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); + + public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup); + + //public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup, Comparator<Boolean> comparator); + + public abstract void addUserInfo(String name, String path, Object data); + + public abstract void removeUserInfo(String name, String path); + + public abstract void addGroupInfo(String name, String path, Object data); + + public abstract void removeGroupInfo(String name, String path); + + ////////////////////////////// public abstract List<String> getAllPlayersPermissions(String userName); |