Solved Public args

Discussion in 'Spigot Plugin Development' started by Creepermanthe3rd, Jun 28, 2016.

  1. I was wondering if it is possible to make args from a command public.

    So I could get the args from a command and use those arg in another class.

    If so if anyone could tell me that would be great!
  2. You could just make a global String array, and set it to the args passed in onCommand
  3. It would be better to simply pass it to a method in the other class.
  4. Firestar311


    Or use a String[] object of the arguments of the method in the other class, and pass it on when you need it. But it all depends on the context of your code
  5. how?
  6. public String[] args = *get all args from onCommand method*
  7. Firestar311


    Whatever class you have your onCommand method in, create a global variable (public) like this
    Code (Text):
    public String[] args
    Then when you need it in the other class, just call the class that the args variable is in
    Code (Text):
  8. If you want to use ClassName.args without an instance, the field args would need to be static.
  9. I figured it out! Thanks for the help
  10. You do realise that this is horrible code design, right?
    • Agree Agree x 1
  11. I..

    I tried reading this, and i am still really confused..

    Do you want to permanently store the argument strings, or just use them once? Do you know any java at all?

    What are you actually trying to do, as an end-result?