Add webchat-permissions setting, fix bPerms, PermissionsBukkit

This commit is contained in:
Mike Primm 2012-03-31 00:23:22 -05:00
parent 1d6cedeeb0
commit 6afb0d9b92
6 changed files with 37 additions and 61 deletions

View File

@ -457,11 +457,11 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
if (permissions == null) if (permissions == null)
permissions = bPermPermissions.create(getServer(), "dynmap", perdefs); permissions = bPermPermissions.create(getServer(), "dynmap", perdefs);
if (permissions == null) if (permissions == null)
permissions = PermBukkitPermissions.create(getServer(), "dynmap"); permissions = PermBukkitPermissions.create(getServer(), "dynmap", perdefs);
if (permissions == null) if (permissions == null)
permissions = NijikokunPermissions.create(getServer(), "dynmap"); permissions = NijikokunPermissions.create(getServer(), "dynmap");
if (permissions == null) if (permissions == null)
permissions = BukkitPermissions.create("dynmap"); permissions = BukkitPermissions.create("dynmap", perdefs);
if (permissions == null) if (permissions == null)
permissions = new OpPermissions(new String[] { "fullrender", "cancelrender", "radiusrender", "resetstats", "reload", "purgequeue", "pause", "ips-for-id", "ids-for-ip", "add-id-for-ip", "del-id-for-ip" }); permissions = new OpPermissions(new String[] { "fullrender", "cancelrender", "radiusrender", "resetstats", "reload", "purgequeue", "pause", "ips-for-id", "ids-for-ip", "add-id-for-ip", "del-id-for-ip" });
/* Get and initialize data folder */ /* Get and initialize data folder */

View File

