[Guide] How to create a simple Bukkit plugin! (For Beginners)

Discussion in 'Resources' started by ZodiacTheories, Apr 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ZodiacTheories

    Hello Guys!

    So, if you read the title then you are here for a simple Bukkit plugin tutorial (or guide)!

    Please note that this is very basic and won't get you very far in advanced programming.

    So, lets get started!

    1. Download and Install the JDK(Java Development Kit)

    the JDK is what you need for coding Bukkit plugins and other Java plugins, here is the link:

    http://www.oracle.com/technetwork/java/javase/downloads/index.html?ssSourceSiteId=otnjp

    2. Download and Install your IDE (Integrated Development Environment)

    An IDE is the program that you write your plugins in. IDE's are very useful and they tell you where you have gone wrong.

    I recommend Eclipse for beginners as it isn't very complicated.

    Link: http://www.eclipse.org/downloads/

    So, now we are ready to start coding!

    3. Starting

    Now that we have our IDE set up, we can now start coding!

    Ok, so where it says File at the top, you want to click that and hover over new, then you click on Java Project. A window will pop-up in Eclipse and you type in your project name, for this tutorial I will be naming this TutorialPlugin, but you can call it whatever you want. Then press Finish.

    So now we have a folder on our Package Explorer but, why isn't there any code on my screen?

    Click the drop-down menu thing on the left of your folder and you will see that there is a src folder. Right click on that and press new -> package which will bring you to a screen that asks you to name your package.

    4. Naming our package

    You can name your package many different ways, you can do your email backwards like this: com.gmail.myemail or you can do me.yourname.yourpluginname . Those aren't the only two options, but they tend to be the most popular.

    5. Creating our main class.

    What!? My IDE isn't working there is no code!?!!?

    To create our first class, right click on new -> class. You will be asked to name our class, I prefer calling it Main but you can call it anything (up to a point).

    STOP RIGHT THERE

    If you start coding now, you will get all sorts of errors! We need to import the Bukkit API now!

    To get Bukkit, go to http://dl.bukkit.org/downloads/bukkit/ and download the option you want (I will be using the 1.7.9 Development Build).

    So, now we have our JAR, does that mean we can start coding?? NO!

    Right click on your project folder and scroll all the way down to the bottom where it says Properties. Click on that and then click Java Build Path , then Libraries and add External JARs. Now locate to where you saved Bukkit and click that.

    We now have Bukkit imported!!

    Now lets start coding!

    The first few words you are going to want to write are extends JavaPlugin implements Listener, like this:
    Code:
    package me.thesamster8.tutorialplugin;
     
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.Listener;
     
    public class Main extends JavaPlugin implements Listener {
     
    }
    which basically tell the plugin that this is the main class. The implements Listener bit, does not tell the plugin that this is the main class it tells the plugin that it also implements Listener which in this case means that an event is in there. You will notice two red lines appear under Listener and JavaPlugin, hover over them both and press import and problem solved!

    6. onEnable()

    Next, we want to press enter twice and type in @Override. Then press enter and type in public void onEnable() {

    which means "when the server is enabled". Then, we want to register our events, because we are going to create an event, which is why we implemented the Listener. We register our events like this:
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);


    Your code should look like this:

    Code:java
    1. package me.thesamster8.tutorialplugin;
    2.  
    3. import org.bukkit.event.Listener;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class Main extends JavaPlugin implements Listener {
    7.  
    8. @Override
    9. public void onEnable() {
    10. getServer().getPluginManager().registerEvents(this, this);
    11. }
    12.  
    13. }


    7. onDisable()

    This isn't major but I just like doing it.

    Code:java
    1. package me.thesamster8.tutorialplugin;
    2.  
    3. import org.bukkit.event.Listener;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class Main extends JavaPlugin implements Listener {
    7.  
    8. @Override
    9. public void onEnable() {
    10. getServer().getPluginManager().registerEvents(this, this);
    11. }
    12.  
    13. @Override
    14. public void onDisable() {
    15. }
    16.  
    17. }
    18.  


    8. The Event

    WILL CONTINUE TOMORROW - AM BUSY, CANT FIND WAY TO SAVE IT SORRRYYYY!!!

     
  2. Offline

    BungeeTheCookie

    ZodiacTheories
    Congratulations! You basically just took a bunch of already existing resources that are meant for basic coders, concised them into one post, and put it up on the resource section. There are dozens if not hundreds of these resources, plus about 7 in the resources section already. They are never posted on since no one ever goes to them because they are so basic. You should post something people will actually use, not something simple like this. You see, this is what Google is for. I suggest you don't waist any more time doing this and put effort into something that will make the community happy. To be honest, I do not think anyone is going to read this.
     
  3. Offline

    Garris0n

Thread Status:
Not open for further replies.

Share This Page