Add GroupManager specific permissions support

This commit is contained in:
Mike Primm 2013-05-10 01:31:30 -05:00
parent 734937884a
commit d4e24e9d26
3 changed files with 72 additions and 0 deletions

View File

@ -130,6 +130,11 @@
<artifactId>PermissionsBukkit</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.anjocaido</groupId>
<artifactId>EssentialsGroupManager</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>
<version>1.7</version>
</project>

View File

@ -82,6 +82,7 @@ import org.dynmap.bukkit.permissions.NijikokunPermissions;
import org.dynmap.bukkit.permissions.OpPermissions;
import org.dynmap.bukkit.permissions.PEXPermissions;
import org.dynmap.bukkit.permissions.PermBukkitPermissions;
import org.dynmap.bukkit.permissions.GroupManagerPermissions;
import org.dynmap.bukkit.permissions.PermissionProvider;
import org.dynmap.bukkit.permissions.bPermPermissions;
import org.dynmap.common.BiomeMap;
@ -724,6 +725,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
permissions = PEXPermissions.create(getServer(), "dynmap");
if (permissions == null)
permissions = bPermPermissions.create(getServer(), "dynmap", perdefs);
if (permissions == null)
permissions = GroupManagerPermissions.create(getServer(), "dynmap");
if (permissions == null)
permissions = PermBukkitPermissions.create(getServer(), "dynmap", perdefs);
if (permissions == null)

View File

@ -0,0 +1,64 @@
package org.dynmap.bukkit.permissions;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.dynmap.Log;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
public class GroupManagerPermissions implements PermissionProvider {
String name;
GroupManager gm;
WorldsHolder wh;
public static GroupManagerPermissions create(Server server, String name) {
Plugin permissionsPlugin = server.getPluginManager().getPlugin("GroupManager");
if (permissionsPlugin == null)
return null;
server.getPluginManager().enablePlugin(permissionsPlugin);
if(permissionsPlugin.isEnabled() == false)
return null;
Log.info("Using GroupManager " + permissionsPlugin.getDescription().getVersion() + " for access control");
return new GroupManagerPermissions(name, permissionsPlugin);
}
public GroupManagerPermissions(String name, Plugin permissionsPlugin) {
this.name = name;
gm = (GroupManager)permissionsPlugin;
wh = gm.getWorldsHolder();
}
@Override
public boolean has(CommandSender sender, String permission) {
Player player = sender instanceof Player ? (Player) sender : null;
return (player != null) ? wh.getWorldPermissions(player).has(player, name + "." + permission) : true;
}
@Override
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
HashSet<String> hasperms = new HashSet<String>();
AnjoPermissionsHandler apm = wh.getWorldPermissionsByPlayerName(player);
if (apm != null) {
for (String pp : perms) {
if (apm.permission(player, name + "." + pp)) {
hasperms.add(pp);
}
}
}
return hasperms;
}
@Override
public boolean hasOfflinePermission(String player, String perm) {
AnjoPermissionsHandler apm = wh.getWorldPermissionsByPlayerName(player);
if(apm != null) {
return apm.permission(player, name + "." + perm);
}
return false;
}
}