@ -1,6 +1,7 @@
package org.dynmap.bukkit.permissions; package org.dynmap.bukkit.permissions;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -10,20 +11,23 @@ import org.bukkit.entity.Player;
import org.dynmap.Log; import org.dynmap.Log;
public class BukkitPermissions implements PermissionProvider { public class BukkitPermissions implements PermissionProvider {
String name; protected String name;
protected Map<String, Boolean> pd;
public static BukkitPermissions create(String name) { public static BukkitPermissions create(String name, Map<String,Boolean> pd) {
try { try {
Class.forName("org.bukkit.permissions.PermissibleBase"); /* See if class exists */ Class.forName("org.bukkit.permissions.PermissibleBase"); /* See if class exists */
} catch (ClassNotFoundException cnfx) { } catch (ClassNotFoundException cnfx) {
return null; return null;
} }
Log.info("Using Bukkit Permissions (superperms) for access control"); Log.info("Using Bukkit Permissions (superperms) for access control");
return new BukkitPermissions(name); Log.info("Web interface perms only available for online users");
return new BukkitPermissions(name, pd);
} }
public BukkitPermissions(String name) { public BukkitPermissions(String name, Map<String, Boolean> pd) {
this.name = name; this.name = name;
this.pd = pd;
} }
@Override @Override
@ -50,10 +54,16 @@ public class BukkitPermissions implements PermissionProvider {
@Override @Override
public boolean hasOfflinePermission(String player, String perm) { public boolean hasOfflinePermission(String player, String perm) {
Player p = Bukkit.getPlayerExact(name); Player p = Bukkit.getPlayerExact(player);
if (p != null) if (p != null) {
return p.hasPermission(name + "." + perm); return p.hasPermission(name + "." + perm);
else }
else {
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
if((op != null) && op.isOp()) {
return true;
}
return false; return false;
}
} }
} }

View File

@ -47,6 +47,8 @@ public class NijikokunPermissions implements PermissionProvider {
@Override @Override
public Set<String> hasOfflinePermissions(String player, Set<String> perms) { public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
if(permissions == null)
permissions = ((Permissions)plugin).getHandler();
HashSet<String> hasperms = new HashSet<String>(); HashSet<String> hasperms = new HashSet<String>();
for (String pp : perms) { for (String pp : perms) {
if (permissions.has(defworld, player, name + "." + pp)) { if (permissions.has(defworld, player, name + "." + pp)) {
@ -58,6 +60,8 @@ public class NijikokunPermissions implements PermissionProvider {
@Override @Override
public boolean hasOfflinePermission(String player, String perm) { public boolean hasOfflinePermission(String player, String perm) {
if(permissions == null)
permissions = ((Permissions)plugin).getHandler();
return permissions.has(defworld, player, name + "." + perm); return permissions.has(defworld, player, name + "." + perm);
} }

View File

@ -11,55 +11,30 @@ import org.bukkit.plugin.Plugin;
import org.dynmap.Log; import org.dynmap.Log;
import com.nijiko.permissions.PermissionHandler; import com.nijiko.permissions.PermissionHandler;
import com.platymuus.bukkit.permissions.PermissionInfo;
import com.platymuus.bukkit.permissions.PermissionsPlugin; import com.platymuus.bukkit.permissions.PermissionsPlugin;
import de.bananaco.bpermissions.api.ApiLayer; import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.util.CalculableType; import de.bananaco.bpermissions.api.util.CalculableType;
import de.bananaco.bpermissions.api.util.Permission; import de.bananaco.bpermissions.api.util.Permission;
public class PermBukkitPermissions implements PermissionProvider { public class PermBukkitPermissions extends BukkitPermissions {
String name;
PermissionsPlugin plugin; PermissionsPlugin plugin;
Map<String, Boolean> pd;
public static PermBukkitPermissions create(Server server, String name) { public static PermBukkitPermissions create(Server server, String name, Map<String, Boolean> pd) {
Plugin permissionsPlugin = server.getPluginManager().getPlugin("PermissionsBukkit"); Plugin permissionsPlugin = server.getPluginManager().getPlugin("PermissionsBukkit");
if (permissionsPlugin == null) if (permissionsPlugin == null)
return null; return null;
server.getPluginManager().enablePlugin(permissionsPlugin); server.getPluginManager().enablePlugin(permissionsPlugin);
Log.info("Using PermissionsBukkit " + permissionsPlugin.getDescription().getVersion() + " for access control"); Log.info("Using PermissionsBukkit " + permissionsPlugin.getDescription().getVersion() + " for access control");
return new PermBukkitPermissions(permissionsPlugin, name); return new PermBukkitPermissions(permissionsPlugin, name, pd);
} }
public PermBukkitPermissions(Plugin permissionsPlugin, String name) { public PermBukkitPermissions(Plugin permissionsPlugin, String name, Map<String, Boolean> pd) {
this.name = name; super(name, pd);
plugin = (PermissionsPlugin) permissionsPlugin; plugin = (PermissionsPlugin) permissionsPlugin;
} this.pd = pd;
@Override
public boolean has(CommandSender sender, String permission) {
Player player = sender instanceof Player ? (Player) sender : null;
return (player != null) ? plugin.getPlayerInfo(player.getName()).getPermissions().containsKey(name + "." + permission) : true;
}
@Override
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
Map<String, Boolean> prm = plugin.getPlayerInfo(player).getPermissions();
HashSet<String> hasperms = new HashSet<String>();
for (String pp : perms) {
Boolean pb = prm.get(name + "." + pp);
if ((pb != null) && pb.booleanValue()) {
hasperms.add(pp);
}
}
return hasperms;
}
@Override
public boolean hasOfflinePermission(String player, String perm) {
Boolean b = plugin.getPlayerInfo(player).getPermissions().get(name + "." + perm);
if (b != null)
return b;
else
return false;
} }
} }

View File

@ -20,11 +20,8 @@ import de.bananaco.bpermissions.api.WorldManager;
import de.bananaco.bpermissions.api.util.CalculableType; import de.bananaco.bpermissions.api.util.CalculableType;
import de.bananaco.bpermissions.api.util.Permission; import de.bananaco.bpermissions.api.util.Permission;
public class bPermPermissions implements PermissionProvider { public class bPermPermissions extends BukkitPermissions {
String name;
String defworld;
WorldManager wm; WorldManager wm;
Map<String,Boolean> pd;
public static bPermPermissions create(Server server, String name, Map<String,Boolean> pd) { public static bPermPermissions create(Server server, String name, Map<String,Boolean> pd) {
Plugin permissionsPlugin = server.getPluginManager().getPlugin("bPermissions"); Plugin permissionsPlugin = server.getPluginManager().getPlugin("bPermissions");
@ -36,23 +33,10 @@ public class bPermPermissions implements PermissionProvider {
} }
public bPermPermissions(String name, Map<String,Boolean> pd) { public bPermPermissions(String name, Map<String,Boolean> pd) {
this.name = name; super(name, pd);
defworld = Bukkit.getServer().getWorlds().get(0).getName();
wm = WorldManager.getInstance(); wm = WorldManager.getInstance();
this.pd = pd;
} }
@Override
public boolean has(CommandSender sender, String permission) {
Player player = sender instanceof Player ? (Player) sender : null;
boolean rslt = true;
if(player != null) {
rslt = hasOfflinePermission(player.getName(), permission);
}
return rslt;
}
@Override @Override
public Set<String> hasOfflinePermissions(String player, Set<String> perms) { public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
HashSet<String> hasperms = new HashSet<String>(); HashSet<String> hasperms = new HashSet<String>();

View File

@ -30,7 +30,8 @@ components:
block-banned-player-chat: true block-banned-player-chat: true
# Require login for web-to-server chat (requires login-enabled: true) # Require login for web-to-server chat (requires login-enabled: true)
webchat-requires-login: false webchat-requires-login: false
# If set to true, users must have dynmap.webchat permission in order to chat
webchat-permissions: false
# # Optional - make players hidden when they are inside/underground/in shadows (#=light level: 0=full shadow,15=sky) # # Optional - make players hidden when they are inside/underground/in shadows (#=light level: 0=full shadow,15=sky)
# hideifshadow: 4 # hideifshadow: 4
# # Optional - make player hidden when they are under cover (#=sky light level,0=underground,15=open to sky) # # Optional - make player hidden when they are under cover (#=sky light level,0=underground,15=open to sky)
@ -53,6 +54,8 @@ components:
# hideifsneaking: false # hideifsneaking: false
# # Require login for web-to-server chat (requires login-enabled: true) # # Require login for web-to-server chat (requires login-enabled: true)
# webchat-requires-login: false # webchat-requires-login: false
# # If set to true, users must have dynmap.webchat permission in order to chat
# webchat-permissions: false
- class: org.dynmap.SimpleWebChatComponent - class: org.dynmap.SimpleWebChatComponent
allowchat: true allowchat: true