Setup IntelliJ IDEA for Bukkit plugin development

Setup IntelliJ IDEA for Bukkit plugin development

There are a few really good texteditors out on the Internet for developing, and when programming you really need one that you like – since you’re going to stare at it quite a bit. When programming in a language like Java that is Object Oriented a good IDE is a lot help, it’s not a requirement but it sure helps. My favorite IDE for Java development is IntelliJ IDEA, there are a few other popular ones out there like Eclipse for example, but I really prefer IntelliJ.

Setup IntelliJ for Bukkit

It’s a bit different to start up a Bukkit plugin environment if you’re used to Eclipse for example, I’ll do my best to walk you through the process. Begin by making a new Empty Project. The project is where you will house all of your Bukkit plugins, or modules as it is called in IntelliJ.

Make a new blank Project

As I briefly mentioned above, projects in IntelliJ is not quite as you’d think they are, they are actually more of the collection of your Plugins. I named my Project Tutorials, because in this project I will house all of my Tutorial plugins. Now it’s time to make a new Module which what a plugin actually is, a Java module. Click File > New Module choose to make a new Java Module. (You could actually choose to make a Maven Module from the beginning, but I’m going to walk you through the long way.) Now it’s time to name our plugin, for this Tutorial I’ve decided to name it SetupIntellijForBukkit, quite fitting right?

module_is_plugin

Our plugin needs to be within a package, I’m sure you’re familar with this but do not worry if you’re not, and we need to follow a specific naming convention that Java uses, you can use your GitHub or even your e-mail if you do not have your own domain. Most important is to have a unique name in all lower case and the name of your plugin appended at the end. That’s is why I named the package to net.jejje.java.setupintellijforbukkit. You create the package by right clicking the src folder like the image below indicates.

make_our_package

I went a head and made our main class and named it MyMainClass, beacuse I like it, and I put it in our newly made package. If we would try to extend this class from Bukkit (JavaPlugin) nothing would happen, we would only get an error like this image shows.

cannot_resolve_javaplugin

This is because we haven’t told IntelliJ where or what dependencies we need. We will need Bukkit as our dependency, let’s go a head and add that now. Do that by navigating to File > Project Structure or by using the hot key for Ctrl + Alt + Shift + S and navigate to the Modules and under the Dependencies tab click the green plus sign and click the Jars and directories and then locate your craftbukkit file, if you don’t have one yet follow my tutorial on how to setup Bukkit on Windows and when the tutorial is finished you will both have the craftbukkit jar and a testing environment to later test out our plugins on.

add_bukkit_jars_as_dependencies

Now IntelliJ suggests that we import Bukkit and we can do that by hitting Alt + Enter and now we can soon begin our development, as I mentioned before when we created our Module that we would add Maven support, it is now time to do that – and I chose to show you this longer approach so that if you in the future would forget it would be good to know how to add the framework afterwards, and we’ll add this by right clicking our SetupIntelliJForBukkit module and clicking Add Framework Support… and tick the Maven framework and it will be added.

add_framework_support

Now if we would want to build our plugin, or artifact as it is called – we will need to tell IntelliJ which class is our main class. Remember when we went into the Project Structure, let’s go there again and click yourself into Artifact, and click the green plus sign and choose Jar > From module with dependencies.

add_mainclass_path

Just clicking OK will find your Main class, but you can also try to locate it using the “…” on the Main Class field. Now finally, we can begin our Bukkit development and when it’s time to test our plugin out you will need to build the jar file, as I mentioned our plugin is an Artifact and when we’re going to build it we will navigate to Build > Build Artifacts… this will begin the process. So where will this jar file be saved, you might ask, when you where in the Project Structure under the Artifacts setting there is an input field named Output Directory. I usually set this directory to my plugins folder within my developing server, and I would recommend you to do the same.

Jimmy Nelsing's Picture

About Jimmy Nelsing

I'm a computer enthusiast who loves the web and web development, I've used Wordpress for a long time on and off for different web pages for many years. I also like to develop in PHP, especially with Laravel and have also started with Java programming as side projects - testing out Bukkit and Android.

http://jejje.net/

Comments