Added DinnerPerms support to WEPIF

Dieser Commit ist enthalten in:
zml2008 2011-08-01 21:02:15 -07:00
Ursprung 2efa37f0b2
Commit cb7ec82905
3 geänderte Dateien mit 83 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,71 @@
package com.sk89q.bukkit.migration;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import java.util.ArrayList;
import java.util.List;
public class DinnerPermsResolver implements PermissionsResolver {
private static final String GROUP_PREFIX = "group.";
private final Server server;
public DinnerPermsResolver(Server server) {
this.server = server;
}
@Override
public void load() {
// Permissions are already loaded
}
@Override
public boolean hasPermission(String name, String permission) {
Player player = server.getPlayer(name);
if (player == null)
return false; // Permissions are only registered for online players
if ( player.hasPermission("*") || player.hasPermission(permission))
return true;
int i = 0;
while (i <= permission.length() + 1) {
int dotPos = permission.indexOf(".", i);
if (dotPos > -1) {
if (player.hasPermission(permission.substring(0, dotPos + 1) + "*"))
return true;
i += dotPos;
} else {
break;
}
}
return false;
}
@Override
public boolean hasPermission(String worldName, String name, String permission) {
return hasPermission(name, permission); // no per-world ability to check permissions in dinnerperms
}
@Override
public boolean inGroup(String name, String group) {
Player player = server.getPlayer(name);
if (player == null)
return false;
return player.hasPermission(GROUP_PREFIX + group);
}
@Override
public String[] getGroups(String name) {
Player player = server.getPlayer(name);
if (player == null)
return new String[0];
List<String> groupNames = new ArrayList<String>();
for (PermissionAttachmentInfo permAttach : player.getEffectivePermissions()) {
String perm = permAttach.getPermission();
if (!perm.startsWith(GROUP_PREFIX))
continue;
groupNames.add(perm.substring(perm.indexOf(GROUP_PREFIX), perm.length()));
}
return groupNames.toArray(new String[groupNames.size()]);
}
}

Datei anzeigen

@ -44,6 +44,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
if (tryPluginPermissionsResolver()) return;
if (tryNijiPermissions()) return;
if (tryFlatFilePermissions()) return;
if (tryDinnerPerms()) return;
perms = new ConfigurationPermissionsResolver(config);
logger.info(name + ": No known permissions plugin detected. Using configuration file for permissions.");
@ -75,13 +76,21 @@ public class PermissionsResolverManager implements PermissionsResolver {
perms = new PluginPermissionsResolver(
(PermissionsProvider) plugin);
logger.info(name + ": Using plugin '"
+ plugin.getDescription().getName() + " for permissions.");
+ plugin.getDescription().getName() + "' for permissions.");
return true;
}
}
return false;
}
private boolean tryDinnerPerms() {
if (!config.getBoolean("permissions.dinner-perms", true))
return false;
perms = new DinnerPermsResolver(server);
logger.info(name + ": Using the Bukkit Permissions API.");
return true;
}
public void setPluginPermissionsResolver(Plugin plugin) {
if (!(plugin instanceof PermissionsProvider)) {
@ -91,7 +100,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
perms = new PluginPermissionsResolver(
(PermissionsProvider) plugin);
logger.info(name + ": Using plugin '"
+ plugin.getDescription().getName() + " for permissions.");
+ plugin.getDescription().getName() + "' for permissions.");
}
public void load() {

Datei anzeigen

@ -63,6 +63,7 @@ debug: false
# See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit
# Now with multiworld support (see example)
permissions:
dinner-perms: true
groups:
default:
permissions: