Using methods from another plugin

Discussion in 'Plugin Development' started by Wizardo367, Aug 19, 2013.

Thread Status:
Not open for further replies.
  1. Hello, I'm currently working on a custom plugin at the moment and I would like to use methods from my existing public plugin as well. The public plugin 'SuperMarket' is currently in development as well since I am re-writing it so basically I just want to know how both can be linked together to share methods. Any help is appreciated.
     
  2. Offline

    Lactem

    You should be able to add your other plugin as an external JAR in a similar way to how you added CraftBukkit.jar or Bukkit.jar. Then just import. You would probably have to make the methods you want to use static, as well.
     
  3. Offline

    toothplck1

    No... Just make the instances of your classes accessible, static generally doesn't have many uses when it comes to plugins.
     
  4. Offline

    Lactem

    I would have to disagree with you on that one.
     
  5. Offline

    firecombat4

    Explain please?, I haven't found a lot of uses for it either
     
  6. Offline

    MrSnare

    maybe he doesnt like objects :p
     
  7. Offline

    beastman3226

    MrSnare firecombat4
    Static methodology is very handy in plugins. I use it for handling data upstream before it gets to a flatfile or database because my plugins support both I have to checks to figure out which way to handle the data. Also, static can help when your class doesn't need a reference to your main class yet it needs its methods, you make a static method to avoid having to initialize another main class that wouldn't be able to access a config or other.

    Now back to the original post. If you made your plugin even relatively OOP, then all that needs to be done is to implement it via adding it as a library and using its methods and instantiating its classes. Be warned! This creates a dependency that not all server owners want.
     
    Lactem likes this.
  8. Offline

    MrSnare

    Preaching to the choir
     
  9. Offline

    beastman3226

    MrSnare
    Sorry, your post made it sound like you didn't like the static logic/didn't use it.
     
  10. Offline

    firecombat4

    beastman3226 ahh ic ic, I'm still relatively new to programming, still grasping all the names of things etc etc But thanks haha your post made sense :D
     
  11. Offline

    Lactem

    Thank you!
     
  12. Offline

    The_Doctor_123

    I don't know why some of you say that "static is not good in plugins." This is Java. Bukkit doesn't create a new language, it simply uses it and provides pre-defined items for us to use. A Bukkit plugin is just like any other of your projects.

    Anyway, import your jar that you want to use and import the classes in your classes you want to access them in. If this plugin will be public in the future, add a dependency to your plugin.yml.
     
  13. Offline

    toothplck1

    To rephrase my comment in such a way that more matches what I intended: "Static generally is misused by people who don't understand what it is actually doing and what it actually means, unless you fully understand the concept of static, you should avoid using it. In addition, unless you mean to have no shared data being used between the plugins, I would recommend just using instances accessible via casting the plugin returned from getServer().getPluginManager().getPlugin(String) to your main class and then working down your hierarchy to get the objects you need. Because the alternative of storing all your variables statically is appalling. Although another possible solution is to make your API classes singletons, which is something I do on many occasions."
     
Thread Status:
Not open for further replies.

Share This Page