Cleanup formatting.

This commit is contained in:
Wizjany 2011-09-27 03:32:46 -04:00
parent 4f80e78a7e
commit 2d7c462477
10 changed files with 141 additions and 144 deletions

View File

@ -15,7 +15,7 @@
*
* 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;
@ -28,10 +28,10 @@ import org.bukkit.util.config.Configuration;
public class ConfigurationPermissionsResolver implements PermissionsResolver {
private Configuration config;
private Map<String,Set<String>> userPermissionsCache;
private Map<String, Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String,Set<String>> userGroups;
private Map<String, Set<String>> userGroups;
public ConfigurationPermissionsResolver(Configuration config) {
this.config = config;
}
@ -44,50 +44,51 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
config.setProperty("permissions.groups.admins.permissions", new String[]{"*"});
config.setProperty("permissions.users.sk89q.permissions", new String[]{"worldedit.*"});
config.setProperty("permissions.users.sk89q.groups", new String[]{"admins"});
}
public void load() {
userGroups = new HashMap<String,Set<String>>();
userPermissionsCache = new HashMap<String,Set<String>>();
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>>();
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);
@ -102,7 +103,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
}
}
}
public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
@ -110,19 +111,19 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);
return perms.contains("*") || perms.contains(permission);
}
public boolean hasPermission(String worldName, String player, String permission) {
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
}
public boolean inGroup(String player, String group) {
@ -130,21 +131,21 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
if (groups == null) {
return false;
}
return groups.contains(group);
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()]);
return groups.toArray(new String[groups.size()]);
}
public String getDetectionMessage() {
return "No known permissions plugin detected. Using configuration file for permissions.";
}
}

View File

@ -15,7 +15,7 @@
*
* 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;
@ -35,15 +35,15 @@ public class DinnerPermsResolver implements PermissionsResolver {
public DinnerPermsResolver(Server server) {
this.server = server;
}
public static PermissionsResolver factory(Server server, Configuration config) {
if(!config.getBoolean("dinnerperms", true)){
if (!config.getBoolean("dinnerperms", true)) {
return null;
}
return new DinnerPermsResolver(server);
}
}
public void load() {
// Permissions are already loaded
}
@ -97,6 +97,5 @@ public class DinnerPermsResolver implements PermissionsResolver {
public String getDetectionMessage() {
return "Using the Bukkit Permissions API.";
}
}

View File

@ -15,7 +15,7 @@
*
* 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;
@ -32,40 +32,40 @@ import org.bukkit.Server;
import org.bukkit.util.config.Configuration;
public class FlatFilePermissionsResolver implements PermissionsResolver {
private Map<String,Set<String>> userPermissionsCache;
private Map<String, Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String,Set<String>> userGroups;
private Map<String, Set<String>> userGroups;
protected File groupFile;
protected File userFile;
public static PermissionsResolver factory(Server server, Configuration config){
public static PermissionsResolver factory(Server server, Configuration config) {
File groups = new File("perms_groups.txt");
File users = new File("perms_users.txt");
if(!groups.exists() || !users.exists()){
File users = new File("perms_users.txt");
if (!groups.exists() || !users.exists()) {
return null;
}
return new FlatFilePermissionsResolver(groups, users);
}
public FlatFilePermissionsResolver(){
public FlatFilePermissionsResolver() {
this(new File("perms_groups.txt"), new File("perms_users.txt"));
}
public FlatFilePermissionsResolver(File groupFile, File userFile) {
this.groupFile = groupFile;
this.userFile = userFile;
}
@Deprecated
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>>();
public Map<String, Set<String>> loadGroupPermissions() {
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
FileReader input = null;
@ -83,11 +83,11 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
} 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(",");
@ -105,17 +105,17 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
} catch (IOException e2) {
}
}
return userGroupPermissions;
}
public void load() {
userGroups = new HashMap<String,Set<String>>();
userPermissionsCache = new HashMap<String,Set<String>>();
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
Map<String,Set<String>> userGroupPermissions = loadGroupPermissions();
Map<String, Set<String>> userGroupPermissions = loadGroupPermissions();
if (userGroupPermissions.containsKey("default")) {
defaultPermissionsCache = userGroupPermissions.get("default");
}
@ -129,7 +129,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
String line;
while ((line = buff.readLine()) != null) {
Set<String> permsCache = new HashSet<String>();
line = line.trim();
// Blank line
@ -138,11 +138,11 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
} 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];
@ -171,7 +171,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
}
}
}
public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
@ -179,19 +179,19 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);
return perms.contains("*") || perms.contains(permission);
}
public boolean hasPermission(String worldName, String player, String permission) {
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
}
public boolean inGroup(String player, String group) {
@ -199,21 +199,21 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
if (groups == null) {
return false;
}
return groups.contains(group);
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()]);
return groups.toArray(new String[groups.size()]);
}
public String getDetectionMessage() {
return "perms_groups.txt and perms_users.txt detected! Using flat file permissions.";
}
}

