Plugin Dependencies

Discussion in 'Plugin Development' started by Freelix2000, Dec 6, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Freelix2000

    I am trying to make a plugin with an optional Vault dependency, but one of my flaws as a developer is dependencies. I have never made a plugin that depends on another plugin, and besides adding something to plugin.yml and referring another jar, I don't even know where to start. If someone could please explain just the basic setup for a dependency and how it can be used, that would be nice. =)
     
  2. Offline

    InflamedSebi

    Maybe u already got it to work but here is what i use:

    add this to the plugin.yml:
    if your plugin can't run without it:
    Code:
    depend: [Vault]
    if your plugin can run even without it (just with less features):
    Code:
    softdepend: [Vault]
    in your onEnable:
    Code:java
    1.  
    2. public Economy economy = null;
    3.  
    4. @Override
    5. public void onEnable() {
    6. economy = tryHookEconomy()
    7. }
    8.  
    9. public Economy tryHookEconomy() {
    10. if (economy == null) {
    11. try {
    12. RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
    13. economy = rsp.getProvider();
    14. } catch (Exception e) {
    15. }
    16. log.l(ChatColor.DARK_RED + "Economy not found!", Level.SEVERE, Depth.FEW);
    17. } else
    18. log.l(ChatColor.DARK_GREEN + "Economy was found!", Level.INFO,
    19. Depth.NORMAL);
    20. return economy;
    21. }


    if it fails u can also disable ur own plugin :)

    Code:java
    1.  
    2. getServer().getPluginManager().disablePlugin(this);


    PS: dont mind about my logger ... i just use my own ;)
    hooking into other plugins is slightly easier ... see worldguard:
    Code:java
    1.  
    2. public WorldGuardPlugin tryHookWorldGuard() {
    3. if (worldguard == null) {
    4. try {
    5. worldguard = (WorldGuardPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
    6. } catch (Exception e) {
    7. }
    8. log.l(ChatColor.DARK_RED + "WorldGuard not found, plugin disabled!", Level.SEVERE, Depth.FEW);
    9. } else
    10. log.l(ChatColor.DARK_GREEN + "WorldGuard found, plugin enabled!", Level.INFO, Depth.NORMAL);
    11. return worldguard;
    12. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page