mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-16 22:03:53 +00:00
More file moving.
This commit is contained in:
@ -0,0 +1,130 @@
|
||||
// $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 java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||
private Configuration config;
|
||||
private Map<String,Set<String>> userPermissionsCache;
|
||||
private Set<String> defaultPermissionsCache;
|
||||
private Map<String,Set<String>> userGroups;
|
||||
|
||||
public ConfigurationPermissionsResolver(Configuration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
userGroups = new HashMap<String,Set<String>>();
|
||||
userPermissionsCache = new HashMap<String,Set<String>>();
|
||||
defaultPermissionsCache = new HashSet<String>();
|
||||
|
||||
Map<String,Set<String>> userGroupPermissions = new HashMap<String,Set<String>>();
|
||||
|
||||
List<String> groupKeys = config.getKeys("permissions.groups");
|
||||
|
||||
if (groupKeys != null) {
|
||||
for (String key : groupKeys) {
|
||||
List<String> permissions =
|
||||
config.getStringList("permissions.groups." + key + ".permissions", null);
|
||||
|
||||
if (permissions.size() > 0) {
|
||||
Set<String> groupPerms = new HashSet<String>(permissions);
|
||||
userGroupPermissions.put(key, groupPerms);
|
||||
|
||||
if (key.equals("default")) {
|
||||
defaultPermissionsCache.addAll(permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> userKeys = config.getKeys("permissions.users");
|
||||
|
||||
if (userKeys != null) {
|
||||
for (String key : userKeys) {
|
||||
Set<String> permsCache = new HashSet<String>();
|
||||
|
||||
List<String> permissions =
|
||||
config.getStringList("permissions.users." + key + ".permissions", null);
|
||||
|
||||
if (permissions.size() > 0) {
|
||||
permsCache.addAll(permissions);
|
||||
}
|
||||
|
||||
List<String> groups =
|
||||
config.getStringList("permissions.users." + key + ".groups", null);
|
||||
groups.add("default");
|
||||
|
||||
if (groups.size() > 0) {
|
||||
for (String group : groups) {
|
||||
Set<String> groupPerms = userGroupPermissions.get(group);
|
||||
if (groupPerms != null) {
|
||||
permsCache.addAll(groupPerms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userPermissionsCache.put(key.toLowerCase(), permsCache);
|
||||
userGroups.put(key.toLowerCase(), new HashSet<String>(groups));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPermission(String player, String permission) {
|
||||
int dotPos = permission.lastIndexOf(".");
|
||||
if (dotPos > -1) {
|
||||
if (hasPermission(player, permission.substring(0, dotPos))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
|
||||
if (perms == null) {
|
||||
return defaultPermissionsCache.contains(permission)
|
||||
|| defaultPermissionsCache.contains("*");
|
||||
}
|
||||
|
||||
return perms.contains("*") || perms.contains(permission);
|
||||
}
|
||||
|
||||
public boolean inGroup(String player, String group) {
|
||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||
if (groups == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return groups.contains(group);
|
||||
}
|
||||
|
||||
public String[] getGroups(String player) {
|
||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||
if (groups == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
return groups.toArray(new String[groups.size()]);
|
||||
}
|
||||
}
|
@ -0,0 +1,189 @@
|
||||
// $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 java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class FlatFilePermissionsResolver implements PermissionsResolver {
|
||||
private Map<String,Set<String>> userPermissionsCache;
|
||||
private Set<String> defaultPermissionsCache;
|
||||
private Map<String,Set<String>> userGroups;
|
||||
|
||||
public FlatFilePermissionsResolver() {
|
||||
}
|
||||
|
||||
public static boolean filesExists() {
|
||||
return (new File("perms_groups.txt")).exists()
|
||||
&& (new File("perms_users.txt")).exists();
|
||||
}
|
||||
|
||||
public Map<String,Set<String>> loadGroupPermissions() {
|
||||
Map<String,Set<String>> userGroupPermissions = new HashMap<String,Set<String>>();
|
||||
|
||||
File file = new File("perms_groups.txt");
|
||||
FileReader input = null;
|
||||
|
||||
try {
|
||||
input = new FileReader(file);
|
||||
BufferedReader buff = new BufferedReader(input);
|
||||
|
||||
String line;
|
||||
while ((line = buff.readLine()) != null) {
|
||||
line = line.trim();
|
||||
|
||||
// Blank line
|
||||
if (line.length() == 0) {
|
||||
continue;
|
||||
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] parts = line.split(":");
|
||||
|
||||
String key = parts[0];
|
||||
|
||||
if (parts.length > 1) {
|
||||
String[] perms = parts[1].split(",");
|
||||
|
||||
Set<String> groupPerms = new HashSet<String>(Arrays.asList(perms));
|
||||
userGroupPermissions.put(key, groupPerms);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
}
|
||||
}
|
||||
|
||||
return userGroupPermissions;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
userGroups = new HashMap<String,Set<String>>();
|
||||
userPermissionsCache = new HashMap<String,Set<String>>();
|
||||
defaultPermissionsCache = new HashSet<String>();
|
||||
|
||||
Map<String,Set<String>> userGroupPermissions = loadGroupPermissions();
|
||||
|
||||
if (userGroupPermissions.containsKey("default")) {
|
||||
defaultPermissionsCache = userGroupPermissions.get("default");
|
||||
}
|
||||
|
||||
File file = new File("perms_users.txt");
|
||||
FileReader input = null;
|
||||
|
||||
try {
|
||||
input = new FileReader(file);
|
||||
BufferedReader buff = new BufferedReader(input);
|
||||
|
||||
String line;
|
||||
while ((line = buff.readLine()) != null) {
|
||||
Set<String> permsCache = new HashSet<String>();
|
||||
|
||||
line = line.trim();
|
||||
|
||||
// Blank line
|
||||
if (line.length() == 0) {
|
||||
continue;
|
||||
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] parts = line.split(":");
|
||||
|
||||
String key = parts[0];
|
||||
|
||||
if (parts.length > 1) {
|
||||
String[] groups = (parts[1] + ",default").split(",");
|
||||
String[] perms = parts.length > 2 ? parts[2].split(",") : new String[0];
|
||||
|
||||
permsCache.addAll(Arrays.asList(perms));
|
||||
|
||||
for (String group : groups) {
|
||||
Set<String> groupPerms = userGroupPermissions.get(group);
|
||||
if (groupPerms != null) {
|
||||
permsCache.addAll(groupPerms);
|
||||
}
|
||||
}
|
||||
|
||||
userPermissionsCache.put(key.toLowerCase(), permsCache);
|
||||
userGroups.put(key.toLowerCase(), new HashSet<String>(Arrays.asList(groups)));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPermission(String player, String permission) {
|
||||
int dotPos = permission.lastIndexOf(".");
|
||||
if (dotPos > -1) {
|
||||
if (hasPermission(player, permission.substring(0, dotPos))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
|
||||
if (perms == null) {
|
||||
return defaultPermissionsCache.contains(permission)
|
||||
|| defaultPermissionsCache.contains("*");
|
||||
}
|
||||
|
||||
return perms.contains("*") || perms.contains(permission);
|
||||
}
|
||||
|
||||
public boolean inGroup(String player, String group) {
|
||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||
if (groups == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return groups.contains(group);
|
||||
}
|
||||
|
||||
public String[] getGroups(String player) {
|
||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||
if (groups == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
return groups.toArray(new String[groups.size()]);
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
// $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;
|
||||
try {
|
||||
return api.getHandler().has(player, permission);
|
||||
} catch (Throwable t) {
|
||||
return api.Security.permission(player, permission);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "static-access", "deprecation" })
|
||||
public boolean inGroup(String name, String group) {
|
||||
try {
|
||||
Player player = server.getPlayer(name);
|
||||
if (player == null) return false;
|
||||
try {
|
||||
return api.getHandler().inGroup(player.getWorld().getName(), name, group);
|
||||
} catch (Throwable t) {
|
||||
return api.Security.inGroup(name, group);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "static-access", "deprecation" })
|
||||
public String[] getGroups(String name) {
|
||||
try {
|
||||
Player player = server.getPlayer(name);
|
||||
if (player == null) return new String[0];
|
||||
String group;
|
||||
try {
|
||||
group = api.getHandler().getGroup(player.getWorld().getName(), player.getName());
|
||||
} catch (Throwable t) {
|
||||
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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// $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;
|
||||
|
||||
public interface PermissionsResolver {
|
||||
public void load();
|
||||
public boolean hasPermission(String name, String permission);
|
||||
public boolean inGroup(String player, String group);
|
||||
public String[] getGroups(String player);
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
// $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 java.util.logging.Logger;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
public class PermissionsResolverManager implements PermissionsResolver {
|
||||
private Configuration config;
|
||||
private Server server;
|
||||
private PermissionsResolver perms;
|
||||
private String name;
|
||||
private Logger logger;
|
||||
|
||||
public PermissionsResolverManager(Configuration config, Server server, String name, Logger logger) {
|
||||
this.config = config;
|
||||
this.server = server;
|
||||
this.name = name;
|
||||
this.logger = logger;
|
||||
|
||||
findResolver();
|
||||
}
|
||||
|
||||
public void findResolver() {
|
||||
if (tryPluginPermissionsResolver()) return;
|
||||
if (tryNijiPermissions()) return;
|
||||
if (tryFlatFilePermissions()) return;
|
||||
|
||||
perms = new ConfigurationPermissionsResolver(config);
|
||||
logger.info(name + ": No known permissions plugin detected. Using configuration file for permissions.");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tryFlatFilePermissions() {
|
||||
if (FlatFilePermissionsResolver.filesExists()) {
|
||||
perms = new FlatFilePermissionsResolver();
|
||||
logger.info(name + ": perms_groups.txt and perms_users.txt detected! Using flat file permissions.");
|
||||
return true;
|
||||
}
|
||||
|
||||
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() {
|
||||
perms.load();
|
||||
}
|
||||
|
||||
public boolean hasPermission(String name, String permission) {
|
||||
return perms.hasPermission(name, permission);
|
||||
}
|
||||
|
||||
public boolean inGroup(String player, String group) {
|
||||
return perms.inGroup(player, group);
|
||||
}
|
||||
|
||||
public String[] getGroups(String player) {
|
||||
return perms.getGroups(player);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
// $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.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.ServerListener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class PermissionsResolverServerListener extends ServerListener {
|
||||
private PermissionsResolverManager manager;
|
||||
|
||||
public PermissionsResolverServerListener(PermissionsResolverManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a plugin is enabled
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
Plugin plugin = event.getPlugin();
|
||||
String name = plugin.getDescription().getName();
|
||||
|
||||
if (plugin instanceof PermissionsProvider) {
|
||||
manager.setPluginPermissionsResolver(plugin);
|
||||
} else if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) {
|
||||
manager.findResolver();
|
||||
manager.load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a plugin is disabled
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
Plugin plugin = event.getPlugin();
|
||||
String name = plugin.getDescription().getName();
|
||||
|
||||
if (plugin instanceof PermissionsProvider
|
||||
|| name.equalsIgnoreCase("GroupUsers")
|
||||
|| name.equalsIgnoreCase("Permissions")) {
|
||||
manager.findResolver();
|
||||
manager.load();
|
||||
}
|
||||
}
|
||||
|
||||
public void register(Plugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE,
|
||||
this, Priority.Normal, plugin);
|
||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_DISABLE,
|
||||
this, Priority.Normal, plugin);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// $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;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
}
|
||||
|
||||
public boolean hasPermission(String name, String permission) {
|
||||
return resolver.hasPermission(name, permission);
|
||||
}
|
||||
|
||||
public boolean inGroup(String player, String group) {
|
||||
return resolver.inGroup(player, group);
|
||||
}
|
||||
|
||||
public String[] getGroups(String player) {
|
||||
return resolver.getGroups(player);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user