How to make a bukkit plugin for Minecraft servers? –  

This article is intended to answer the question above. Literally πŸ™‚

So, the short answer is:
Type make at the shell/command prompt, and your plugin will be ready to deploy.

The longer answer:

I used to avoid using sophisticated IDE’s to build programs – they come and go.
We have the “Program Maintenance Utility” so called “make” since decades to build programs, libraries, documentation and other stuff by describing the complete technology chain in a single Makefile, and run the chain by using the make utility.

1. Tools you need

  • An OS with “make” installed. I prefer Linux, but the method can be easily adopted for Windows platforms as well (using nmake).
  • A text editor that can handle special characters, like TAB. I think that a strong editor is a “musthave” for programmers. Personally, I am using THE – The Hessling Editor – a re imagination of XEDIT, the “shell” of VM/CMS dated back to the 80’s. In the PC/DOS era it was available as KEDIT from Mansfield Software Group, Inc. (still in charge)
  • Java Development Kit a.k.a. JDK. It can be downloaded from Oracle but do not browse for it, use a search site for “jdk 1.x download” where x is the recommended version of Java for your server.
  • Java Runtime Environment a.k.a. JRE. It is probably installed on your machine if you can run your test server there πŸ™‚ .

2. Resources you need

  • Bukkit/Spigot placed into the lib directory. Nowadays it is not so easy to obtain those jar files as before the DCMA scandal, but it is possible. For example you might use “BuildTools” from https://www.spigotmc.org/ to decompile/patch the original Mojang’s stuff, and add the work of the community in an automated way (All Hail Glory). You need JRE in order to run BuildTools.jar, and if the things went well – you have your jar files you are looking for. The spigot-1.x.x.jar will be your server, since I’ve put craftbukkit-1.x.x to “lib” to “link” my plugin with.
  • Other plugins you decided to rely on – e.g. WorlGuard, WorldEdit, etc… might be also placed there.

3. Organize your files into directories

In my example I’ve prepared the following directories and files:

Directories “com/meres/stickem” somehow reflects the hierarchy where you put your source code in the world of Java.

  • “com” is the TLD (“net”, “org”, etc… might be used too) “meres” is my nick (you must use your own here), “stickem” is the name of my plugin, and “StickEm” identifies the main class coded in StickEm.java.
  • I’ve put craftbukkit into the “lib” directory. One might place other imports here, and set the CLASSPATH for java compilation accordingly (check the Makefile below).
  • “Makefile” controls the Program Maintenance Utility – make – that will create your final product by checking dependencies and invoking compilers/linkers or other tools when it is necessary to keep the results up to date.
  • “plugin.yml” describes the plugin, and must be packed into the final product – stickem.jar – in order to be recognized by the server – as a plugin.

4. Makefile

#*
#* Makefile for single ended java compilation
#*
#* Meres Ten <meres10@alpha.tmit.bme.hu>
#*—————————————————————————-
MAIN=StickEm
PROJECT=stickem
AUTH=meres
DOM=com
#*—————————————————————————-
#*
#* Toolchain – adjust according to your JDK deployment
#*
#PREFIX=/root/_E/_opt/jdk1.6.0
PREFIX=/root/_E/_opt/jdk1.7.0_79
JC=$(PREFIX)/bin/javac
JAR=$(PREFIX)/bin/jar
#*
#* Includes and libraries – adjust to actual BUKKIT version
#*
CLASSPATH=lib/craftbukkit-1.8.8.jar:./
BASEDIR=$(DOM)/$(AUTH)/$(PROJECT)
BASECP=$(DOM).$(AUTH).$(PROJECT)
#*
#* Options
#*
JFLAGS=-classpath $(CLASSPATH) -Xlint:deprecation
JARFLAGS=#*
#* General rule to compile JAVA
#*
%.class: %.java
:mrgreen: $(JC) $(JFLAGS) $<# Targets and components to build
# —————————————————————————-
#
TARGET=$(PROJECT).jar
OBJS=$(BASEDIR)/StickEm.class
$(TARGET): $(OBJS)
:mrgreen: $(JAR) $(JARFLAGS) cf $(TARGET) -C ./ $(OBJS) plugin.yml

clean:
:mrgreen: rm -f $(TARGET) $(OBJS)
:mrgreen: find . -name ‘*.bak’ -exec rm ‘{}’ ‘+’spotless: clean

This is the Bad Old Makefile – driving people crazy with invisible tabulator characters inside.

The first section contains assignments stating who-is-who-and-where. Red colored values must be customized according to your plugin, and the working environment.

The second part describes the technology chain in reverse order. Very basic, and frequently used generic rules have to be defined first – like how to compile a java file into a class bytecode. Intermediate and final products can be specified later.

The lines with colons specifies targets, and their dependency files.
Next consecutive lines were indented by invisible TAB characters having the ASCII code of 09 in hex, and represented by :mrgreen: ‘s in the above example. They must be there as tabs – spaces will not do.

These lines commence different tools – compilers, linkers, archive managers to produce the target using the files in the dependency list, but only if it is necessary. If the target is older than any of its sources, the tool will create a fresh one, do nothing otherwise.

Invoking make without arguments will produce the top level product/all, but it is possible to make specific targets by listing them as arguments.
For example, in my Makefile “make clean” will remove intermediate stuff, except libraries and source codes from the project tree – making it clean.

5. plugin.yml

This is for my minimalist plugin. You might read “http://wiki.bukkit.org/Plugin_YAML” for creating more complex scenario.
One must change the assignments according to the organization of the plugin being developed.

6. StickEm.java

 

Well, this is my sample code.
Originally this plugin was intended to stick players to the rided entity.
I’ve used it for scripting minigames, and it is worked for 1.5 fine.
Unfortunately – since that left-shift ejection mechanism – I can manage it to work for vehicles only now :-(.
(but I’ve seen signs that we can catch that soon – all glory to Spigot/bukkit team)
So, at its current stage, it is not intended to be a real plugin – but might be used for fun πŸ™‚ .

7. That’s all Folks for now, good luck and type

make

If all went well – without an error – the resulted jar file can be deployed into your server’s plugin directory.
(homework: include an “install” target in the Makefile that copies the resulted jar in its final place)
Punch it, and beware of riding a chicken!

Look Out Below

Look Out Below

meres10

P.S.

The code can be downloaded from Here-, and Here- (with bukkit included in the later one – beat me for this)