mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Fix superperms to pass all tests
http://dev.bukkit.org/server-mods/superpermstest/
This commit is contained in:
parent
cd8ef9361b
commit
24a6073488
3 changed files with 312 additions and 231 deletions
|
@ -77,3 +77,4 @@ v 1.6:
|
||||||
- Prevent Group.equals tests throwing a NullPointerException for GlobalGroups.
|
- Prevent Group.equals tests throwing a NullPointerException for GlobalGroups.
|
||||||
- Stop throwing errors on an empty users file.
|
- Stop throwing errors on an empty users file.
|
||||||
- Optimize sorting to speedup permission tests.
|
- Optimize sorting to speedup permission tests.
|
||||||
|
- Fix superperms to pass all tests http://dev.bukkit.org/server-mods/superpermstest/
|
|
@ -97,43 +97,59 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllPlayersPermissions(String userName) {
|
public List<String> getAllPlayersPermissions(String userName) {
|
||||||
|
|
||||||
List<String> playerPermArray = new ArrayList<String>(ph.getUser(userName).getPermissionList());
|
List<String> playerPermArray = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (String perm : ph.getUser(userName).getPermissionList()) {
|
||||||
|
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
||||||
|
playerPermArray.add(perm);
|
||||||
|
|
||||||
|
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
|
||||||
|
|
||||||
|
if (children != null) {
|
||||||
|
for (String child : children.keySet()) {
|
||||||
|
if (children.get(child))
|
||||||
|
if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
|
||||||
|
playerPermArray.add(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (String group : getGroups(userName)) {
|
for (String group : getGroups(userName)) {
|
||||||
if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) {
|
if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) {
|
||||||
for (String perm : GroupManager.getGlobalGroups().getGroupsPermissions(group)) {
|
for (String perm : GroupManager.getGlobalGroups().getGroupsPermissions(group)) {
|
||||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
||||||
playerPermArray.add(perm);
|
playerPermArray.add(perm);
|
||||||
|
|
||||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
|
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
for (String child : children.keySet()) {
|
for (String child : children.keySet()) {
|
||||||
if (children.get(child))
|
if (children.get(child))
|
||||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm)))
|
if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child)))
|
||||||
playerPermArray.add(child);
|
playerPermArray.add(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for (String perm : ph.getGroup(group).getPermissionList()) {
|
for (String perm : ph.getGroup(group).getPermissionList()) {
|
||||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
||||||
playerPermArray.add(perm);
|
playerPermArray.add(perm);
|
||||||
|
|
||||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
|
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
for (String child : children.keySet()) {
|
for (String child : children.keySet()) {
|
||||||
if (children.get(child))
|
if (children.get(child))
|
||||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm)))
|
if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
|
||||||
playerPermArray.add(child);
|
playerPermArray.add(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//Collections.sort(playerPermArray, StringPermissionComparator.getInstance());
|
||||||
|
|
||||||
return playerPermArray;
|
return playerPermArray;
|
||||||
}
|
}
|
||||||
|
@ -670,8 +686,22 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||||
* @return PermissionCheckResult
|
* @return PermissionCheckResult
|
||||||
*/
|
*/
|
||||||
public PermissionCheckResult checkFullUserPermission(User user, String targetPermission) {
|
public PermissionCheckResult checkFullUserPermission(User user, String targetPermission) {
|
||||||
|
|
||||||
|
return checkFullGMPermission(user, targetPermission, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check user and groups with inheritance and Bukkit if bukkit = true
|
||||||
|
* return a PermissionCheckResult.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* @param targetPermission
|
||||||
|
* @param checkBukkit
|
||||||
|
* @return PermissionCheckResult
|
||||||
|
*/
|
||||||
|
public PermissionCheckResult checkFullGMPermission(User user, String targetPermission, Boolean checkBukkit) {
|
||||||
PermissionCheckResult result = new PermissionCheckResult();
|
PermissionCheckResult result = new PermissionCheckResult();
|
||||||
result.askedPermission = targetPermission;
|
result.accessLevel = targetPermission;
|
||||||
result.resultType = PermissionCheckResult.Type.NOTFOUND;
|
result.resultType = PermissionCheckResult.Type.NOTFOUND;
|
||||||
|
|
||||||
if (user == null || targetPermission == null || targetPermission.isEmpty()) {
|
if (user == null || targetPermission == null || targetPermission.isEmpty()) {
|
||||||
|
@ -697,6 +727,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkBukkit == true) {
|
||||||
// Check Bukkit perms to support plugins which add perms via code (Heroes).
|
// Check Bukkit perms to support plugins which add perms via code (Heroes).
|
||||||
final Player player = Bukkit.getPlayer(user.getName());
|
final Player player = Bukkit.getPlayer(user.getName());
|
||||||
if ((player != null) && (player.hasPermission(targetPermission))) {
|
if ((player != null) && (player.hasPermission(targetPermission))) {
|
||||||
|
@ -704,6 +735,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||||
result.owner = user;
|
result.owner = user;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// THEN IT RETURNS A NOT FOUND
|
// THEN IT RETURNS A NOT FOUND
|
||||||
return result;
|
return result;
|
||||||
|
@ -960,7 +992,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||||
* Every '-' or '+' in the beginning is ignored. It will match only node
|
* Every '-' or '+' in the beginning is ignored. It will match only node
|
||||||
* names.
|
* names.
|
||||||
*
|
*
|
||||||
* @param userAcessLevel
|
* @param userAccessLevel
|
||||||
* @param fullPermissionName
|
* @param fullPermissionName
|
||||||
* @return true if found a matching token. false if not.
|
* @return true if found a matching token. false if not.
|
||||||
*/
|
*/
|
||||||
|
@ -986,9 +1018,11 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
|
if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
|
||||||
userAccessLevelLength--;
|
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1);
|
||||||
|
} else {
|
||||||
|
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset,
|
||||||
|
Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset));
|
||||||
}
|
}
|
||||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,14 @@ package org.anjocaido.groupmanager.permissions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.anjocaido.groupmanager.GroupManager;
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
import org.anjocaido.groupmanager.data.User;
|
import org.anjocaido.groupmanager.data.User;
|
||||||
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
|
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
|
||||||
|
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -57,7 +57,7 @@ import org.bukkit.plugin.PluginManager;
|
||||||
public class BukkitPermissions {
|
public class BukkitPermissions {
|
||||||
|
|
||||||
protected Map<Player, PermissionAttachment> attachments = new HashMap<Player, PermissionAttachment>();
|
protected Map<Player, PermissionAttachment> attachments = new HashMap<Player, PermissionAttachment>();
|
||||||
protected Set<Permission> registeredPermissions = new HashSet<Permission>();
|
protected LinkedList<Permission> registeredPermissions = new LinkedList<Permission>();
|
||||||
protected GroupManager plugin;
|
protected GroupManager plugin;
|
||||||
protected boolean dumpAllPermissions = true;
|
protected boolean dumpAllPermissions = true;
|
||||||
protected boolean dumpMatchedPermissions = true;
|
protected boolean dumpMatchedPermissions = true;
|
||||||
|
@ -96,12 +96,12 @@ public class BukkitPermissions {
|
||||||
public void collectPermissions() {
|
public void collectPermissions() {
|
||||||
registeredPermissions.clear();
|
registeredPermissions.clear();
|
||||||
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
|
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
|
||||||
for(Permission permission : bukkitPlugin.getDescription().getPermissions())
|
for (Permission permission : bukkitPlugin.getDescription().getPermissions())
|
||||||
registeredPermissions.add(permission);
|
registeredPermissions.push(permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePermissions(Player player){
|
public void updatePermissions(Player player) {
|
||||||
this.updatePermissions(player, null);
|
this.updatePermissions(player, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ public class BukkitPermissions {
|
||||||
this.attachments.put(player, player.addAttachment(plugin));
|
this.attachments.put(player, player.addAttachment(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
world = player.getWorld().getName();
|
world = player.getWorld().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,41 +132,53 @@ public class BukkitPermissions {
|
||||||
/*
|
/*
|
||||||
* find matching permissions
|
* find matching permissions
|
||||||
*
|
*
|
||||||
* and base bukkit perms if we are set to allow bukkit permissions to override.
|
* and base bukkit perms if we are set to allow bukkit permissions to
|
||||||
|
* override.
|
||||||
*/
|
*/
|
||||||
Boolean value;
|
Boolean value = false;
|
||||||
|
|
||||||
for (Permission permission : registeredPermissions) {
|
for (Permission permission : registeredPermissions) {
|
||||||
|
|
||||||
value = worldData.getPermissionsHandler().checkUserPermission(user, permission.getName());
|
PermissionCheckResult result = worldData.getPermissionsHandler().checkFullGMPermission(user, permission.getName(), false);
|
||||||
|
|
||||||
// Only check bukkit override IF we don't have the permission directly.
|
// Only check bukkit override IF we don't have the permission
|
||||||
if (value = false) {
|
// directly.
|
||||||
|
if (result.resultType == PermissionCheckResult.Type.NOTFOUND) {
|
||||||
PermissionDefault permDefault = permission.getDefault();
|
PermissionDefault permDefault = permission.getDefault();
|
||||||
|
|
||||||
if ((plugin.getGMConfig().isBukkitPermsOverride())
|
if ((plugin.getGMConfig().isBukkitPermsOverride()) && ((permDefault == PermissionDefault.TRUE)
|
||||||
&& ((permDefault == PermissionDefault.TRUE)
|
|
||||||
|| ((permDefault == PermissionDefault.NOT_OP) && !player.isOp())
|
|| ((permDefault == PermissionDefault.NOT_OP) && !player.isOp())
|
||||||
|| ((permDefault == PermissionDefault.OP) && player.isOp())))
|
|| ((permDefault == PermissionDefault.OP) && player.isOp()))) {
|
||||||
|
value = true;
|
||||||
|
} else {
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
} else if (result.resultType == PermissionCheckResult.Type.NEGATION) {
|
||||||
|
value = false;
|
||||||
|
} else {
|
||||||
value = true;
|
value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == true){
|
|
||||||
// Set the root permission
|
// Set the root permission
|
||||||
|
if ((value == true) || (result.resultType == PermissionCheckResult.Type.NEGATION)) {
|
||||||
attachment.setPermission(permission, value);
|
attachment.setPermission(permission, value);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if ((value == true) || (result.resultType == PermissionCheckResult.Type.NOTFOUND)) {
|
||||||
// fetch and set all children of this permission node
|
// fetch and set all children of this permission node
|
||||||
Map<String, Boolean> children = permission.getChildren();
|
Map<String, Boolean> children = permission.getChildren();
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
for (String child : children.keySet()) {
|
for (String child : children.keySet()) {
|
||||||
if (children.get(child))
|
if (children.get(child))
|
||||||
attachment.setPermission(child, true);
|
attachment.setPermission(child, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Add any missing permissions for this player (non bukkit plugins)
|
// Add any missing permissions for this player (non bukkit plugins and child nodes)
|
||||||
List<String> playerPermArray = new ArrayList<String>(worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName()));
|
List<String> playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName());
|
||||||
|
|
||||||
for (String permission : playerPermArray) {
|
for (String permission : playerPermArray) {
|
||||||
value = true;
|
value = true;
|
||||||
|
@ -183,7 +195,41 @@ public class BukkitPermissions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a map of the child permissions as defined by the supplying plugin
|
* Returns a map of the ALL child permissions as defined by the supplying plugin
|
||||||
|
* null is empty
|
||||||
|
*
|
||||||
|
* @param node
|
||||||
|
* @return Map of child permissions
|
||||||
|
*/
|
||||||
|
public Map<String, Boolean> getAllChildren(String node, List<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))) {
|
||||||
|
for (String childName : children.keySet()) {
|
||||||
|
if (!alreadyVisited.containsKey(childName)) {
|
||||||
|
stack.push(childName);
|
||||||
|
alreadyVisited.put(childName, children.get(childName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alreadyVisited.remove(node);
|
||||||
|
if (!alreadyVisited.isEmpty()) return alreadyVisited;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a map of the child permissions (1 node deep) as defined by the supplying plugin
|
||||||
* null is empty
|
* null is empty
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
|
@ -191,10 +237,11 @@ public class BukkitPermissions {
|
||||||
*/
|
*/
|
||||||
public Map<String, Boolean> getChildren(String node) {
|
public Map<String, Boolean> getChildren(String node) {
|
||||||
for (Permission permission : registeredPermissions) {
|
for (Permission permission : registeredPermissions) {
|
||||||
if (permission.getName() == node) {
|
if (permission.getName().equalsIgnoreCase(node)) {
|
||||||
return permission.getChildren();
|
return permission.getChildren();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,18 +249,17 @@ public class BukkitPermissions {
|
||||||
List<String> perms = new ArrayList<String>();
|
List<String> perms = new ArrayList<String>();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// All permissions registered with Bukkit for this player
|
* // All permissions registered with Bukkit for this player
|
||||||
PermissionAttachment attachment = this.attachments.get(player);
|
* PermissionAttachment attachment = this.attachments.get(player);
|
||||||
|
*
|
||||||
// List perms for this player
|
* // List perms for this player perms.add("Attachment Permissions:");
|
||||||
perms.add("Attachment Permissions:");
|
* for(Map.Entry<String, Boolean> entry :
|
||||||
for(Map.Entry<String, Boolean> entry : attachment.getPermissions().entrySet()){
|
* attachment.getPermissions().entrySet()){ perms.add(" " +
|
||||||
perms.add(" " + entry.getKey() + " = " + entry.getValue());
|
* entry.getKey() + " = " + entry.getValue()); }
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
perms.add("Effective Permissions:");
|
perms.add("Effective Permissions:");
|
||||||
for(PermissionAttachmentInfo info : player.getEffectivePermissions()){
|
for (PermissionAttachmentInfo info : player.getEffectivePermissions()) {
|
||||||
if (info.getValue() == true)
|
if (info.getValue() == true)
|
||||||
perms.add(" " + info.getPermission() + " = " + info.getValue());
|
perms.add(" " + info.getPermission() + " = " + info.getValue());
|
||||||
}
|
}
|
||||||
|
@ -232,7 +278,7 @@ public class BukkitPermissions {
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
player_join = true;
|
player_join = true;
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
//force GM to create the player if they are not already listed.
|
// force GM to create the player if they are not already listed.
|
||||||
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
||||||
player_join = false;
|
player_join = false;
|
||||||
updatePermissions(event.getPlayer());
|
updatePermissions(event.getPlayer());
|
||||||
|
@ -242,7 +288,7 @@ public class BukkitPermissions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerPortal(PlayerPortalEvent event) { // will portal into another world
|
public void onPlayerPortal(PlayerPortalEvent event) { // will portal into another world
|
||||||
if(event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())){ // only if world actually changed
|
if (event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // only if world actually changed
|
||||||
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
|
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,8 +332,8 @@ public class BukkitPermissions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginDisable(PluginDisableEvent event) {
|
public void onPluginDisable(PluginDisableEvent event) {
|
||||||
//collectPermissions();
|
// collectPermissions();
|
||||||
//updateAllPlayers();
|
// updateAllPlayers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue