Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by JoseGamer_PT, May 16, 2016.
In my plugins i use many static abuses.
Is any way to fix them?
Thanks for your time <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.
(sorry im n00b)
Can you show me examples please?
@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
Use constructors, getters , setters to get the instance and variables / methods from other classes
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;
and with that you can get your main-class's instance i BELIEVE
Or you can use PluginManager and use something like this:
MyPlugin plugin = (MyPlugin)Bukkit.getPluginManager().getPlugin("MyPlugin");
Of course, you're using a static bukkit method.
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.
SOLVED! THANKS FOR ALL HELP!