Solved Initializing commands

Discussion in 'Plugin Development' started by Aragone, Jul 15, 2019.

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

    Aragone

    Hello !

    When I want to initialize a command in my onEnable() method, I proceed like that :

    https://pastebin.com/raw/YqA5XBDw

    Some persons of this forums said to me that it could be better if I initialize the commands with a variable. How can I do that ? Is it to make the code better and less heavy ?

    Thanks for your help !
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Aragone Make a field for each type of command class that you have.
     
  3. Offline

    Aragone

    @timtower Can you be more precise ?

    @KarimAKL said to me in an old thread : "Also, don't create two instances of your CommandHome class when you register the commands, make a variable with an instance and pass the variable when you register the commands."
     
  4. Online

    KarimAKL

    @Aragone I meant something like this:
    Code:Java
    1. YourCommandClass fieldName = new YourCommandClass();
    2. JavaPlugin#getCommand("YourCommand").setExecutor(fieldName);
     
  5. Offline

    Aragone

    It works well, thank you.
     
Thread Status:
Not open for further replies.

Share This Page