How to create commands in different classes

Discussion in 'Plugin Development' started by TheMCBukkitTut, Mar 7, 2014.

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

    TheMCBukkitTut

    hey there i need help into creating commands in different classes please could you help me by pasting a plugin.yml and Main + 2 command classes.

    Thanks jacob
     
  2. Offline

    tamajpm

    Maybe the answer to you're question:

    %Command% = The name of you're command.
    %ClassName% = The name of you're class outside the main class.

    The first thing you need to do is create another class with the name %ClassName%. After you did this you need to implements this with the CommandExecutor. If you did that you need to create the onCommand like normal. The class will look like this:

    %ClassName%:
    Code:java
    1. public class ClassName implements CommandExecutor {
    2. public ClassName() {
    3.  
    4. }
    5.  
    6. public boolean onCommand(CommandSender cs, Command cmd, String cl, String[] args) {
    7. if(cmd.getName().equalsIgnoreCase("%Command%")) {
    8. //Do something.
    9. return true;
    10. }
    11.  
    12. return false;
    13. }
    14. }


    After you did this you need to go to you're onEnable in the main class and put "getCommand("%Command%").setExecutor(new %ClassName%());". The onEnable will look like this:

    onEnable:
    Code:java
    1.  
    2. public void onEnable() {
    3. getCommand("CommandName").setExecutor(new ClassName());
    4. }


    I hope this helped you, if you have any questions you can pm me.
     
  3. Offline

    Jombi

    Perhaps you should read around a bit before asking us to write your plugin for you.
     
  4. Offline

    TheMCBukkitTut

    ok thanks :D
     
Thread Status:
Not open for further replies.

Share This Page