Creating basic command functions in BungeeCord

Jan 4, 2021
Creating basic command functions in BungeeCord
  • Please read this guide for the first time creating a BungeeCord plugin!

    Basic introduction
    First, make a new Package (In this tuturial it will be called "test"). In this package make a new class with the name Test (this is going to be our Main.java).

    This is the blank BungeeCord plugin code.
    Code (Text):
    package test;

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

    public class Test extends Plugin {

        @Override
        public void onEnable(){
     
        }
    }
     
    Now, because we're going to bring a structure into this plugin we're going to make a second package which name is commands.
    In this package make a new Class, which name is Lobby, because first we're going to make a single /lobby command.

    Creating a /lobby command
    So for now we're going to make a new command. First we do something like this:
    Code (Text):
        public class Lobby extends Command {

            public Lobby() {
                 super("Lobby");
            }
    After you've done this we make the command itself:
    Code (Text):
            public void execute(CommandSender sender, String[] args) {
                  }
    Now we will add some code for the plugin to check whether it's a player sending or console sending that command.
    Code (Text):
            public void execute(CommandSender sender, String[] args) {
                if ((sender instanceof ProxiedPlayer)) {
                  ProxiedPlayer p = (ProxiedPlayer)sender;
                  p.connect(ProxyServer.getInstance().getServerInfo("lobby"));

       
                }
    So for example this will send the player to a server, which name is lobby.

    To integrate a message, use
    Code (Text):
    p.sendMessage
    to send a message.
    Code (Text):
            public void execute(CommandSender sender, String[] args) {
                if ((sender instanceof ProxiedPlayer)) {
                  ProxiedPlayer p = (ProxiedPlayer)sender;
    p.sendMessage(new ComponentBuilder ("Connecting you to the lobby!").color(ChatColor.RED).create());    

    p.connect(ProxyServer.getInstance().getServerInfo("lobby"));

       
                }
    This will display "Connecting you to the lobby!" before the player is going to be connected to the lobby. For more informations about the Chat Components see this.

    Now, we have to import our Lobby class into the plugin. For this go into the Test Class (Main) and add this:
    Code (Text):
    ProxyServer.getInstance().getPluginManager().registerCommand(this, new commands.Lobby(this));
    to register the command.

    The code will should be looking similar to this:
    Code (Text):
    package test;

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

    public class Test extends Plugin {

        @Override
        public void onEnable(){
            ProxyServer.getInstance().getPluginManager().registerCommand(this, new commands.Lobby(this));
        }
    }
     
  • Loading...
  • Loading...