Minecraft Blogs / Tutorial

How to make a Minecraft plugin / onEnable() and onDisable() / Tutorial Series #2

  • 1,939 views, 1 today
  • 4
  • 2
  • 3
TeamJaval's Avatar TeamJaval
Level 59 : Grandmaster Programmer
113
undefined


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

undefined

undefined

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
undefined

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
undefined

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(){

}

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.

undefined

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.

undefined

undefined



CreditKendogHD, TeamJaval
Tags

Create an account or sign in to comment.

edisd1
12/19/2014 11:13 pm
Level 1 : New Network
edisd1's Avatar
You should really finish the rest and put the rest of the urls in the part 1! looks good!
1
fase
03/30/2014 12:35 pm
Level 11 : Journeyman Gent
fase's Avatar
Looks great!
1
TeamJaval
03/30/2014 12:36 pm
Level 59 : Grandmaster Programmer
TeamJaval's Avatar
Thanks Phase_ :)
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome