diff options
author | snowleo <schneeleo@gmail.com> | 2012-01-18 04:01:01 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-01-18 04:01:01 +0100 |
commit | f0dd81ee000b333b2aca59b9949518c7686cceb1 (patch) | |
tree | cf620b5603e1b25656550f87a37975b6dc5351af /EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java | |
parent | 27b0cc86de8c21f089e0e68a5db3ebb42f4df2d2 (diff) | |
parent | 5c1d49fd0efe56c24d6ae5f63f4d0cc31329243d (diff) | |
download | Essentials-f0dd81ee000b333b2aca59b9949518c7686cceb1.tar Essentials-f0dd81ee000b333b2aca59b9949518c7686cceb1.tar.gz Essentials-f0dd81ee000b333b2aca59b9949518c7686cceb1.tar.lz Essentials-f0dd81ee000b333b2aca59b9949518c7686cceb1.tar.xz Essentials-f0dd81ee000b333b2aca59b9949518c7686cceb1.zip |
Merge branch 'refs/heads/master' into 3.0
Did some tweaks, so that it actually works.
Conflicts:
Essentials/src/com/earth2me/essentials/Essentials.java
Essentials/src/com/earth2me/essentials/User.java
Essentials/src/com/earth2me/essentials/Util.java
Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java
Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java
Essentials/src/com/earth2me/essentials/commands/Commandmail.java
Essentials/src/com/earth2me/essentials/commands/Commandme.java
Essentials/src/com/earth2me/essentials/commands/Commandmsg.java
Essentials/src/com/earth2me/essentials/commands/Commandnick.java
Essentials/src/com/earth2me/essentials/commands/Commandr.java
Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java
EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java
EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java
EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java
EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
build.xml
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java | 123 |
1 files changed, 88 insertions, 35 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 202e27e3a..91f9a9bd6 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.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
@@ -23,9 +24,9 @@ import java.util.List; import java.util.Map;
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.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -43,8 +44,7 @@ import org.bukkit.event.server.ServerListener; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
-import org.bukkit.permissions.PermissionDefault;
-import org.bukkit.plugin.Plugin;
+//import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
@@ -52,7 +52,7 @@ import org.bukkit.plugin.PluginManager; *
* BukkitPermissions overrides to force GM reponses to Superperms
*
- * @author ElgarL, based upon PermissionsEX implementation
+ * @author ElgarL, originally based upon PermissionsEX implementation
*/
public class BukkitPermissions {
@@ -62,13 +62,25 @@ public class BukkitPermissions { protected boolean dumpAllPermissions = true;
protected boolean dumpMatchedPermissions = true;
public boolean player_join = false;
+
+ private static Field permissions;
+
+ // Setup reflection (Thanks to Codename_B for the reflection source)
+ static {
+ try {
+ permissions = PermissionAttachment.class.getDeclaredField("permissions");
+ permissions.setAccessible(true);
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NoSuchFieldException e) {
+ e.printStackTrace();
+ }
+ }
public BukkitPermissions(GroupManager plugin) {
this.plugin = plugin;
-
this.collectPermissions();
this.registerEvents();
-
this.updateAllPlayers();
GroupManager.logger.info("Superperms support enabled.");
@@ -93,50 +105,69 @@ public class BukkitPermissions { manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin);
}
+
public void collectPermissions() {
registeredPermissions.clear();
+ /*
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
for (Permission permission : bukkitPlugin.getDescription().getPermissions())
registeredPermissions.push(permission);
}
+ */
+
+ registeredPermissions = new LinkedList<Permission>(Bukkit.getPluginManager().getPermissions());
+
}
+
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
+ * 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;
}
- if (!this.attachments.containsKey(player)) {
- this.attachments.put(player, player.addAttachment(plugin));
+ PermissionAttachment attachment;
+ // Find the players current attachment, or add a new one.
+ if (this.attachments.containsKey(player)) {
+ attachment = this.attachments.get(player);
+ } else {
+ attachment = player.addAttachment(plugin);
+ this.attachments.put(player, attachment);;
}
if (world == null) {
world = player.getWorld().getName();
}
- // All permissions registered with Bukkit for this player
- PermissionAttachment attachment = this.attachments.get(player);
-
OverloadedWorldHolder worldData = plugin.getWorldsHolder().getWorldData(world);
+ Boolean value = false;
+ //User user = worldData.getUser(player.getName());
- User user = worldData.getUser(player.getName());
-
+ /*
// clear permissions
for (String permission : attachment.getPermissions().keySet())
attachment.unsetPermission(permission);
-
+ */
+
/*
* find matching permissions
*
* and base bukkit perms if we are set to allow bukkit permissions to
* override.
*/
- Boolean value = false;
-
+
+ /*
for (Permission permission : registeredPermissions) {
PermissionCheckResult result = worldData.getPermissionsHandler().checkFullGMPermission(user, permission.getName(), false);
@@ -163,35 +194,48 @@ public class BukkitPermissions { if ((value == true) || (result.resultType == PermissionCheckResult.Type.NEGATION)) {
attachment.setPermission(permission, value);
}
- /*
- if ((value == true) || (result.resultType == PermissionCheckResult.Type.NOTFOUND)) {
- // fetch and set all children of this permission node
- Map<String, Boolean> children = permission.getChildren();
- if (children != null) {
- for (String child : children.keySet()) {
- if (children.get(child))
- attachment.setPermission(child, value);
- }
- }
- }*/
-
}
+ */
- // Add any missing permissions for this player (non bukkit plugins and child nodes)
- List<String> playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName());
-
+ // Add all permissions for this player (GM only)
+ // child nodes will be calculated by Bukkit.
+ List<String> playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName(), false);
+ Map<String, Boolean> newPerms = new HashMap<String, Boolean>();
+
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);
}
+ */
+ newPerms.put(permission, value);
+ }
+
+ //player.recalculatePermissions();
+
+ /**
+ * 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);
+ // Clear the map (faster than removing the attachment and recalculating)
+ orig.clear();
+ // Then whack our map into there
+ orig.putAll(newPerms);
+ // That's all folks!
+ attachment.getPermissible().recalculatePermissions();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
}
- player.recalculatePermissions();
}
/**
@@ -245,6 +289,12 @@ public class BukkitPermissions { return null;
}
+ /**
+ * List all effective permissions for this player.
+ *
+ * @param player
+ * @return List<String> of permissions
+ */
public List<String> listPerms(Player player) {
List<String> perms = new ArrayList<String>();
@@ -266,6 +316,9 @@ public class BukkitPermissions { return perms;
}
+ /**
+ * force Bukkit to update every OnlinePlayers permissions.
+ */
public void updateAllPlayers() {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
updatePermissions(player);
@@ -332,7 +385,7 @@ public class BukkitPermissions { @Override
public void onPluginDisable(PluginDisableEvent event) {
- // collectPermissions();
+ collectPermissions();
// updateAllPlayers();
}
}
|