mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-15 04:41:37 +08:00
Added support for Niji's permission system.
This commit is contained in:
parent
bcb46d6b54
commit
01fa16aa54
@ -22,6 +22,7 @@
|
||||
<include name="CraftBukkit.jar" />
|
||||
<include name="Bukkit.jar" />
|
||||
<include name="GroupUsers.jar" />
|
||||
<include name="Permissions.jar" />
|
||||
</fileset>
|
||||
</classpath>
|
||||
</javac>
|
||||
|
101
src/com/sk89q/bukkit/migration/NijiPermissionsResolver.java
Normal file
101
src/com/sk89q/bukkit/migration/NijiPermissionsResolver.java
Normal file
@ -0,0 +1,101 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 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;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
|
||||
public class NijiPermissionsResolver implements PermissionsResolver {
|
||||
private Server server;
|
||||
private Permissions api;
|
||||
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
public NijiPermissionsResolver(Server server)
|
||||
throws PluginAccessException, MissingPluginException {
|
||||
this.server = server;
|
||||
PluginManager manager = server.getPluginManager();
|
||||
|
||||
Plugin plugin = manager.getPlugin("Permissions");
|
||||
if (plugin == null) {
|
||||
throw new MissingPluginException();
|
||||
}
|
||||
|
||||
try {
|
||||
api = (Permissions)plugin;
|
||||
} catch (ClassCastException e) {
|
||||
throw new PluginAccessException();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public boolean hasPermission(String name, String permission) {
|
||||
try {
|
||||
Player player = server.getPlayer(name);
|
||||
if (player == null) return false;
|
||||
return api.Security.permission(player, permission);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public boolean inGroup(String name, String group) {
|
||||
try {
|
||||
Player player = server.getPlayer(name);
|
||||
if (player == null) return false;
|
||||
return group.equals(api.Security.getGroup(player.getName()));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public String[] getGroups(String name) {
|
||||
try {
|
||||
Player player = server.getPlayer(name);
|
||||
if (player == null) return new String[0];
|
||||
String group = api.Security.getGroup(player.getName());
|
||||
if (group == null) {
|
||||
return new String[0];
|
||||
} else {
|
||||
return new String[]{ group };
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static class PluginAccessException extends Exception {
|
||||
private static final long serialVersionUID = 7044832912491608706L;
|
||||
}
|
||||
|
||||
public static class MissingPluginException extends Exception {
|
||||
private static final long serialVersionUID = 7044832912491608706L;
|
||||
}
|
||||
}
|
@ -22,8 +22,6 @@
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import com.sk89q.bukkit.migration.GroupUsersPemissionsResolver.MissingPluginException;
|
||||
import com.sk89q.bukkit.migration.GroupUsersPemissionsResolver.PluginAccessException;
|
||||
|
||||
public class PermissionsResolverManager implements PermissionsResolver {
|
||||
private Configuration config;
|
||||
@ -43,6 +41,7 @@ public PermissionsResolverManager(Configuration config, Server server, String na
|
||||
|
||||
public void findResolver() {
|
||||
if (tryGroupsUsers()) return;
|
||||
if (tryNijiPermissions()) return;
|
||||
if (tryFlatFilePermissions()) return;
|
||||
|
||||
perms = new ConfigurationPermissionsResolver(config);
|
||||
@ -54,12 +53,16 @@ private boolean tryGroupsUsers() {
|
||||
perms = new GroupUsersPemissionsResolver(server);
|
||||
logger.info(name + ": GroupUsers detected! Using GroupUsers for permissions.");
|
||||
return true;
|
||||
} catch (PluginAccessException e) {
|
||||
return false;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
return false;
|
||||
} catch (MissingPluginException e) {
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tryNijiPermissions() {
|
||||
try {
|
||||
perms = new NijiPermissionsResolver(server);
|
||||
logger.info(name + ": Permissions plugin detected! Using Permissions plugin for permissions.");
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -38,7 +38,9 @@ public PermissionsResolverServerListener(PermissionsResolverManager manager) {
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPluginEnabled(PluginEvent event) {
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("GroupUsers")) {
|
||||
String name = event.getPlugin().getDescription().getName();
|
||||
|
||||
if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) {
|
||||
manager.findResolver();
|
||||
}
|
||||
}
|
||||
@ -49,7 +51,9 @@ public void onPluginEnabled(PluginEvent event) {
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPluginDisabled(PluginEvent event) {
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("GroupUsers")) {
|
||||
String name = event.getPlugin().getDescription().getName();
|
||||
|
||||
if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) {
|
||||
manager.findResolver();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user