MCPcopy Create free account
hub / github.com/Teneted/Tenet / getPlugin

Method getPlugin

src/main/java/org/bukkit/plugin/java/JavaPlugin.java:383–398  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

getClassLoaderMethod · 0.80
castMethod · 0.80

Tested by

no test coverage detected