View File

@ -15,7 +15,7 @@
*
* 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;
@ -31,29 +31,29 @@ import org.bukkit.util.config.Configuration;
public class NijiPermissionsResolver implements PermissionsResolver {
private Server server;
private Permissions api;
public static PermissionsResolver factory(Server server, Configuration config) {
PluginManager pluginManager = server.getPluginManager();
Plugin plugin = pluginManager.getPlugin("Permissions");
// Check if plugin is loaded and have Permissions interface
if(plugin == null || !(plugin instanceof Permissions)){
if (plugin == null || !(plugin instanceof Permissions)) {
return null;
}
// Check for fake permissions
if(config.getBoolean("ignore-nijiperms-bridges", true) && isFakeNijiPerms(plugin)){
if (config.getBoolean("ignore-nijiperms-bridges", true) && isFakeNijiPerms(plugin)) {
return null;
}
return new NijiPermissionsResolver(server, (Permissions)plugin);
return new NijiPermissionsResolver(server, (Permissions) plugin);
}
public void load() {
}
public NijiPermissionsResolver(Server server, Permissions plugin) {
this.server = server;
this.api = plugin;
@ -88,7 +88,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
}
}
@SuppressWarnings({ "static-access" })
@SuppressWarnings("static-access")
public boolean inGroup(String name, String group) {
try {
Player player = server.getPlayer(name);
@ -104,7 +104,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
}
}
@SuppressWarnings({ "static-access" })
@SuppressWarnings("static-access")
public String[] getGroups(String name) {
try {
Player player = server.getPlayer(name);
@ -114,8 +114,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
groups = api.getHandler().getGroups(player.getWorld().getName(), player.getName());
} catch (Throwable t) {
String group = api.Security.getGroup(player.getWorld().getName(), player.getName());
if (group != null)
groups = new String[] {group};
if (group != null) groups = new String[] { group };
}
if (groups == null) {
return new String[0];
@ -127,7 +126,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
return new String[0];
}
}
public static class PluginAccessException extends Exception {
private static final long serialVersionUID = 7044832912491608706L;
}
@ -143,10 +142,10 @@ public class NijiPermissionsResolver implements PermissionsResolver {
}
return permsCommand.getPlugin().getDescription().getName().equals("Permissions");
}
public static boolean isFakeNijiPerms(Plugin plugin){
public static boolean isFakeNijiPerms(Plugin plugin) {
PluginCommand permsCommand = Bukkit.getServer().getPluginCommand("permissions");
return !(permsCommand.getPlugin().equals(plugin));
}

View File

@ -15,7 +15,7 @@
*
* 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;
@ -30,17 +30,17 @@ import org.bukkit.util.config.Configuration;
public class PermissionsExResolver implements PermissionsResolver {
private final PermissionManager manager;
private final Server server;
public static PermissionsResolver factory(Server server, Configuration config){
public static PermissionsResolver factory(Server server, Configuration config) {
PermissionManager manager = server.getServicesManager().load(PermissionManager.class);
if(manager == null){
if (manager == null) {
return null;
}
return new PermissionsExResolver(server, manager);
}
public PermissionsExResolver(Server server, PermissionManager manager) {
this.server = server;
this.manager = manager;

View File

@ -15,7 +15,7 @@
*
* 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;

View File

@ -15,12 +15,12 @@
*
* 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 extends PermissionsProvider {
public void load();
public String getDetectionMessage();
}

View File

@ -15,7 +15,7 @@
*
* 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;
@ -58,8 +58,8 @@ public class PermissionsResolverManager implements PermissionsResolver {
private Configuration config;
private String name;
private Logger logger;
protected Class<? extends PermissionsResolver>[] availableResolvers = new Class[]{
protected Class<? extends PermissionsResolver>[] availableResolvers = new Class[] {
PluginPermissionsResolver.class,
PermissionsExResolver.class,
NijiPermissionsResolver.class,
@ -81,19 +81,19 @@ public class PermissionsResolverManager implements PermissionsResolver {
this.name = name;
this.logger = logger;
this.listener = new PermissionsResolverServerListener(this, plugin);
loadConfig(new File("wepif.yml"));
findResolver();
}
public void findResolver() {
for (Class resolverClass : availableResolvers){
for (Class resolverClass : availableResolvers) {
try {
Method factoryMethod = resolverClass.getMethod("factory", Server.class, Configuration.class);
this.permissionResolver = (PermissionsResolver)factoryMethod.invoke(null, this.server, this.config);
if(this.permissionResolver != null){
this.permissionResolver = (PermissionsResolver) factoryMethod.invoke(null, this.server, this.config);
if (this.permissionResolver != null) {
logger.info(name + ": " + this.permissionResolver.getDetectionMessage());
return;
}
@ -105,12 +105,12 @@ public class PermissionsResolverManager implements PermissionsResolver {
permissionResolver = new ConfigurationPermissionsResolver(config);
logger.info(name + ": No known permissions plugin detected. Using configuration file for permissions.");
}
public void setPluginPermissionsResolver(Plugin plugin) {
if (!(plugin instanceof PermissionsProvider)) {
return;
}
permissionResolver = new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
logger.info(name + ": Using plugin '" + plugin.getDescription().getName() + "' for permissions.");
}
@ -147,7 +147,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
config = new Configuration(file);
config.load();
List<String> keys = config.getKeys();
config.setHeader(CONFIG_HEADER);
config.setHeader(CONFIG_HEADER);
if (!keys.contains("dinnerperms")) {
config.setProperty("dinnerperms", config.getBoolean("dinner-perms", true));
isUpdated = true;
@ -156,7 +156,6 @@ public class PermissionsResolverManager implements PermissionsResolver {
config.setProperty("ignore-nijiperms-bridges", true);
isUpdated = true;
}
if (keys.contains("dinner-perms")) {
config.removeProperty("dinner-perms");
isUpdated = true;
@ -179,13 +178,13 @@ public class PermissionsResolverManager implements PermissionsResolver {
void setServerListener(PermissionsResolverServerListener listener) {
this.listener = listener;
}
public static class MissingPluginException extends Exception {
private static final long serialVersionUID = 7044832912491608706L;
}
public String getDetectionMessage() {
return "Using WEPIF for permissions";
}
}
}

View File

@ -15,7 +15,7 @@
*
* 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;
@ -40,7 +40,7 @@ public class PermissionsResolverServerListener extends ServerListener {
register(plugin);
}
}
/**
* Called when a plugin is enabled
*
@ -67,13 +67,13 @@ public class PermissionsResolverServerListener extends ServerListener {
public void onPluginDisable(PluginDisableEvent event) {
Plugin plugin = event.getPlugin();
String name = plugin.getDescription().getName();
if (plugin instanceof PermissionsProvider || "Permissions".equals(name) || "PermissionsEx".equals(name)) {
manager.findResolver();
manager.load();
}
}
public void register(Plugin plugin) {
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE,
this, Priority.Normal, plugin);
@ -81,6 +81,5 @@ public class PermissionsResolverServerListener extends ServerListener {
this, Priority.Normal, plugin);
manager.setServerListener(this);
}
}

View File

@ -15,7 +15,7 @@
*
* 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;
@ -25,31 +25,31 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.util.config.Configuration;
public class PluginPermissionsResolver implements PermissionsResolver {
protected PermissionsProvider resolver;
protected Plugin plugin;
public static PermissionsResolver factory(Server server, Configuration config){
public static PermissionsResolver factory(Server server, Configuration config) {
// Looking for service
RegisteredServiceProvider<PermissionsProvider> serviceProvider = server.getServicesManager().getRegistration(PermissionsProvider.class);
if(serviceProvider != null){
if (serviceProvider != null) {
return new PluginPermissionsResolver(serviceProvider.getProvider(), serviceProvider.getPlugin());
}
// Looking for plugin
for (Plugin plugin : server.getPluginManager().getPlugins()) {
if(plugin instanceof PermissionsProvider){
return new PluginPermissionsResolver((PermissionsProvider)plugin, plugin);
if (plugin instanceof PermissionsProvider) {
return new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
}
}
}
return null;
}
public PluginPermissionsResolver(PermissionsProvider resolver, Plugin permissionsPlugin) {
this.resolver = resolver;
this.plugin = permissionsPlugin;
this.plugin = permissionsPlugin;
}
public void load() {
@ -74,5 +74,5 @@ public class PluginPermissionsResolver implements PermissionsResolver {
public String getDetectionMessage() {
return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions.";
}
}