Java Code Examples for org.bukkit.plugin.java.JavaPlugin#getProvidingPlugin()
The following examples show how to use
org.bukkit.plugin.java.JavaPlugin#getProvidingPlugin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoaderUtils.java From helper with MIT License | 6 votes |
@Nonnull public static synchronized HelperPlugin getPlugin() { if (plugin == null) { JavaPlugin pl = JavaPlugin.getProvidingPlugin(LoaderUtils.class); if (!(pl instanceof HelperPlugin)) { throw new IllegalStateException("helper providing plugin does not implement HelperPlugin: " + pl.getClass().getName()); } plugin = (HelperPlugin) pl; String pkg = LoaderUtils.class.getPackage().getName(); pkg = pkg.substring(0, pkg.length() - ".internal".length()); Bukkit.getLogger().info("[helper] helper (" + pkg + ") bound to plugin " + plugin.getName() + " - " + plugin.getClass().getName()); setup(); } return plugin; }
Example 2
Source File: GuiListener.java From IF with The Unlicense | 6 votes |
/** * Handles the disabling of the plugin * * @param event the event fired * @since 0.5.19 */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPluginDisable(@NotNull PluginDisableEvent event) { Plugin thisPlugin = JavaPlugin.getProvidingPlugin(getClass()); if (event.getPlugin() != thisPlugin) { return; } int counter = 0; //callbacks might open GUIs, eg. in nested menus int maxCount = 10; while (!activeGuiInstances.isEmpty() && counter++ < maxCount) { for (Gui gui : new ArrayList<>(activeGuiInstances)) { for (HumanEntity viewer : gui.getViewers()) { viewer.closeInventory(); } } } if (counter == maxCount) { thisPlugin.getLogger().warning("Unable to close GUIs on plugin disable: they keep getting opened " + "(tried: " + maxCount + " times)"); } }
Example 3
Source File: BukkitPluginResolver.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public @Nullable Plugin getImplicitProvidingPlugin(Class<?> cls) { try { return JavaPlugin.getProvidingPlugin(cls); } catch(IllegalArgumentException e) { return null; } }
Example 4
Source File: BlockingActionManager.java From LagMonitor with MIT License | 5 votes |
public Map.Entry<String, StackTraceElement> findPlugin(StackTraceElement[] stacktrace) { boolean skipping = true; for (StackTraceElement elem : stacktrace) { try { Class<?> clazz = Class.forName(elem.getClassName()); if (clazz.getName().endsWith("VanillaCommandWrapper")) { //explicit use getName instead of SimpleName because getSimpleBinaryName causes a //StringIndexOutOfBoundsException for obfuscated plugins return Maps.immutableEntry("Vanilla", elem); } Plugin plugin; try { plugin = JavaPlugin.getProvidingPlugin(clazz); if (plugin == this.plugin) { continue; } return Maps.immutableEntry(plugin.getName(), elem); } catch (IllegalArgumentException illegalArgumentEx) { //ignore } } catch (ClassNotFoundException ex) { //if this class cannot be loaded then it could be something native so we ignore it } } return null; }
Example 5
Source File: BlockingActionManager.java From LagMonitor with MIT License | 5 votes |
public Map.Entry<String, StackTraceElement> findPlugin(StackTraceElement[] stacktrace) { boolean skipping = true; for (StackTraceElement elem : stacktrace) { try { Class<?> clazz = Class.forName(elem.getClassName()); if (clazz.getName().endsWith("VanillaCommandWrapper")) { //explicit use getName instead of SimpleName because getSimpleBinaryName causes a //StringIndexOutOfBoundsException for obfuscated plugins return Maps.immutableEntry("Vanilla", elem); } Plugin plugin; try { plugin = JavaPlugin.getProvidingPlugin(clazz); if (plugin == this.plugin) { continue; } return Maps.immutableEntry(plugin.getName(), elem); } catch (IllegalArgumentException illegalArgumentEx) { //ignore } } catch (ClassNotFoundException ex) { //if this class cannot be loaded then it could be something native so we ignore it } } return null; }
Example 6
Source File: Gui.java From IF with The Unlicense | 4 votes |
/** * Loads a Gui from a given input stream. * Throws a {@link RuntimeException} instead of returning null in case of a failure. * * @param instance the class instance for all reflection lookups * @param inputStream the file * @return the gui * @see #load(Object, InputStream) */ @NotNull public static Gui loadOrThrow(@NotNull Object instance, @NotNull InputStream inputStream) { Plugin plugin = JavaPlugin.getProvidingPlugin(Gui.class); try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); Gui gui = new Gui(plugin, Integer.parseInt(documentElement.getAttribute("rows")), ChatColor .translateAlternateColorCodes('&', documentElement.getAttribute("title"))); if (documentElement.hasAttribute("field")) XMLUtil.loadFieldAttribute(instance, documentElement, gui); if (documentElement.hasAttribute("onTopClick")) { gui.setOnTopClick(XMLUtil.loadOnEventAttribute(instance, documentElement, InventoryClickEvent.class, "onTopClick")); } if (documentElement.hasAttribute("onBottomClick")) { gui.setOnBottomClick(XMLUtil.loadOnEventAttribute(instance, documentElement, InventoryClickEvent.class, "onBottomClick")); } if (documentElement.hasAttribute("onGlobalClick")) { gui.setOnGlobalClick(XMLUtil.loadOnEventAttribute(instance, documentElement, InventoryClickEvent.class, "onGlobalClick")); } if (documentElement.hasAttribute("onOutsideClick")) { gui.setOnOutsideClick(XMLUtil.loadOnEventAttribute(instance, documentElement, InventoryClickEvent.class, "onOutsideClick")); } if (documentElement.hasAttribute("onClose")) { gui.setOnClose(XMLUtil.loadOnEventAttribute(instance, documentElement, InventoryCloseEvent.class, "onClose")); } if (documentElement.hasAttribute("populate")) { MethodUtils.invokeExactMethod(instance, "populate", gui, Gui.class); } else { NodeList childNodes = documentElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); if (item.getNodeType() == Node.ELEMENT_NODE) gui.addPane(loadPane(instance, item)); } } return gui; } catch (Exception e) { throw new XMLLoadException("Error loading " + plugin.getName() + "'s gui with associated class: " + instance.getClass().getSimpleName(), e); } }
Example 7
Source File: AbstractVaultPermission.java From LuckPerms with MIT License | 4 votes |
public AbstractVaultPermission() { super.plugin = JavaPlugin.getProvidingPlugin(Permission.class); }
Example 8
Source File: PlayerTracker.java From MineCloud with ISC License | 4 votes |
PlayerTracker() { this.plugin = (MineCloudPlugin) JavaPlugin.getProvidingPlugin(PlayerTracker.class); }