Matt Hines Development

Matt Hines.
Software Engineering Student.
London.
This blog is mainly to display my different projects, as well as a place for me to share and discuss technology news.

Recent Tweets @MattDevUK


My Setup - OS: Windows 7 Ultimate with SP1

IDE: Eclipse 3.7.1

Bukkit Version: CraftBukkit 1.3.1-R2.0

Minecraft: 1.3.2

I have declared the above just so I don’t get messages from people confused as to why something is different on their system if they are running different versions of software than me.

Setting up your Bukkit Server!

You will need to vist CraftBukkit - Recommended Build to get the latest stable build of CraftBukkit server. This will automatically download the latest recommended version to your computer.

Once downloaded, you need to decide where you want to keep all of the server files and folders. I have just created a folder in my C: drive called “Bukkit”, you can create a folder on your desktop, in your Documents, anywhere. One you have decided, move the downloaded .JAR file into that folder and rename it to ‘craftbukkit.jar’ if the .jar isn’t showing to begin with, you do not need to add it at the end of craftbukkit, it is just hidden.

The next step involves you opening Notepad, or your favourite text editor and type:

java -Xmx1024M -Xms1024M -jar craftbukkit.jar

PAUSE

You may substitute the 1024 for a smaller or greater number if you wish to allocate more or less RAM to the server. I wouldn’t recommend any more than1024 as it will just be a testing local server that nobody else an join without the use of Hamatchi.

(set up instructions for other OS’s can be found on the bukkit Wiki)

Now you must save this file in the same folder as you placed the craftbukkit.jar earlier, but save this file as ‘RUN.bat’.

Finally, double-click the RUN.bat file you just made and the server will start up with a command prompt/terminal window and you will see files and folders being created in the directory.

To join the server from Minecraft, from the main menu select Multiplayer, then Add Server. Give the server name if you wish, but in the Server Address box enter:

localhost:25565

You do not need the port number, but it doesn’t hurt to include it. You should now be able to join your server and load the world. It may seem a little slow at first as all new servers do, when it is busy generating the terrain and chunks around you, but you should not experience any lag as there are no networks for it to converse across, just purely your own computer.

Two Important Server Commands

STOP - stops the server, calls the ‘onDisable’ method of each plugin, disconnects all users. Useful when making extreme changes to the plugin and/or server.

RELOAD - reloads all of the plugins and does not disconnect the user from the server. This cna be very useful when editing your plugin. For instance, you can the plugin to output a message when you break a block, save and export the changed plugin, send the reload command and next time you break a block the message will appear (given that it is coded correctly!).

Now you have your server set up it’s time to move onto your development environment!


Pick your IDE!

You can use any IDE from Eclipse to Netbeans+ or even use a basic text editor such as Notepad or Sublime but be warned there is no/limited debugging or help given by the basic text editors, and no JavaDocs integration!

I will be using Eclipse as it is my favoured IDE for Java so be wary that some things I do throughout this project may not apply to you or may be slightly different if using another IDE.

Setting up the workspace

Start Eclipse, then create a new Project by selecting File > New > Java Project. You may name the project anything you like but it is advised to keep it sensible and relevant to your plugin. Continue following the on-screen wizard, leaving everything as default. Once complete, a folder will appear in the Package Explorer window, on the left of the screen with the name of your project. Double click on it to open/expand it, revealing the contents of your project.

Reference the Bukkit API

Before we begin developing we need to add the Bukkit API library to our project so that we may use any of the built in functions and methods required to develop a Bukkit plugin. You may also add in other APIs if you wish to use multiple.

The latest Bukkit API can ge downloaded by clicking here: Bukkit API - Development Snapshot

You may also use the JAR file you downloaded for the server originally, but the above link will always give you the very latest API version.

Save this JAR file somewhere safe, I have put it in a folder named ‘Bukkit Dev’ on my desktop.

Next back to Eclipse, right click on the folder with the name of your project in the Package Explorer and select Properties. Select Java Build Path from the left side of the window that pops up and then select the Libraries tab.

Click on the Add External JARs… button and browse to either the API JAR file or the original Bukkit Server JAR file. Click OK and you’re ready to go!

Bukkit Javadocs

If you have much experience with IDEs and programming, you might notice that by hovering over a class or method, a container appears with some extra information about that particular piece of code. Bukkit has it’s own documentation that contains useful descriptions of each method and class within the API. This step is not vital to being able to develop for Bukkit, but it does provide a lot of help and useful information when learning the API.

To anable the Bukkit Javadoc, expand the project folder in the Package Explorer, then expand Referenced Libraries. Right-click on the JAR file you added to the references earlier and select Properties. Select Javadoc Location from the left hand menu and make sure the Javadoc URL radio button is selected. In the Javadoc location path type:

http://jd.bukkit.org/apidocs/

Click Validate, then OK and we are set to start developing!

I shall write another post on creating our first package, class and methods later on as writing up these posts takes on average 4-5 times as long as it takes to actually do them, so apologies if you catch up instantly but I want to dedicate some time to developing too! :P

Please let me know what you think of this first post in the series talking about Bukkit development. After the project is all set up, the posts might not be quite as detailed and will cover the main points as we progress with our code.