How to pass on the command event to different CommandExecutor classes

Discussion in 'Plugin Development' started by xorinzor, Aug 15, 2014.

Thread Status:
Not open for further replies.
  1. So basically, I want to be able to use something like:
    • /wb help
    • /wb createstructure
    • /wb createpath
    • /wb startgame
    • /wb <etc>
    And instead of having a lot of if-else statements in 1 CommandExecutor class for each argument I was wondering how I can distribute these between individual CommandExecutor classes by passing on the event (or if there is a better solution available, please share).

    Thanks :)
     
  2. Offline

    TheDummy

    xorinzor One possible solution is to make a method for each sub command and use the if-else. Such as:
    Code:java
    1. public void createPath( String args[] )
    2. {
    3. // Do stuff
    4. }
    5.  
    6. public void startGame( String args[] )
    7. {
    8. // Do stuff
    9. }
     

  3. I guess thats one way of doing it, just not sure if that's the cleanest solution
     
  4. Offline

    Rocoty

    Think in a more object oriented way. This is where abstraction and inheritance comes in handy. Create an interface for SubCommands with declared methods for getting the command name and executing the command with a sender (and arguments). Classes can implement these methods for specific sub command handling and then in your actual command executor class you can have a list of instances of these classes and iterate over them to check if they are the right subcommand and act accordingly.

    HIH
     
Thread Status:
Not open for further replies.

Share This Page