Solved Improve static abuses.

Discussion in 'Spigot Plugin Development' started by JoseGamer_PT, May 16, 2016.

  1. In my plugins i use many static abuses.
    Is any way to fix them?

    Thanks for your time <3
    - Jose
     
    • Agree Agree x 1
  2. Dependency injection
     
  3. That might actually prove to be pretty hard IMO, especially if you have a huge project.

    Start by passing your main class through in constructors of your classes and making everything in your main class non-static. See where it takes you.
     
  4. ??
    (sorry im n00b)

    Can you show me examples please?
     
  5. Google it
     
  6. @JoseGamer_PT I'm guessing people have told you to improve static abuses, so you ask others what you need to do. You have no idea what static abuse actually means so you're hoping to be spoonfed. If you want to do what you ask, start by actually properly learning java, especially the Object-Oriented part of it. Once you get that done, you will know what you have to do to improve static abuse
     
  7. Use constructors, getters , setters to get the instance and variables / methods from other classes
     
    • Agree Agree x 2
  8. Dependency injection is great if you are not trying to get your main class. But if you are, i am pretty sure there's a method;

    <Mainclass>.getPlugin(<mainclass>.class);

    and with that you can get your main-class's instance i BELIEVE
     
  9. Or you can use PluginManager and use something like this:

    Code (Java):

    MyPlugin plugin = (MyPlugin)Bukkit.getPluginManager().getPlugin("MyPlugin");
     
    Of course, you're using a static bukkit method.
     
  10. The way to fix them is to stick the OOP paradigm... go out, replace all of the static methods with something that is not static and figure out how to get a small plugin working without any static. Then do it for a larger one and so on.
     
    • Like Like x 1
  11. SOLVED! THANKS FOR ALL HELP!