Added PermissionsProvider interface that can also handle permissions.

Dieser Commit ist enthalten in:
sk89q 2011-03-02 00:49:59 -08:00
Ursprung 7a8aa9838e
Commit 488f841d69
4 geänderte Dateien mit 112 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,26 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.bukkit.migration;
public interface PermissionsProvider {
public boolean hasPermission(String name, String permission);
public boolean inGroup(String player, String group);
public String[] getGroups(String player);
}

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.bukkit.migration;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.config.Configuration; import org.bukkit.util.config.Configuration;
public class PermissionsResolverManager implements PermissionsResolver { public class PermissionsResolverManager implements PermissionsResolver {
@ -40,6 +41,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
} }
public void findResolver() { public void findResolver() {
if (tryPluginPermissionsResolver()) return;
if (tryGroupsUsers()) return; if (tryGroupsUsers()) return;
if (tryNijiPermissions()) return; if (tryNijiPermissions()) return;
if (tryFlatFilePermissions()) return; if (tryFlatFilePermissions()) return;
@ -78,6 +80,31 @@ public class PermissionsResolverManager implements PermissionsResolver {
return false; return false;
} }
private boolean tryPluginPermissionsResolver() {
for (Plugin plugin : server.getPluginManager().getPlugins()) {
if (plugin instanceof PermissionsProvider) {
perms = new PluginPermissionsResolver(
(PermissionsProvider) plugin);
logger.info(name + ": Using plugin '"
+ plugin.getDescription().getName() + " for permissions.");
return true;
}
}
return false;
}
public void setPluginPermissionsResolver(Plugin plugin) {
if (!(plugin instanceof PermissionsProvider)) {
return;
}
perms = new PluginPermissionsResolver(
(PermissionsProvider) plugin);
logger.info(name + ": Using plugin '"
+ plugin.getDescription().getName() + " for permissions.");
}
public void load() { public void load() {
perms.load(); perms.load();
} }

Datei anzeigen

@ -39,9 +39,12 @@ public class PermissionsResolverServerListener extends ServerListener {
*/ */
@Override @Override
public void onPluginEnabled(PluginEvent event) { public void onPluginEnabled(PluginEvent event) {
String name = event.getPlugin().getDescription().getName(); Plugin plugin = event.getPlugin();
String name = plugin.getDescription().getName();
if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) { if (plugin instanceof PermissionsProvider) {
manager.setPluginPermissionsResolver(plugin);
} else if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) {
manager.findResolver(); manager.findResolver();
} }
} }
@ -53,9 +56,12 @@ public class PermissionsResolverServerListener extends ServerListener {
*/ */
@Override @Override
public void onPluginDisabled(PluginEvent event) { public void onPluginDisabled(PluginEvent event) {
String name = event.getPlugin().getDescription().getName(); Plugin plugin = event.getPlugin();
String name = plugin.getDescription().getName();
if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) { if (plugin instanceof PermissionsProvider
|| name.equalsIgnoreCase("GroupUsers")
|| name.equalsIgnoreCase("Permissions")) {
manager.findResolver(); manager.findResolver();
} }
} }

Datei anzeigen

@ -0,0 +1,49 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.bukkit.migration;
public class PluginPermissionsResolver implements PermissionsResolver {
protected PermissionsProvider resolver;
public PluginPermissionsResolver(PermissionsProvider resolver) {
this.resolver = resolver;
}
@Override
public void load() {
}
@Override
public boolean hasPermission(String name, String permission) {
return resolver.hasPermission(name, permission);
}
@Override
public boolean inGroup(String player, String group) {
return resolver.inGroup(player, group);
}
@Override
public String[] getGroups(String player) {
return resolver.getGroups(player);
}
}