1.8.8 Another dumb question

Discussion in 'Spigot Plugin Development' started by Wilsoon, Jan 13, 2020.

Thread Status:
Not open for further replies.
  1. So I have this error:

    Code (Text):
    org.bukkit.plugin.UnknownDependencyException: WorldEdit
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:222) [paper.jar:git-PaperSpigot-"4c7641d"]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:293) [paper.jar:git-PaperSpigot-"4c7641d"]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:202) [paper.jar:git-PaperSpigot-"4c7641d"]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:563) [paper.jar:git-PaperSpigot-"4c7641d"]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]

    I have a depend set in plugin.yml as:

    depend: [Worldedit]

    I have my own code for when it fails to find Worldedit in the plugins. Is it possible for me to make it so that my code loads instead of the UnknownDependencyException?



    My code:

    Code (Java):
    package com.gmail.calorious.wergteleport;

    import org.bukkit.plugin.java.JavaPlugin;

    import org.bukkit.ChatColor;

    import org.bukkit.plugin.PluginDescriptionFile;

    @SuppressWarnings("unused")
    public class Main extends JavaPlugin {
       
        @Override
       public void onEnable() {
       getServer().getPluginManager().registerEvents(new EventHandling(), this);
       getLogger().info(ChatColor.GOLD + "Hooking to WorldEdit...");
       if(getServer().getPluginManager().getPlugin("WorldEdit").isEnabled()) {
           getLogger().info(ChatColor.GREEN + "Sucessfully hooked to Worldedit!");
       }
       else if(getServer().getPluginManager().getPlugin("WorldEdit").isEnabled()) {
               getLogger().info(ChatColor.RED + "Failed to hook to Worldedit!");
               getLogger().info(ChatColor.RED + "This plugin requires Worldedit to function.");
               getLogger().severe(ChatColor.DARK_RED + "STOPPING PLUGIN: " + getDescription().getName());
               getLogger().severe(ChatColor.DARK_RED + "Reason: Dependent Plugin not found.");
               getLogger().severe(ChatColor.DARK_RED + "Required Plugins: " + getDescription().getDepend());
               getPluginLoader().disablePlugin(this);
           }
    }
    }
    // Note: Ignore my tons of stuff there, it's not meant for a public plugin, just my own testing.
     
  2. Is that the full stacktrace?
    Also, PluginManager#getPlugin is nullable
     
    • Useful Useful x 1
  3. A hard dependency as you defined here, will cause this error and will not load your plugin, since the expectation is that your plugin will fail to work when it's loaded without this plugin being present. What you can do however, is define WorldEdit as a soft dependency instead of a hard dependency. That way, WorldEdit will still be loaded before your plugin, however if WorldEdit is not present on the server, your plugin will still be loaded, allowing your code to take over the dependency handling instead of letting Bukkit do this for you.
     
    • Useful Useful x 1
  4. SteelPhoenix

    Moderator

    #onEnable() never gets called if the required dependencies are not on the server. Also Paper is not supported here.
     
    • Like Like x 1
Thread Status:
Not open for further replies.