diff --git a/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java index 856e9ab72..3919241d7 100644 --- a/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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> userPermissionsCache; + private Map> userPermissionsCache; private Set defaultPermissionsCache; - private Map> userGroups; - + private Map> 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>(); - userPermissionsCache = new HashMap>(); + userGroups = new HashMap>(); + userPermissionsCache = new HashMap>(); defaultPermissionsCache = new HashSet(); - Map> userGroupPermissions = new HashMap>(); - + Map> userGroupPermissions = new HashMap>(); + List groupKeys = config.getKeys("permissions.groups"); - + if (groupKeys != null) { for (String key : groupKeys) { List permissions = config.getStringList("permissions.groups." + key + ".permissions", null); - + if (permissions.size() > 0) { Set groupPerms = new HashSet(permissions); userGroupPermissions.put(key, groupPerms); - + if (key.equals("default")) { defaultPermissionsCache.addAll(permissions); } } } } - + List userKeys = config.getKeys("permissions.users"); if (userKeys != null) { for (String key : userKeys) { Set permsCache = new HashSet(); - + List permissions = config.getStringList("permissions.users." + key + ".permissions", null); - + if (permissions.size() > 0) { permsCache.addAll(permissions); } - + List groups = config.getStringList("permissions.users." + key + ".groups", null); groups.add("default"); - + if (groups.size() > 0) { for (String group : groups) { Set 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 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 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."; } - + } diff --git a/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java b/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java index 16647f9e9..949143449 100644 --- a/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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."; } - - + } diff --git a/src/main/java/com/sk89q/bukkit/migration/FlatFilePermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/FlatFilePermissionsResolver.java index cc7077f7e..76f1c9cf6 100644 --- a/src/main/java/com/sk89q/bukkit/migration/FlatFilePermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/FlatFilePermissionsResolver.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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> userPermissionsCache; + private Map> userPermissionsCache; private Set defaultPermissionsCache; - private Map> userGroups; - + private Map> 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> loadGroupPermissions() { - Map> userGroupPermissions = new HashMap>(); + + public Map> loadGroupPermissions() { + Map> userGroupPermissions = new HashMap>(); 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>(); - userPermissionsCache = new HashMap>(); + userGroups = new HashMap>(); + userPermissionsCache = new HashMap>(); defaultPermissionsCache = new HashSet(); - Map> userGroupPermissions = loadGroupPermissions(); - + Map> 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 permsCache = new HashSet(); - + 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 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 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."; } - + } diff --git a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java index 428d082e3..5ae15addf 100644 --- a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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)); } diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java index d7b02a955..bad0ee2a3 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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; diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java index a95f9324d..04688e9bf 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ package com.sk89q.bukkit.migration; diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolver.java index 7027dc0f4..f2f7c339e 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolver.java @@ -15,12 +15,12 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ package com.sk89q.bukkit.migration; public interface PermissionsResolver extends PermissionsProvider { public void load(); - + public String getDetectionMessage(); } diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java index 68ebd076a..90408cbf7 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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[] availableResolvers = new Class[]{ + + protected Class[] 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 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"; - } + } } diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java index 5d88d17e1..1cee1a587 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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); } - - + } diff --git a/src/main/java/com/sk89q/bukkit/migration/PluginPermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/PluginPermissionsResolver.java index 0bdfcb168..10a957a52 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PluginPermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/PluginPermissionsResolver.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ 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 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."; } - + }