Minecraft Plugins in 2017 with Spigot

The Basis...

A guy named Dawson came to me the other day and began speaking to me about Minecraft plugins. It has been a very long time since I have played Minecraft. Most people think that it is a children's game but I do believe at some point we have all played it.

Besides that let's talk about developing plugins for a Minecraft server in 2017.

You're probably familiar with the name Bukkit and hMod. Both of these existed as server clients a very long time ago. We are talking around 2011 or possibly even earlier.

What changed?

From my basic understanding hMod became Bukkit. Then Bukkit became affiliated with Spigot. Then all of it became available through something called BuildTools. Now you have to use Git to pull an entire repo that builds the latest version of Minecraft servers right on your desktop. Which leads me to believe that running a Minecraft server now requires a little more effort if you want customization.

Here's an entire wiki page dedicated to BuildTools.

Also plugins are now just a simple drag and drop into the plugins folder rather than editing a configuration and specifying what plugins need to be loaded.

Building a Plugin, starting out...

There are a few different programs out there that offer different advantages and disadvantages. I will be using a program called Eclipse for compiling plugins or .jar files. I have never really used this program before so it's a new but familiar interface if you have ever touched VisualStudio before.

Creating the Project

Hop into Eclipse and create a new Java Project. I am naming my project 'MyBlankPlugin'. Hit next and you should be prompted with a screen that has a tab called Libraries. This is where we're going to load in the API for spigot. We'll be loading in an external jar this way. See the image below as an example.

You'll be selecting the latest version of Spigot from your BuildTools pull (download). You'll want the one that is hyphenated as '-shaded'.

Load that external library in and hit finish.

Structuring the Project

You're going to need a few new files to get started. Right-click your 'src' folder in your Package Explorer and create a new package.

We're going to name it similar to our project name. I have named mine stuyk.myBlankPlugin.

Hit 'finish' and then right-click your new package file and create a new class. We're just going to name this class 'Main' because it's going to house a lot of the main features for our plugin.

After finishing that step you need to create a '.yml' file.
Right-click your project folder and add a new file to it.

We're going to name it plugin.yml and yes I do believe this is case sensitive.

Once we've done that. Open up plugin.yml and we're going to add a few lines in this file.

name: MyBlankPlugin  
main: stuyk.myBlankPlugin.Main  
version: 1.0  
commands:  

Name is going to be the name of your project.
Main is going to be the path to your main class.
Version is entirely controlled by you.
Commands aren't important right now unless you plan on working with commands. Look into it on your own time.

Save it. Close it.

Hooking into the Library

Open up your main class file. Main.java

You should see something along the lines of...

package stuyk.myBlankPlugin;

public class Main {

}

When you first start a project like this you absolutely need to specify that it is extending a java plugin. We do this by adjusting our class to look like the following.

When you extend the class you will be prompted with an error. You will need to hover over and import JavaPlugin.

o·ver·ride

extend over; overlap.

We're going to use an @Override to add an onEnable and an onDisable to our plugin. These will be the very first things called when the plugin starts. We'll put this inside of our first bit of curly brackets.

    @Override
    public void onEnable() {

    }

    @Override
    public void onDisable() {

    }

Now that we have those we can throw in a little console message to ensure that the plugin is compiling properly.

Add in a console message to our onEnable function.

System.out.println("The blank plugin has been enabled!");  

Sweet now we have a basic functioning plugin that we can compile to ensure it runs on the server.

File -> Export

Save it as a Java -> JAR file.

Untick .classpath and .project

Then set your project's export destination to your plugins folder for your server. If you haven't even setup a basic server directory hop into google and look up how to set up a spigot server.

Otherwise here is an example image.

After that you just need to rev up that server and check to make sure you got a console output.

Now what?

Now you have a super basic Minecraft Plugin that pretty much does nothing. I will be writing a few more tutorials on building Minecraft plugins to help the few of you who are interested in this. In the mean time use your googlefu to help teach yourself on working with the Spigot API.

Here are a few projects you can attempt.

  • Send a message to the player.
  • Send a message to the player when they join.
  • Destroy a block and force it to send a player a message.
  • Destroy a block and prevent it from being destroyed.
  • Prevent a specific block type from being placed down.
  • Create a command that responds to you. /ping -> pong!