PluginBase - wysohn/GeneralLib GitHub Wiki
An abstract class that extends JavaPlugin. It's the first class you always have to deal with for every plugins.
I assume you already have the prior plugin development(at least printing Hello World! maybe). PluginBase is the abstract class that extends JavaPlugin. This means that letting your main class to extend the PluginBase will make it also a JavaPlugin.
For example)
public class MyPlugin extends PluginBase{
}
Hierarchy: ... -> JavaPlugin -> PluginBase -> MyPlugin
And as you already know, this is not done. You have to specify where your 'main' class is in the plugin.yml right? The same thing goes here.
In plugin.yml
main: com.some.package.MyPlugin
this is just an example, and you will have to use the package name and class name you created just like you did with the JavaPlugin.
Probably at this point, most IDE like Eclipse or IntelliJ will complain about unimplemented method. But before even we go there, we need one more thing to do.
In order for the PluginBase to work properly, you need to initialize it with its constructor. To do so, you just call the super constructor inside your plugin's main class constructor.
public class MyPlugin extends PluginBase{
public MyPlugin(){
super(new MyPluginConfig(), "mymaincommand", "myadminpermission")
}
}
It seems confusing, but it actually is not. I will go one by one.
1. You have to notice that I used default(no argument) constructor, which is public MyPlugin(){blah blah...}.
This is because when Bukkit API initialize your 'main' class, it looks for the default constructor. So to be found out by Bukkit API, a default constructor(no args) must be present in your plugin's main class. And like I already said, you have to call constructor of PluginBase in order to initialize the PluginBase, so the above code is the most ideal for any cases.
2. You are probably wondering what these arguments passed to the super() constructor.
Arg0 - PluginConfig
Arg1 - The second argument is the main command that will be used to execute the commands. For example, I've put "mymaincommand" in the second argument; later after creating .jar and loading it in your Bukkit/Spigot server, you will be able to execute any commands you made by /mymaincommand <subcommand> <args...>. And if you didn't notice, there is a overloaded constructor that accepts array of String instead of single String, so if your plugin will have more than one main command, to something like this
super(new MyPluginConfig(), new String[]{"mymaincommand", "mymaincommand2"}, "my.admin.permission");
And don't forget! just like how you made your plugin by extending JavaPlugin, you still have to put your commands in the plugin.yml
main: ...
commands:
mymaincommand:
aliases: ["mmc", "mycmd"]
mymaincommand2:
aliases: ["mmc2"]
Arg2 - The last argument is the admin permission that can override any permissions, and this will allow user with this permission to bypass permission required for each commands. But if you have functionality which require admin permission(like admin tools for example), you will have to check it by yourself.
3. You now implement the method
There is only one method, preEnable(), to implement. This is where you initialize everything. It's very important to do it here as the method will be used by PluginBase to initialize everything in correct order.
public class MyPlugin extends PluginBase{
public MyPlugin(){
super(new MyPluginConfig(), "mymaincommand", "myadminpermission")
}
@Override
public void preEnable(){
//TODO initialize your commands, languages, managers, and APISupports
}
}