Command Executor with 1 command

Discussion in 'Plugin Development' started by iliasdewachter, Nov 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    iliasdewachter

    So hi Bukkit-Community,
    I would like to have 1 command:
    /base create
    /base teleport
    /base delete
    /base invite
    Etc...

    Abit of code:

    Main class
    Code:java
    1.  
    2. public void onEnable() {
    3. getCommand("base").setExecutor(new CommandHandler(this));
    4. }
    5.  


    CommandHandler class
    Code:java
    1.  
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    4. if (sender instanceof Player == false)
    5. {
    6. sender.sendMessage("Je moet hier een speler voor zijn!");
    7. return true;
    8. }
    9. Player player = (Player) sender;
    10.  
    11. if (cmd.getName().equalsIgnoreCase("createbase"))
    12. {
    13. commandBaseCreate(player, cmd, label, args); // how can I call this method from the next class?
    14. }
    15.  
    16. return false;
    17. }
    18.  

    CommandBaseCreate class
    Code:java
    1.  
    2. static public void commandBaseCreate(Player player, Command cmd, String label, String[] args) {
    3.  
    4. //Code
    5. }
    6.  


    But how can I call the method commandBaseCreate? Because it's in another class.
     
  2. Offline

    amhokies

    First off, your method header should be public static void... instead of static public void...

    It's as simple as doing the following:
    Code:java
    1. CommandBaseCreate.commandBaseCreate(player, cmd, label, args);

    With a static method, you can call the method from any class that has access to it without making an instance of the class that it's in.
     
  3. Offline

    The_Doctor_123

    Why don't you just make individual CommandExecutors for the commands?

    amhokies
    I don't believe any modifiers have to be in a certain order, but it's better to do it that way anyway.
     
  4. Offline

    amhokies

    The_Doctor_123
    Yeah, the way he does it there would technically work, but as you said it's best to do it the other way.
     
  5. Offline

    iliasdewachter

    amhokies

    Thanks mate, that fixed it, pretty strange but it works, thanks! :p
     
  6. Offline

    The_Doctor_123

    iliasdewachter
    Strange..? It's your code. Didn't you know how it would work?
     
Thread Status:
Not open for further replies.

Share This Page