This method provides fast access to the plugin that has #getProvidingPlugin(Class) provided the given plugin class, which is usually the plugin that implemented it. An exception to this would be if plugin's jar that contained the class does not extend the class, where the intended plugin
(@NotNull Class<T> clazz)
| 381 | * extend the class |
| 382 | */ |
| 383 | @NotNull |
| 384 | public static <T extends JavaPlugin> T getPlugin(@NotNull Class<T> clazz) { |
| 385 | Validate.notNull(clazz, "Null class cannot have a plugin"); |
| 386 | if (!JavaPlugin.class.isAssignableFrom(clazz)) { |
| 387 | throw new IllegalArgumentException(clazz + " does not extend " + JavaPlugin.class); |
| 388 | } |
| 389 | final ClassLoader cl = clazz.getClassLoader(); |
| 390 | if (!(cl instanceof PluginClassLoader)) { |
| 391 | throw new IllegalArgumentException(clazz + " is not initialized by " + PluginClassLoader.class); |
| 392 | } |
| 393 | JavaPlugin plugin = ((PluginClassLoader) cl).plugin; |
| 394 | if (plugin == null) { |
| 395 | throw new IllegalStateException("Cannot get plugin for " + clazz + " from a static initializer"); |
| 396 | } |
| 397 | return clazz.cast(plugin); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * This method provides fast access to the plugin that has provided the |
nothing calls this directly
no test coverage detected