Creating basic command functions in BungeeCord

Feb 20, 2016
Creating basic command functions in BungeeCord
  • Creating basic command functions in BungeeCord

    How to create your own BungeeCord commands



    BungeeCord supports a command interface, just like Bukkit. In this tutorial, we will create a simple "Hello World" command.


    Creating the command(top)


    Create a new class and call it HelloWorldCommand. This class should extend Command. Your IDE will now complain that you will need a constructor and an implementation of execute(). We will add the constructor first, then the execute() implementation.

    The constructor(top)


    Command has two constructors: a simple one with just a command name, and an expanded one with permission and aliases. We'll use the first one for now. Add the following code to your class:

    Code (Java):
      public HelloWorldCommand() {
          super("helloworld");
      }
    This will create a command that can be run by using /helloworld.

    The executor(top)


    Now we can add the actual meat of the command. Add the following code to your class:

    Code (Java):
      @Override
      public void execute(CommandSender commandSender, String[] strings) {
          commandSender.sendMessage(new ComponentBuilder("Hello world!").color(ChatColor.GREEN).create());
      }
    To be precise, the message "Hello world!" (in green color) will be sent to players running /helloworld.

    Registering the command(top)


    Add the following to your onEnable() method:

    Code (Java):
    getProxy().getPluginManager().registerCommand(this, new HelloWorldCommand());
    You have now created your command. Unlike Bukkit, BungeeCord does not require that you add your commands to your plugin.yml.
  • Loading...
  • Loading...