Merge remote branch 'remotes/ess/groupmanager' into essmaster

This commit is contained in:
KHobbits 2011-09-20 13:36:55 +01:00
commit 1fd5222d40
5 changed files with 143 additions and 13 deletions

View File

@ -9,5 +9,5 @@ v 1.1:
- Fix for Users.yml containing only 'users:' causing a crash. - Fix for Users.yml containing only 'users:' causing a crash.
- GroupManager will now generate a fresh Users and Groups yml if either file is empty. - GroupManager will now generate a fresh Users and Groups yml if either file is empty.
- Fix for an infinite loop bug with the new Bukkit Perms during a new user creation. - Fix for an infinite loop bug with the new Bukkit Perms during a new user creation.
v 1.2:
- Fixed BukkitPerms population. Wasn't correctly setting superperms. - Fixed BukkitPerms population. Wasn't correctly setting superperms.
- Push updates to superperms for all valid GM commands.

View File

@ -208,7 +208,7 @@ public class GroupManager extends JavaPlugin {
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
boolean playerCanDo = false; boolean playerCanDo = false;
boolean isConsole = false; boolean isConsole = false;
Player senderPlayer = null; Player senderPlayer = null, targetPlayer = null;
Group senderGroup = null; Group senderGroup = null;
User senderUser = null; User senderUser = null;
@ -341,6 +341,9 @@ public class GroupManager extends JavaPlugin {
auxUser.setGroup(auxGroup); auxUser.setGroup(auxGroup);
sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'."); 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; return true;
//break; //break;
case manudel: case manudel:
@ -375,6 +378,9 @@ public class GroupManager extends JavaPlugin {
dataHolder.removeUser(auxUser.getName()); dataHolder.removeUser(auxUser.getName());
sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' to default settings."); 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; return true;
case manuaddsub: case manuaddsub:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -416,6 +422,9 @@ public class GroupManager extends JavaPlugin {
auxUser.addSubGroup(auxGroup); auxUser.addSubGroup(auxGroup);
sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'."); 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; return true;
case manudelsub: case manudelsub:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -449,6 +458,9 @@ public class GroupManager extends JavaPlugin {
auxUser.removeSubGroup(auxGroup); auxUser.removeSubGroup(auxGroup);
sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list."); 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; return true;
case mangadd: case mangadd:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -491,6 +503,8 @@ public class GroupManager extends JavaPlugin {
dataHolder.removeGroup(auxGroup.getName()); dataHolder.removeGroup(auxGroup.getName());
sender.sendMessage(ChatColor.YELLOW + "You deleted a group named " + auxGroup.getName() + ", it's users are default group now."); sender.sendMessage(ChatColor.YELLOW + "You deleted a group named " + auxGroup.getName() + ", it's users are default group now.");
BukkitPermissions.updateAllPlayers();
return true; return true;
case manuaddp: case manuaddp:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -554,6 +568,10 @@ public class GroupManager extends JavaPlugin {
//PARECE OK //PARECE OK
auxUser.addPermission(args[1]); auxUser.addPermission(args[1]);
sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to player '" + auxUser.getName() + "' permissions."); 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; return true;
//break; //break;
case manudelp: case manudelp:
@ -605,6 +623,9 @@ public class GroupManager extends JavaPlugin {
auxUser.removePermission(args[1]); auxUser.removePermission(args[1]);
sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from player '" + auxUser.getName() + "' permissions."); 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; return true;
//break; //break;
case manulistp: case manulistp:
@ -760,6 +781,8 @@ public class GroupManager extends JavaPlugin {
auxGroup.addPermission(args[1]); auxGroup.addPermission(args[1]);
sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to group '" + auxGroup.getName() + "' permissions."); sender.sendMessage(ChatColor.YELLOW + "You added '" + args[1] + "' to group '" + auxGroup.getName() + "' permissions.");
BukkitPermissions.updateAllPlayers();
return true; return true;
case mangdelp: case mangdelp:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -799,6 +822,8 @@ public class GroupManager extends JavaPlugin {
auxGroup.removePermission(args[1]); auxGroup.removePermission(args[1]);
sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from group '" + auxGroup.getName() + "' permissions."); sender.sendMessage(ChatColor.YELLOW + "You removed '" + args[1] + "' from group '" + auxGroup.getName() + "' permissions.");
BukkitPermissions.updateAllPlayers();
return true; return true;
case manglistp: case manglistp:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -912,6 +937,8 @@ public class GroupManager extends JavaPlugin {
auxGroup.addInherits(auxGroup2); auxGroup.addInherits(auxGroup2);
sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " is now in " + auxGroup.getName() + " inheritance list."); sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " is now in " + auxGroup.getName() + " inheritance list.");
BukkitPermissions.updateAllPlayers();
return true; return true;
case mangdeli: case mangdeli:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -947,6 +974,8 @@ public class GroupManager extends JavaPlugin {
auxGroup.removeInherits(auxGroup2.getName()); auxGroup.removeInherits(auxGroup2.getName());
sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " was removed from " + auxGroup.getName() + " inheritance list."); sender.sendMessage(ChatColor.RED + "Group " + auxGroup2.getName() + " was removed from " + auxGroup.getName() + " inheritance list.");
BukkitPermissions.updateAllPlayers();
return true; return true;
case manuaddv: case manuaddv:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -1394,6 +1423,9 @@ public class GroupManager extends JavaPlugin {
} }
worldsHolder.loadWorld(auxString); worldsHolder.loadWorld(auxString);
sender.sendMessage("The request to world '" + auxString + "' was sent."); sender.sendMessage("The request to world '" + auxString + "' was sent.");
BukkitPermissions.updateAllPlayers();
return true; return true;
} }
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -1418,6 +1450,9 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.YELLOW + " The current world was reloaded."); sender.sendMessage(ChatColor.YELLOW + " The current world was reloaded.");
} }
worldsHolder.mirrorSetUp(); worldsHolder.mirrorSetUp();
BukkitPermissions.updateAllPlayers();
return true; return true;
case listgroups: case listgroups:
//VALIDANDO ESTADO DO SENDER //VALIDANDO ESTADO DO SENDER
@ -1488,6 +1523,9 @@ public class GroupManager extends JavaPlugin {
auxUser.setGroup(auxGroup); auxUser.setGroup(auxGroup);
sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); 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; return true;
//break; //break;
case mandemote: case mandemote:
@ -1543,6 +1581,9 @@ public class GroupManager extends JavaPlugin {
auxUser.setGroup(auxGroup); auxUser.setGroup(auxGroup);
sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + "."); 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; return true;
//break; //break;
case mantogglevalidate: case mantogglevalidate:

View File

@ -80,6 +80,76 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return ph.getUser(userName).getGroup().getName(); 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. * Verify if player is in suck group.
* It will check it's groups inheritance. * It will check it's groups inheritance.

View File

@ -16,6 +16,7 @@
package org.anjocaido.groupmanager.permissions; package org.anjocaido.groupmanager.permissions;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -24,6 +25,8 @@ 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.utils.PermissionCheckResult;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -40,6 +43,7 @@ import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener; import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -113,10 +117,12 @@ public class BukkitPermissions {
world = player.getWorld().getName(); world = player.getWorld().getName();
} }
// All permissions registered with Bukkit for this player
PermissionAttachment attachment = this.attachments.get(player); PermissionAttachment attachment = this.attachments.get(player);
User user = GroupManager.getWorldsHolder().getWorldData(world).getUser(player.getName()); OverloadedWorldHolder worldData = GroupManager.getWorldsHolder().getWorldData(world);
List<String> permissions = user.getGroup().getPermissionList();
User user = worldData.getUser(player.getName());
// clear permissions // clear permissions
for (String permission : attachment.getPermissions().keySet()) { for (String permission : attachment.getPermissions().keySet()) {
@ -124,14 +130,23 @@ public class BukkitPermissions {
} }
// find matching permissions // find matching permissions
PermissionCheckResult permissionResult;
Boolean value;
for (Permission permission : registeredPermissions) { for (Permission permission : registeredPermissions) {
boolean permissionValue = user.getGroup().hasSamePermissionNode(permission.getName()); permissionResult = worldData.getPermissionsHandler().checkFullUserPermission(user, permission.getName());
attachment.setPermission(permission, permissionValue); if (permissionResult.resultType.equals(PermissionCheckResult.Type.FOUND))
value = true;
else
value = false;
attachment.setPermission(permission, value);
} }
// all permissions // Add any missing permissions for this player (non bukkit plugins)
for (String permission : permissions) { List<String> playerPermArray = new ArrayList<String>(worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName()));
Boolean value = true;
for (String permission : playerPermArray) {
value = true;
if (permission.startsWith("-")) { if (permission.startsWith("-")) {
permission = permission.substring(1); // cut off - permission = permission.substring(1); // cut off -
value = false; value = false;
@ -141,8 +156,8 @@ public class BukkitPermissions {
attachment.setPermission(permission, value); attachment.setPermission(permission, value);
} }
} }
player.recalculatePermissions(); player.recalculatePermissions();
/* /*
// List perms for this player // List perms for this player
GroupManager.logger.info("Attachment Permissions:"); GroupManager.logger.info("Attachment Permissions:");

View File

@ -3,6 +3,8 @@ package org.anjocaido.groupmanager.permissions;
//import java.util.Collection; //import java.util.Collection;
//import java.util.Map; //import java.util.Map;
//import java.util.Set; //import java.util.Set;
import java.util.List;
import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.data.Group;
//import org.anjocaido.groupmanager.data.User; //import org.anjocaido.groupmanager.data.User;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -229,4 +231,6 @@ public abstract class PermissionsReaderInterface {
public abstract void removeGroupInfo(String name, String path); public abstract void removeGroupInfo(String name, String path);
////////////////////////////// //////////////////////////////
public abstract List<String> getAllPlayersPermissions(String userName);
} }