Create your first BungeeCord plugin (Proxy)

Jul 20, 2017
Create your first BungeeCord plugin (Proxy)
  • Creating your first BungeeCord plugin

    How to get started with creating plugins


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

    Java knowledge is required for this tutorial.

    Note: If you are impatient and just want to start quickly, you can get a skeleton project using this tool, import it with File -> Import Project in IntelliJ IDEA or File -> Import -> Maven -> Existing Maven Projects in Eclipse (repeatedly clicking Next), and continue to read the other documentation on the wiki. You should also read this tutorial, particularly the compiling section.


    Setting up your Project(top)


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

    First, open your IDE and create a new project, and then select Maven. 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 me.username). 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. We will now add some content to this file. Add the following lines to it, before </project>:

    Code (XML):
        <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.6.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>

        <dependencies>
            <dependency>
                <groupId>net.md-5</groupId>
                <artifactId>bungeecord-api</artifactId>
                <version>1.12-SNAPSHOT</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>net.md-5</groupId>
                <artifactId>bungeecord-api</artifactId>
                <version>1.12-SNAPSHOT</version>
                <type>javadoc</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.

    Creating your main class(top)

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

    Right click java, then make a new package. Call it me.username.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 did not do so, open it now.

    Now, we can create our basic plugin. This page will only focus on making a plugin that does nothing except display a message when enabled; 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:

    Code (Java):
    package me.username.testplugin;

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

    public class TestPlugin extends Plugin {
        @Override
        public void onEnable() {
            // You should not put an enable message in your plugin.
            // BungeeCord already does so
            getLogger().info("Yay! It loads!");
        }
    }

    Making it load(top)

    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 (yml):
    name: TestPlugin
    main: me.username.testplugin.TestPlugin
    version: 1.0
    author: username
    You can also create a bungee.yml file if plugin.yml is already loaded by Bukkit.

    Compiling(top)

    We are almost done. It is now time to compile the plugin. Expand the Maven Projects pane on the right (If you don't see it, click on View and then on Tool Buttons), expand your project, expand Lifecycle, double-click clean, 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 [INFO] Enabled plugin TestPlugin version 1.0 by username appears, it worked, and you have created your first BungeeCord plugin! To recompile it, repeat these instructions.

    For Bukkit Developers(top)

    If you are a Bukkit developer, and anything seems remarkably familiar to you, it is because the BungeeCord API was heavily inspired by the Bukkit API. Many of the concepts (EventHandlers and Schedulers) remain the same, and some class and method names are the same.
  • Loading...
  • Loading...