Create your first BungeeCord plugin (Proxy) - Historical

Applied By Tux: Jun 27, 2014 at 10:20 AM

Create your first BungeeCord plugin (Proxy)
Congratulations on deciding to create your first BungeeCord plugin! This tutorial will get you up to speed with the basics.

Note: If you're impatient and just want to start quickly, you can get a skeleton project using this tool and continue read the other documentation on the wiki.

This tutorial only covers IntelliJ IDEA, but other IDEs should have similar steps.

First, open your IDE and create a new project. You should have a screen similar to this:
[​IMG]

Click next, then you will get this screen:
[​IMG]
For GroupId, type in your Java package name (like org.spigotmc). For ArtifactId, type in the name of your plugin (in our case, it will be TestPlugin). Leave the version alone for now, and click next. Change the name of your project to the name of your plugin, and then click "Finish".

The IDE will open and show you a file called pom.xml. Let's add some content to this file. Add the following lines to it:

HTML:
    <repositories>
        <repository>
            <id>bungeecord-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>net.md-5</groupId>
            <artifactId>bungeecord-api</artifactId>
            <version>1.7-SNAPSHOT</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>
This will add the BungeeCord dependency to your project. If you are using IDEA, it will ask if you want to import changes from the pom.xml file. Import them. If it asks about the language level being changed, allow it to reload the project.

Next, expand TestPlugin, then src, then main. It should look like this:
[​IMG]

Right click java, then make a new package. Call it org.spigotmc.testplugin. Next, right-click the package you just created and make a new class. Call it TestPlugin. The IDE should have opened the file for you; if it didn't, open it now.

Now, we can create our basic plugin. This page will only focus on making a plugin that does nothing; other pages on the wiki can detail all the other things you can do with your new plugin.

Add "extends Plugin" after the "TestPlugin" and before the "{". The file should look something like this:

PHP:
package org.spigotmc.testplugin;

import net.md_5.bungee.api.plugin.Plugin;

public class TestPlugin extends Plugin {
}
Now we can create the plugin.yml file, so that BungeeCord recognizes that this is a plugin and tell it how to load it. Right click resources, and create a new file called plugin.yml. In this file, add the following:

Code (Text):
name: TestPlugin
main: org.spigotmc.testplugin.TestPlugin
We are almost done. It is now time to compile the plugin. Expand the Maven Projects pane on the left, expand your project, expand Lifecycle and double-click "package". Maven will now compile your project. Now, open your project's folder, and look in target for your plugin. Install it on your BungeeCord instance and start it. If a line like "05:18:33 [INFO] Enabled plugin TestPlugin version null by null" appeared, it worked, and you have created your first BungeeCord plugin!