Merge remote-tracking branch 'origin/groupmanager'

This commit is contained in:
snowleo 2012-04-05 17:05:43 +02:00
commit f73a5d0e8d
6 changed files with 76 additions and 25 deletions

View File

@ -157,3 +157,10 @@ v 1.9:
- Update GlobalGroups.yml for new/changed Towny permission nodes. - Update GlobalGroups.yml for new/changed Towny permission nodes.
- Stop attempting to push empty permissions when players edit the yml's incorrectly. - Stop attempting to push empty permissions when players edit the yml's incorrectly.
- Catch errors caused by bad indentation in yml's. - Catch errors caused by bad indentation in yml's.
- Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions.
- Added a new permission node 'groupmanager.op'. This will cause players with this node to be treated as op's when
using GroupManager commands (they will still require each commands permission node to use them).
- Prevent Null entries in group inheritance from throwing errors.
v 2.0:
- Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions.
- Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions.

View File

@ -303,7 +303,7 @@ public class GroupManager extends JavaPlugin {
senderPlayer = (Player) sender; senderPlayer = (Player) sender;
senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName()); senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName());
senderGroup = senderUser.getGroup(); senderGroup = senderUser.getGroup();
isOpOverride = (isOpOverride && senderPlayer.isOp()); isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op")));
System.out.println("[PLAYER_COMMAND] " + senderPlayer.getName() + ": /" + commandLabel + " " + Tasks.join(args, " ")); System.out.println("[PLAYER_COMMAND] " + senderPlayer.getName() + ": /" + commandLabel + " " + Tasks.join(args, " "));
if (isOpOverride || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager." + cmd.getName())) { if (isOpOverride || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager." + cmd.getName())) {

View File

@ -563,10 +563,12 @@ public class WorldDataHolder {
List<String> inheritedList = inheritance.get(groupKey); List<String> inheritedList = inheritance.get(groupKey);
Group thisGroup = ph.getGroup(groupKey); Group thisGroup = ph.getGroup(groupKey);
for (String inheritedKey : inheritedList) { for (String inheritedKey : inheritedList) {
Group inheritedGroup = ph.getGroup(inheritedKey); if (inheritedKey != null) {
if (thisGroup != null && inheritedGroup != null) { Group inheritedGroup = ph.getGroup(inheritedKey);
thisGroup.addInherits(inheritedGroup); if (thisGroup != null && inheritedGroup != null) {
} thisGroup.addInherits(inheritedGroup);
}
}
} }
} }

View File

@ -144,7 +144,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
// Perm doesn't already exists and there is no negation for it // 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) // 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)) if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm))
|| (negated && !playerPermArray.contains(perm.substring(1)))) || (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm)))
playerPermArray.add(perm); playerPermArray.add(perm);
} }
} }
@ -155,8 +155,10 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return playerPermArray; return playerPermArray;
} }
private Set<String> populatePerms (List<String> perms, 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>(); Set<String> permArray = new HashSet<String>();
Boolean allPerms = false; Boolean allPerms = false;
@ -164,20 +166,17 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
if (perms.contains("*")) { if (perms.contains("*")) {
permArray.addAll(GroupManager.BukkitPermissions.getAllRegisteredPermissions(includeChildren)); permArray.addAll(GroupManager.BukkitPermissions.getAllRegisteredPermissions(includeChildren));
allPerms = true; allPerms = true;
perms.remove("*");
} }
for (String perm : perms) { for (String perm : perms) {
if (!perm.equalsIgnoreCase("*")) {
/** /**
* all permission sets are passed here pre-sorted, alphabetically. * all permission sets are passed here pre-sorted, alphabetically.
* This means negated nodes will be processed before all permissions * This means negated nodes will be processed before all permissions
* other than *. * other than *.
*/ */
boolean negated = false; boolean negated = perm.startsWith("-");
if (perm.startsWith("-"))
negated = true;
if (!permArray.contains(perm)) { if (!permArray.contains(perm)) {
permArray.add(perm); permArray.add(perm);
@ -195,15 +194,16 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet<String>()); Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet<String>());
if (children != null) { if (children != null) {
if (negated || (negated && allPerms)) { if (negated)
if (allPerms) {
// Remove children of negated nodes // Remove children of negated nodes
for (String child : children.keySet()) for (String child : children.keySet())
if (children.get(child)) if (children.get(child))
if (permArray.contains(child)) if (permArray.contains(child))
permArray.remove(child); permArray.remove(child);
} else if (!negated){ } else {
// Add child nodes // Add child nodes
for (String child : children.keySet()) for (String child : children.keySet())
@ -214,7 +214,6 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
} }
} }
} }
}
} }
return permArray; return permArray;
@ -959,7 +958,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
for (String sonName : now.getInherits()) { for (String sonName : now.getInherits()) {
Group son = ph.getGroup(sonName); Group son = ph.getGroup(sonName);
if (son != null && !alreadyVisited.contains(son)) { if (son != null && !alreadyVisited.contains(son)) {
stack.push(son); // Add rather than push to retain inheritance order.
stack.add(son);
alreadyVisited.add(son); alreadyVisited.add(son);
} }
} }

View File

@ -38,6 +38,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
@ -343,6 +344,18 @@ public class BukkitPermissions {
this.updatePermissions(player, null); this.updatePermissions(player, null);
} }
/**
* Force remove any attachments
*
* @param player
*/
private void removeAttachment(Player player) {
if (attachments.containsKey(player)) {
player.removeAttachment(attachments.get(player));
attachments.remove(player);
}
}
/** /**
* Player events tracked to cause Superperms updates * Player events tracked to cause Superperms updates
* *
@ -355,6 +368,12 @@ public class BukkitPermissions {
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
setPlayer_join(true); setPlayer_join(true);
Player player = event.getPlayer(); Player player = event.getPlayer();
/*
* Tidy up any lose ends
*/
removeAttachment(player);
// 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) {
setPlayer_join(false); setPlayer_join(false);
@ -370,7 +389,25 @@ public class BukkitPermissions {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
attachments.remove(event.getPlayer()); 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
*/
removeAttachment(player);
} }
} }

View File

@ -164,3 +164,8 @@ commands:
description: Clear world selection. Next commands will work on your world. description: Clear world selection. Next commands will work on your world.
usage: /<command> usage: /<command>
permissions: groupmanager.manclear permissions: groupmanager.manclear
Permissions:
groupmanager.op:
description: User is treated as an op when using the GroupManager commands.
default: false