113
Welcome back to the second tutorial blog in the 'How to make a plugin' series. From the mass majority of you wanting more tutorials, we just had to release more.
In this tutorial you will learn how to do the following :
- Learn the meaning of onEnable() and onDisable()
- Implement onEnable() and onDisable()
If you've already followed this tutorial then click the link below to view the next tutorial...
Next Tutorial - Click Here
After following the first tutorial, you should have your package, class setup along with Bukkit API already implemented in.
Now, Your class should look like this :
Spoiler
Now that you have this open, here is where we start programming. So where it says 'public class Main' or whatever you have as your class name, you want to add :
'extends JavaPlugin'
Then hover your mouse over JavaPlugin until a little window pops up. In the little window it should say 'Import JavaPlugin (org.bukkit.plugin.java). When it does just left click onto it and it should add some code to your class at the top.
Now your code should look like this :
Spoiler
Once you've got that we can move onto the next step.
Inside the public class, we want to add 2 public void's, onEnable() and onDisable(). I'll now show you how to do this and explain what it does.
What you want to do inside the public class is write the following :
Spoiler
public void onEnable() {
}
public void onDisable(){
}
}
public void onDisable(){
}
Explaination
onEnable and onDisable are called when you start your server. Bukkit will scan for plugins and automatically run the jar. When looking throught the code, if Bukkit finds onEnable then when the plugin is enabled by Bukkit it will do something. For example, It would display a line of text saying 'Hello World, how are you today?'. Also, when Bukkit finds onDisable then it will do something with the plugin is being disabled (shutting the server off).
I hope this tutorial has been useful. I will be uploading more daily or even 2/3 per day.
To create these tutorials for you is quite a challenge, If you'd like to see more tutorials and more sections covered then please donate to our team as generously as you can. Every bit of it helps and supports us even more.
Donators will be able to get private lessons from myself or anyone else from TeamJaval. Including their name posted on numerous blogs as a big thank you.
Credit | KendogHD, TeamJaval |
Tags |
2829182
6
Create an account or sign in to comment.