diff options
author | KHobbits <rob@khobbits.co.uk> | 2011-09-20 13:36:55 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2011-09-20 13:36:55 +0100 |
commit | 1fd5222d40bad99a7f66a44c0b85b761100e2029 (patch) | |
tree | dd1528f5dd275b00afbb041a38d6e04f8a7063c3 /EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions | |
parent | ac1f2badc7680900ed9e42928d6df30dd55cc99b (diff) | |
parent | f2dd51cf573ccf403f687e5a863ba449af77b766 (diff) | |
download | Essentials-1fd5222d40bad99a7f66a44c0b85b761100e2029.tar Essentials-1fd5222d40bad99a7f66a44c0b85b761100e2029.tar.gz Essentials-1fd5222d40bad99a7f66a44c0b85b761100e2029.tar.lz Essentials-1fd5222d40bad99a7f66a44c0b85b761100e2029.tar.xz Essentials-1fd5222d40bad99a7f66a44c0b85b761100e2029.zip |
Merge remote branch 'remotes/ess/groupmanager' into essmaster
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions')
3 files changed, 99 insertions, 10 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index b892e653e..5830f0c88 100755..100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -79,6 +79,76 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { public String getGroup(String userName) { return ph.getUser(userName).getGroup().getName(); } + + /** + * Returns All permissions (including inheritance) of player name. + * @param userName + * @return + */ + @Override + public List<String> getAllPlayersPermissions(String userName) { + + User user = ph.getUser(userName); + List<String> playerPermArray = new ArrayList<String>(user.getPermissionList()); + List<String> playerMainGroupPermArray = new ArrayList<String>(user.getGroup().getPermissionList()); + List<String> subGroupsPermArray = new ArrayList<String>(); + List<String> returnPermArray = new ArrayList<String>(); + + for (String subGroup : user.subGroupListStringCopy()) { + subGroupsPermArray.addAll(ph.getGroup(subGroup).getPermissionList()); + } + + for (String permission : subGroupsPermArray) { + /* + * Add each Negated permission + * unless it's being overridden by a higher permission + */ + if (permission.startsWith("-") + && !playerMainGroupPermArray.contains(permission.substring(1)) + && !playerPermArray.contains(permission.substring(1)) + && !playerMainGroupPermArray.contains("*") + && !playerPermArray.contains("*")) { + if (!returnPermArray.contains(permission)) { + returnPermArray.add(permission); + } + } else + if (!returnPermArray.contains(permission) + && !playerMainGroupPermArray.contains("-"+permission) + && !playerPermArray.contains("-"+permission)) { + returnPermArray.add(permission); + } + } + + for (String permission : playerMainGroupPermArray) { + /* + * Add each Negated permission + * unless it's being overridden by a higher permission + */ + if (permission.startsWith("-") + && !playerPermArray.contains(permission.substring(1)) + && !playerMainGroupPermArray.contains("*") + && !playerPermArray.contains("*")) { + if (!returnPermArray.contains(permission)) { + returnPermArray.add(permission); + } + } else + if (!returnPermArray.contains(permission) + && !playerPermArray.contains("-"+permission)) { + returnPermArray.add(permission); + } + } + + for (String permission : playerPermArray) { + /* + * Add each permission + */ + if (!returnPermArray.contains(permission)) { + returnPermArray.add(permission); + } + } + + return returnPermArray; + } /** * Verify if player is in suck group. diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index fe381c127..b82a8f473 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -16,6 +16,7 @@ package org.anjocaido.groupmanager.permissions;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -24,6 +25,8 @@ import java.util.Set; import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.data.User;
+import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
+import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -40,6 +43,7 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
+import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@@ -113,10 +117,12 @@ public class BukkitPermissions { world = player.getWorld().getName();
}
+ // All permissions registered with Bukkit for this player
PermissionAttachment attachment = this.attachments.get(player);
+
+ OverloadedWorldHolder worldData = GroupManager.getWorldsHolder().getWorldData(world);
- User user = GroupManager.getWorldsHolder().getWorldData(world).getUser(player.getName());
- List<String> permissions = user.getGroup().getPermissionList();
+ User user = worldData.getUser(player.getName());
// clear permissions
for (String permission : attachment.getPermissions().keySet()) {
@@ -124,25 +130,34 @@ public class BukkitPermissions { }
// find matching permissions
+ PermissionCheckResult permissionResult;
+ Boolean value;
for (Permission permission : registeredPermissions) {
- boolean permissionValue = user.getGroup().hasSamePermissionNode(permission.getName());
- attachment.setPermission(permission, permissionValue);
- }
+ permissionResult = worldData.getPermissionsHandler().checkFullUserPermission(user, permission.getName());
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.FOUND))
+ value = true;
+ else
+ value = false;
+
+ attachment.setPermission(permission, value);
+ }
- // all permissions
- for (String permission : permissions) {
- Boolean value = true;
+ // Add any missing permissions for this player (non bukkit plugins)
+ List<String> playerPermArray = new ArrayList<String>(worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName()));
+
+ for (String permission : playerPermArray) {
+ value = true;
if (permission.startsWith("-")) {
permission = permission.substring(1); // cut off -
value = false;
}
-
+
if (!attachment.getPermissions().containsKey(permission)) {
attachment.setPermission(permission, value);
}
}
-
player.recalculatePermissions();
+
/*
// List perms for this player
GroupManager.logger.info("Attachment Permissions:");
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java index ede097ea4..bdad6f186 100755..100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java @@ -3,6 +3,8 @@ package org.anjocaido.groupmanager.permissions; //import java.util.Collection; //import java.util.Map; //import java.util.Set; +import java.util.List; + import org.anjocaido.groupmanager.data.Group; //import org.anjocaido.groupmanager.data.User; import org.bukkit.entity.Player; @@ -229,4 +231,6 @@ public abstract class PermissionsReaderInterface { public abstract void removeGroupInfo(String name, String path); ////////////////////////////// + + public abstract List<String> getAllPlayersPermissions(String userName); } |