Custom Feudal Commands

From Feudal Wiki
Jump to: navigation, search

When using Feudal as an API, you can create sub-commands for Feudal which will be shown on /f help.

First create a class which extends us.forseth11.feudal.commands.Command. This class will have you add the following methods:

  • public HelpMessage[] getHelpMessage();
  • public Command.CommandType getType();
  • public boolean run(String[] args, Player p);

First lets go over CommandType. CommandType is an enum which is either PLAYER or SERVER. This tells feudal who can execute this command.

Next is the run method. The run method is called anytime someone types /f. You will need to check to make sure argument 1 matches what ever command you are making. If it does, return true at the end. This will tell Feudal that the command has been handled. Return true even if a player typed in your sub command but entered your arguments incorrectly.

From here you can handle run just like any other command, but keep in mind, if it is a SERVER command, p will be null.

Finally you have to return a help message. This is what will show up when someone types /f help. For most commands forget about the array and just make one HelpMessage. Each HelpMessage contains a permission String and a help message String. If a player has the permission in the permission String, then they will see this command in /f help.

If you want, you can register your command now. To register your command, after you checked to make sure Feudal is enabled, run the following:

Feudal.getAPI().addCommand(new YourCommandClass());

You may also want to make your command show up in a different place in the /f help list. To change the position your command is shown in /f help, you have to implement CustomCommand. CustomCommand will have you add the following method:

  • public int getHelpIndex();

In getHelpIndex(), you can return the index you want your command to be at. To place it at the beginning, return 0.

Here is an example custom command class. REMEMBER TO REGISTER YOUR COMMAND.

Pastebin Example