38
Minecraft / Blogs

Learning Java: Bukkit Style - Part 1 (Or how to program a minecraft plugin)

Collectable

Your first experience with Eclipse

Get Embed Codes

Forum:
HTML:
Link:
avatar
Tux2
Level 40 : Master Unicorn
52

Introduction


Hey guys, Tux2 here, and I've just decided to start doing a series on how to make plugins! Now, you may ask why I'm not doing it as a video, and here's why: I dislike having to watch a video on everything new I want to learn as I would rather just read about it, then do it, so that's the style of approach I'm going to be taking (for now). So, let's get started!

What you will need to have in order to follow along in this series:

  • A current version of the Java 7 JDK (Java Developers Kit): Download Here
  • Eclipse, the IDE (Integrated Developer's Environment), get the "Eclipse IDE for Java Developers" : Download Here
  • An up to date copy of Craftbukkit: Download Here
  • The Minecraft client (Of course!): If you need a download link for this, then you probably shouldn't be doing this tutorial...
  • A ready mind, willing to follow instruction and not skipping ahead and missing important parts.

Setting Up Your Environment



A properly set up environment is extremely important and shouldn't be overlooked. Although I know you're probably a bit impatient to get coding right away, I'd rather make sure your environment is set up properly so that you can code, rather than wondering why nothing is working quite right. Please note that in this tutorial series I will be using Windows 7 Home Premium to illustrate everything, as that is the most common OS, although these instructions should work almost equally as well in Windows 8 or even Windows Vista, and with some adaptation in Mac OS X as well.

Step 1: Install the Java 7 JDK




  1. Click on the link above to download the JDK, accept the license agreement, then download the appropriate package for your operating system.



  2. Run the file once it's done downloading and install Java. (Clicking next all the way through is fine for most installations). Once done it will open up a tab in your browser asking you to register. You can safely close it as it is not required.



  3. Once it's installed click on your start button and type in "command", then click on "Command Prompt" in the search results that come up. In the black window that comes up type in java -version then press "Enter/return" on your keyboard. It should return the version of java that is on the computer. If not, then consult the FAQ

Step 2: Install Eclipse


  1. Open up the location where you downloaded Eclipse. Right click on the zip file, and click on Extract All...
  2. Change the location of where you want the files to be extracted to to: C:eclipse, Then click the Extract button.
  3. When it's done it should open up the folder with all the files. Double click on the Eclipse folder to open it, then right click on the purple Eclipse icon and navigate the menu to Send To->Desktop (Create Shortcut) (You can rename the shortcut whatever you want)

  4. Close out of the eclipse folder and open Eclipse from your desktop. When it asks you which workspace to use, just click "OK" as the default one is perfect for what we are going to use it for today.

Step 3: Setting up your first project


  1. When you first open Eclipse it should present you with a welcome screen. Just close out the welcome screen tab and we can get to work. You are now staring at the main screen of Eclipse. Once we get some content in there I'll show you what everything does.
  2. Now, let's create or first ever plugin! Go to File->New->Java Project
  3. For the project name put "ExampleProject", then click on the Finish button.
  4. Excellent! You've just made an empty project in Eclipse, ready for us to start putting files into. Let's start by downloading the Craftbukkit jar and adding it to the project.
  5. Go to: http://dl.bukkit.org/downloads/craftbukkit/ and download the latest version of the CraftBukkit jar. Open up your downloads folder, then right click it and click on Copy, then click on your name near the top of the window and open up the folder called workspace->ExampleProject. Right click and click on Paste.
  6. Pull up Eclipse to the foreground, right click on the ExampleProject in the Package Explorer pane and click on Refresh. Open it up, and right click on the Craftbukkit file you just downloaded and go to Build Path->Add to Build Path.
  7. Congratulations! You are all set up to start working on your first ever plugin!

Your First Plugin



Now that you've got your environment set up and your example project in place, let's start adding some stuff to that project.

  1. Open up your example project and right click on "src" and go to New->Package. For the package name you want to stick to all lowercase in this format: yourname.projectname, so in this case, for me, Tux2, it would look like this: "tux2.exampleproject". Once you're done typing it in, click on the Finish button.
    (A package is a logical way of separating files within a project, as well as making sure that the files in your project don't conflict with anyone else's plugins as well)
  2. Now that we have a package to put all of our files in right click on the package that was just created and go to New->Class. For the name put "ExampleProject". For the superclass click on the browse button and type in "JavaPlugin" in the dialog box that pops up and double click on the first result that comes up, followed by the OK button. Finally, click on the Finish button in the main dialog box. At this point your window should look similar to the following:

    examplepng

  3. You're doing great! But, our project still doesn't do anything yet, so let's add the onEnable, onDisable, and a few other functions.
  4. Go to Source-->Override/Implement Methods. In the dialog box, check the boxes next to onCommand, onDisable, and onEnable. Then click the OK button.
  5. At the moment, the code should look like this:
    examplepng

    Let's remove all those lines with super in them to make the code look like this:
    examplepng

  6. Excellent! We've now got a good base to extend our plugin on, but we're still missing one file: the plugin.yml file that goes in every single plugin. It tells Bukkit where to look for to find out how to run our little plugin we made. So, let's make it. Right click on your src folder, then go to New->File. For the file name put "plugin.yml", then click on the Finish button.
  7. Now we have the file, but there's still nothing in it! Put the following information in it:

    name: ExamplePlugin
    main: yourname.exampleplugin.ExamplePlugin
    version: 0.1

    So, let's break down what you just put in that file:
    -For the Name, you put ExamplePlugin. That's the name that bukkit will show everyone when you do /plugins in minecraft.
    -For the main, you put yourname.exampleplugin.ExamplePlugin. Now, the first part should correspond to your package name, so for me it would be: tux2.exampleplugin.ExamplePlugin, now, you might be wondering about the last part. That's the class file name, and tells Bukkit which file exactly it should load.
    -Version? Well, that's just the plugin version.
  8. Save all the files, this is a good time to take a break. In part 2 of the tutorial we're actually going to start working on the plugin files we created and actually make it do something, so stay tuned!

Conclusion



So far you've set up your Java environment, installed Eclipse, and made a project file. Now, you may not know what they all do yet, but we'll be showing you all the ropes and what everything is in part 2. If you like the tutorial please remember to diamond. If you have any questions, or comments about the material covered in this part feel free to leave a comment below. Until next time, Tux2, over and out!

Part 2 - Hello World! >>

Comments : 28

Join us to post comments.

Show Comments

1 - 28 of 28

Man can someone help me make some plugin or teach me how to make them
Great tutorial, although some steps that the Wiki has that make programming heaps easier have been missed in this tutorial.
  • youp0711
  • Level 1
  • New Explorer
  • August 31, 2014, 3:31 am
I love it
  • youp0711
  • Level 1
  • New Explorer
  • August 31, 2014, 3:31 am
This is the easiest tutorial to follow for beginers
  • Baamoink
  • Level 22
  • Expert Nerd
  • March 13, 2014, 4:37 am
Came across this blog through a plug-in called HyperMerchant, who gave Tux2, & this blog specifically, credit for getting started on the plug-in that he developed.

Being pretty new to the whole Java coding environment, this tutorial is a god send. I'm surprised this blog hasn't received more attention than it has. Incredibly helpful! Greatly appreciate the time you spent in putting this together Tux2.

On to part 2!
  • Cis112233
  • Level 1
  • New Explorer
  • October 29, 2013, 1:11 pm
Thank you!
  • SJcat810
  • Level 20
  • Expert Nerd
  • August 14, 2013, 9:20 am
Thank you for making this! It's really helpful for people starting to make plugins for the first time.
I backspaced the text written at #2 on Your First Plugin. How do I fix this? I deleted the file.

ALSO: How do you retrieve files without the welcome screen?
Thanks!

-BudderPigPlaysMC
  • Pixel_King
  • Level 38
  • Artisan Pixel Painter
  • April 19, 2013, 5:25 am
I am on Mac, is it the same thing? :3
  • Tux2
  • Level 40
  • Master Unicorn
  • April 19, 2013, 9:24 am
Installation of Eclipse and the Java JDK might be a bit different for your platform, but after installation the instructions on how to use Eclipse and program in Java apply equally to Mac, Windows, and Linux computers.
The legendary Tux I see? :O

DisguiseCraft? Enjin? Multi-Inv? The original showcase? Man you're a god
  • Tux2
  • Level 40
  • Master Unicorn
  • April 17, 2013, 4:20 pm
The original showcase was actually made by NarrowTux, not me, although all the others were correct. It's taken quite a bit of time to get where I'm at, and I never intended to have so many plugins, nor so many popular plugins, it just happened.
Oh... NarrowTux, sorry XD

Yeah I have a plugin which is semi-popular, 3000 downloads, and I honestly never expected to get more than 100 downloads :P

You're a great coder man, keep up with the development. Plus, you probs get a lot of reward points on bukkit dev? XD.

Oh also, one question. Does the Enjin plugin support bungee?
  • Tux2
  • Level 40
  • Master Unicorn
  • April 17, 2013, 5:45 pm
I get around 1000 points per month on bukkit dev. We're also currently thinking about support for bungee.
1000? Daym.
I get like 150 lol!
  • Lax_People
  • Level 7
  • Apprentice Pokemon
  • April 16, 2013, 10:03 pm
Great blog, well put together and easy to follow. I might get back into the java business after this, thanks!
  • Tux2
  • Level 40
  • Master Unicorn
  • April 16, 2013, 10:23 pm
Awesome! I'm glad I've inspired you to get back into it. Also, thanks for the compliments.
  • Lax_People
  • Level 7
  • Apprentice Pokemon
  • April 17, 2013, 7:03 am
Your welcome. And the complements are the truth. Never forget that.
  • BoneHunter9
  • Level 45
  • Master Slime Tamer
  • April 16, 2013, 9:58 am
Very good tutorial dude !!!
Im excited for the next one
  • Tux2
  • Level 40
  • Master Unicorn
  • April 16, 2013, 10:24 pm
Cool. :) It should be out in a couple of days.
You should change the title to:

