Multiple classes extends JavaPlugin

Discussion in 'Spigot Plugin Development' started by DanHraje770, Jun 2, 2017.

  1. Hello,

    I have one problem. I created and I want extends JavaPlugin in How to extends in
  2. Why? What are you trying to do?

    (You only make your main class extend JavaPlugin, no other)
    • Agree Agree x 1
  3. "public class OtherClass extends JavaPlugin"
    • Optimistic Optimistic x 2
    • Like Like x 1
    • Funny Funny x 1
  4. You have to create an instance of the class what extends JavaPlugin. Get the instance then from
  5. XY Problem, what are you actually trying to accomplish? @DanHraje770
    • Agree Agree x 1
  6. How would having two JavaPlugin classes protect your plugin?
  7. You other class seems to be a SQLHandler of sorts, I would just rename it to SQLHandler and use it from the normal Main class
  8. This is not the place for spoon-feeding :)
  9. Ok, and how to extends Java Plugin in class AntiLeak?
  10. I extends JavaPlugin in AntiLeak. Error code in console:
    Code (Text):
    [21:06:14 ERROR]: Error occurred while enabling Annihilation v2.1 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
            at ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at<init>( ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at cz._HeroPwP.Annihilation.AntiLeak.<init>( ~[?:?]
            at cz._HeroPwP.Annihilation.Main.onEnable( ~[?:?]
            at ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.Bukkit.reload( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.command.defaults.ReloadCommand.execute( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.command.SimpleCommandMap.dispatch( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand( [server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand( [server.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO( [server.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B( [server.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A( [server.jar:git-Spigot-21fe707-e1ebe52]
            at [server.jar:git-Spigot-21fe707-e1ebe52]
            at [?:1.8.0_131]
    Caused by: java.lang.IllegalStateException: Initial initialization
            at ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at<init>( ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at cz._HeroPwP.Annihilation.Main.<init>( ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_131]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance( ~[?:1.8.0_131]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( ~[?:1.8.0_131]
            at java.lang.reflect.Constructor.newInstance( ~[?:1.8.0_131]
            at java.lang.Class.newInstance( ~[?:1.8.0_131]
            at<init>( ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin( ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins( ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins( ~[server.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload( ~[server.jar:git-Spigot-21fe707-e1ebe52]
            ... 10 more
  11. If you want to do something with the plugin class pass it as one of the parameters in the constructor of the other class, don't try to extend JavaPlugin in the other class.
  12. How to use constructor for extend JavaPlugin?
  13. Code (Java):
    private Main plugin;

    public OtherClass(Main plugin)
        this.plugin = plugin
    Then you use the plugin field instead of trying to extend JavaPlugin.

    If this doesn't help you then you have to get a better understanding of Java before doing this.
    • Like Like x 1
  14. Apready said it but I'll just got ignored...
  15. Mas


    Learn how classes, objects and constructors work. Ideally you should know Java basics before starting to work with the Spigot API.
    Only your plugin's main class can extend JavaPlugin. To use methods inherited from JavaPlugin in your main class, you will need to pass an instance of your main class to the constructor of your AnitiLeak class, as statede by others.
    #19 Mas, Jun 3, 2017
    Last edited by a moderator: Jun 4, 2017
  16. md_5

    Administrator Developer

    Removed links to code because OP included passwords in them.... You should be more careful
    • Friendly Friendly x 4
    • Like Like x 3
    • Informative Informative x 1