Bukkit API Tutorial

Discussion in 'Bukkit Help' started by dreadiscool, Jul 28, 2011.

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

    dreadiscool

    Forward
    I've slowly started to lose interest in MineCraft, as well as development for plugins. So I've decided to post my knowledge here for newbie programmers to continue the legacy :) Enjoy, comments and (constructive) criticism are appreciated. If you already know how Java works, you can skip the 'Programming Tactics' section. If you need any help with Bukkit, feel free to post on this thread, and hopefully someone else will learn from your question too.

    (And hey, if I don't get to your question in time, someone else might!)

    Here's a list of what's currently finished, or in a 'beta' mode (but still usable!).
    > Please Note...
    > Getting the API
    > Eclipse Troubleshooting


    Please Note... (open)

    For this entire tutorial, I'm using Eclipse. I'm using the JDK available for 64 bit machines. If you don't know what this means, don't worry about it unless Eclipse gets one of the following errors:
    > Failed to load the shared JNI library jvm.dll
    > Eclipse was started but Java returned exit code 13.
    If you do find yourself with this problem, head on over to the eclipse troubleshooting section tab.

    You may be wondering why I'm telling you to use Eclipse over NetBeans...
    Although NetBeans is great if you're designing a GUI, the code completion in it is sadly lacking. Eclipse has a great, built in code completion function, as well as a robust problem solving feature that is really helpful for newbies when learning a new API (yes, Eclipse looks through the JAR files and builds a JavaDoc).

    Getting the API (open)

    Please note that the Bukkit server JAR is SEPERATE from the Bukkit API JAR file. You can find the Bukkit server on the front page, to the top right (for testing your plugins!). You can get the latest Bukkit API Jar file here. As long as the Jar file is downloaded in a stable location (preferably not a flash drive, although you can still pull it off), you can leave it anywhere in your system.

    If you are already familiar with creating a Java project with eclipse, you can skip reading the rest of this paragraph. Start Eclipse. The default workspace location works fine. Click File -> New -> Java Project (top left corner). Now, name your project whatever you want. Don't change any of the other settings unless you know what you're doing.
    Screenshot (open)
    [​IMG]


    Although it's not technically required, it is considered good programming practice to have at least one package inside your SRC folder. Right click on the SRC folder, and select New -> Package. If you want a more in depth tutorial on what packages are, head on over to the Java Package section. Otherwise, know that packages can be embedded inside each other, and to create packages, you put in something like 'dreadiscool.pluginTutorial'.

    As you are just beginning to program, you require only one package, so it's no problem what you name it. Just know that packages cannot begin or end with a dot (.) or your IDE will punch you in the face :). Now that you have your package, right click on it (the package), and select New -> Class. Enough of that now.

    Right click on your project folder itself (since I named my project MyFirstPlugin, the folder name will be MyFirstPlugin) and select Properties, down at the bottom of the menu. You should get an interface like this:
    Project Properties (open)
    [​IMG]


    Click on 'Java Build Path' in the list to the right. In the top center, you should see some tabs. Click on 'Libraries' in the tabs that open up. Now, click on 'Add EXTERNAL Jar' (not 'Add Jar').
    Screenshot (open)
    [​IMG]


    Browse to the location to where you saved your Bukkit API Jar file, and select it. Congratulations, you're on your way to writing your first plugin!

    First Plugin (open)


    Programming Tactics (open)


    API Hookables (open)


    Eclipse Troubleshooting (open)

    Please go to the associated section for the problem you are experiencing.
    Failed to load the JNI shared library jvm.dll (may not be this exact phrasing, but similar!)
    Check if you're running Eclipse 32bit with a Java version of 64bit or vice versa. If you are, make sure either downgrade or upgrade the mismatched file (it doesn't matter which one). If that doesn't work and you are using Windows, right click on the executable and select 'Run As Administrator'.

    Eclipse was started but Java returned exit code 13
    Most probably Eclipse cannot find the JDK. Either plop the executable into the Java/Bin folder, or create a shortcut to eclipse.exe. Right click on the shortcut, and select properties. In the properties, ADD the following line to what's already in there: -vm "C:\your path to java/bin".

    Any other errors (last resort solution)
    Create a shortcut to Eclipse.exe. Right click on the shortcut, and select properties. In the properties, ADD the following line to what's already in there: -vm suppresserrors.

    Java Packages (open)

     
Thread Status:
Not open for further replies.

Share This Page