"Making your first mod"
Mods aren't the same as plugins man. I'm kinda a n00b at Minecraft and even I know that :[size=10pt]P[/size]
  • Tux2
  • Level 40
  • Master Unicorn
  • April 15, 2013, 4:45 pm
There's a fundamental difference between a plugin and a Mod. A mod means you are modifying the original files in Minecraft, while a plugin does not touch any of the files in Minecraft at all and only uses the API (in this case the bukkit API) to interact with Minecraft. In this tutorial we are learning how to program using a Bukkit plugin which technically isn't a mod. As modding is more advanced than plugin development I will be covering it in a later tutorial series as an extension after this one. Also, Forge, and a few other of the modding APIs don't follow Java convention and aren't the best things for a beginning developer to learn on.
  • Drakeh
  • Level 44
  • Master Nether Knight
  • April 15, 2013, 6:08 pm
I concur. Great tutorial by the way.
  • Tux2
  • Level 40
  • Master Unicorn
  • April 15, 2013, 9:38 pm
Thanks! I've been bugged for MONTHS, no, YEARS, that I should do a series on how to make Minecraft plugins and I've always said "no, I'm not doing that because then I would be spending a lot of the time teaching them how to program in Java as well and not really any focused study for just programming for Minecraft." But, of course, as time has gone on, I have thought about it, and I've finally decided to go ahead and just do it. If you've been programming for years, you probably don't really need tutorials like these anyways. I've already got part 2 written, I'm just waiting a few days before putting it out of draft mode for a nice flow.
  • Drakeh
  • Level 44
  • Master Nether Knight
  • April 19, 2013, 9:34 pm
Go for it man. I think this would be a great tutorial if I was interested in developing a plugin.
You lost me at hello...
  • Tux2
  • Level 40
  • Master Unicorn
  • April 15, 2013, 12:25 pm
Lol! Making plugins isn't for the faint of heart and takes a lot of time to learn how to do. I can tell you this though, if you just follow the instructions verbatim and take it one step at a time I bet you'll be able to at least accomplish what I did in the tutorial.

1 - 28 of 28

Show Comments

Search

Browse

Site

© planetminecraft.com

Welcome