Handles all plugin management from the Server
| 39 | * Handles all plugin management from the Server |
| 40 | */ |
| 41 | public final class SimplePluginManager implements PluginManager { |
| 42 | private final Server server; |
| 43 | private final Map<Pattern, PluginLoader> fileAssociations = new HashMap<Pattern, PluginLoader>(); |
| 44 | private final List<Plugin> plugins = new ArrayList<Plugin>(); |
| 45 | private final Map<String, Plugin> lookupNames = new HashMap<String, Plugin>(); |
| 46 | private final Map<Event.Type, SortedSet<RegisteredListener>> listeners = new EnumMap<Event.Type, SortedSet<RegisteredListener>>(Event.Type.class); |
| 47 | private static File updateDirectory = null; |
| 48 | private final SimpleCommandMap commandMap; |
| 49 | private final Map<String, Permission> permissions = new HashMap<String, Permission>(); |
| 50 | private final Map<Boolean, Set<Permission>> defaultPerms = new LinkedHashMap<Boolean, Set<Permission>>(); |
| 51 | private final Map<String, Map<Permissible, Boolean>> permSubs = new HashMap<String, Map<Permissible, Boolean>>(); |
| 52 | private final Map<Boolean, Map<Permissible, Boolean>> defSubs = new HashMap<Boolean, Map<Permissible, Boolean>>(); |
| 53 | private final Comparator<RegisteredListener> comparer = new Comparator<RegisteredListener>() { |
| 54 | public int compare(RegisteredListener i, RegisteredListener j) { |
| 55 | int result = i.getPriority().compareTo(j.getPriority()); |
| 56 | |
| 57 | if ((result == 0) && (i != j)) { |
| 58 | result = 1; |
| 59 | } |
| 60 | |
| 61 | return result; |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | public SimplePluginManager(Server instance, SimpleCommandMap commandMap) { |
| 66 | server = instance; |
| 67 | this.commandMap = commandMap; |
| 68 | |
| 69 | defaultPerms.put(true, new HashSet<Permission>()); |
| 70 | defaultPerms.put(false, new HashSet<Permission>()); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Registers the specified plugin loader |
| 75 | * |
| 76 | * @param loader Class name of the PluginLoader to register |
| 77 | * @throws IllegalArgumentException Thrown when the given Class is not a valid PluginLoader |
| 78 | */ |
| 79 | public void registerInterface(Class<? extends PluginLoader> loader) throws IllegalArgumentException { |
| 80 | PluginLoader instance; |
| 81 | |
| 82 | if (PluginLoader.class.isAssignableFrom(loader)) { |
| 83 | Constructor<? extends PluginLoader> constructor; |
| 84 | |
| 85 | try { |
| 86 | constructor = loader.getConstructor(Server.class); |
| 87 | instance = constructor.newInstance(server); |
| 88 | } catch (NoSuchMethodException ex) { |
| 89 | String className = loader.getName(); |
| 90 | |
| 91 | throw new IllegalArgumentException(String.format("Class %s does not have a public %s(Server) constructor", className, className), ex); |
| 92 | } catch (Exception ex) { |
| 93 | throw new IllegalArgumentException(String.format("Unexpected exception %s while attempting to construct a new instance of %s", ex.getClass().getName(), loader.getName()), ex); |
| 94 | } |
| 95 | } else { |
| 96 | throw new IllegalArgumentException(String.format("Class %s does not implement interface PluginLoader", loader.getName())); |
| 97 | } |
| 98 |
nothing calls this directly
no outgoing calls
no test coverage detected