How to use Factions as a soft depend

Discussion in 'Plugin Development' started by EnderTroll68, Aug 3, 2014.

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

    EnderTroll68

    Hello!

    I have this code:
    Code:java
    1. if (hasFactions)
    2. Bukkit.getPluginManager().registerEvents(new InteractListener(), this);
    3. else
    4. Bukkit.getPluginManager().registerEvents(new FactInteractListener(), this);

    but whenever I use that it causes a dependency error even though the second else statement should not run. How do I handle this?
     
  2. Offline

    SmooshCakez

    To add something as a depend, write one of these in your plugin.yml:
    Code:
    softdepend: [Factions]
    depend: [Factions]
     
  3. Offline

    EnderTroll68

    Yeah I do that and it still gives me the following stack trace:
    Code:
    [18:06:23] [Server thread/ERROR]: Error occurred while enabling BountyMerchant v1.01 (Is it up to date?)
    java.lang.NoClassDefFoundError: com/massivecraft/factions/RelationParticipator
        at com.vimal.bountymerchant.Main.onEnable(Main.java:36) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.java:446) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.java:380) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.reload(CraftServer.java:799) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.Bukkit.reload(Bukkit.java:288) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:701) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:956) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.ClassNotFoundException: com.massivecraft.factions.RelationParticipator
        at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_55]
        at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_55]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:1.7.0_55]
        at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.7.0_55]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:77) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_55]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_55]
        ... 22 more
     
  4. Offline

    SmooshCakez

    Do you get any errors in your editor with your written code? If not, can you show the full code?
     
  5. Offline

    EnderTroll68

    I do not get any errors in my code.

    The part of the code that is relevant is the following:

    if (this.getServer().getPluginManager().isPluginEnabled("Factions"))
    hasFactions = true;

    and the code in the first post in this thread.

    That statement works just fine, as well as the else and if statement. My problem is when the plugin starts it reads the class I do not want it to read and sees there is a missing dependency, and errors out

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    SmooshCakez

    Try this:
    Code:java
    1. Bukkit.getServer().getPluginManager().getPlugin("Factions").isEnabled()
    2. hasFactions = true;


    In the past, isPluginEnabled has been pretty buggy for me. This may fix your problem.
     
  7. Offline

    EnderTroll68

    The boolean works fine. I have used debug code by broadcasting what it is to the server to make sure that wasn't the issue.
     
  8. Offline

    SmooshCakez

    Is Factions working correctly on your server? Does factions give you errors?
     
  9. Offline

    EnderTroll68

    I do not have factions on the server.... That is the whole point. I want this plugin to work when factions is not on the server AND when it is on the server.
     
  10. Offline

    Skye

    EnderTroll68 You are only using "softdepend" in your plugin.yml, and not "depend"? Can you post line 36 of your main class?
     
  11. Offline

    EnderTroll68

    1. if (hasFactions)
    2. Bukkit.getPluginManager().registerEvents(new InteractListener(), this);
    3. else
    4. Bukkit.getPluginManager().registerEvents(new FactInteractListener(), this);
    Line 36 is line 4 of that
     
  12. Offline

    Skye

    EnderTroll68 Can you post your entire onEnable, or even better, the main class? Posting plugin.yml would be good too. Something in your code is making references to Factions regardless of its presence.

    Edit: Actually, nevermind. You're registering your Factions listener when it's not present.

    1. if (hasFactions)
    2. Bukkit.getPluginManager().registerEvents(new InteractListener(), this);
    3. else
    4. Bukkit.getPluginManager().registerEvents(new FactInteractListener(), this);
     
  13. Offline

    fireblast709

    SmooshCakez don't forget to check for null. Also funny how people claim parts of Bukkit are buggy, and solve it by doing pretty much the same thing manually as a fix.
     
  14. Offline

    SmooshCakez

    If that's your definition of complaining...
     
  15. Offline

    fireblast709

Thread Status:
Not open for further replies.

Share This Page