onCommand()

Discussion in 'Plugin Development' started by Flammantis, Sep 19, 2011.

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

    Flammantis

    Me again ;)

    So basicly I've been trying to make another update to my plugin ChatSentry. But to implement this feature I need to now how to make it so that admins can type /csedit list-of-words, which will set the banned-words list in the config file. I can do the config file bit yet I can't get the info from /csedit list-of-words. I'm using
    PHP:
        public boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args){
    and I think it's the String[] args, yet I can't figure out how to put the info into a variable.
    Thanks.
     
  2. Offline

    obnoxint

    If you type the command "/csedit one two three", args[0] contains "one", args[1] contains "two", and so on.
    I don't know if this answers your question, because there is no question at all.
     
  3. Offline

    ItsHarry

    Basically, args is an array with all the arguments after the command.
    Example:
    If you typ /csedit hello poop random bla
    then:
    args[0] = hello
    args[1] = poop
    args[2] = random
    args[3] = bla
     
  4. Offline

    Flammantis

    Well my question if how I would get a list of words into a string/string as list from an array
    Code:
    List<String> words = Arrays.asList();
    Cool thanks
     
  5. Offline

    ItsHarry

    Oh. Just use

    for (String asd : args) {
    words.add(asd);
    }
     
  6. Offline

    Flammantis

    OK thankyou :)
     
  7. Offline

    ItsHarry

    np
     
  8. Offline

    Flammantis

    Oh I just noticed one thing, is there anyway to add to the config instead of set?

    EDIT: done, figured it out :)
    EDIT2: OK actually haven't figured it out, any help would be appreciated.

    OK I think I've figured it out, it's just when I type /csedit it just says /csedit back at me. Any help? Here is my plugin.yml.
    Code:
      csedit:
          description: Edit banned-words
          permission: ChatSentry.csedit
          usage: |
                     /<command>
    Also will this work?
    PHP:
                for (String words args) {
                    List<
    Stringwords1 null;
                    
    words1.add(words);


                
    config getConfiguration();
                
    words1.add((String) config.getProperty("banned-words"));
                
    config.setProperty("banned-words"words1);
                return 
    true;
                }
            } 
    Oops I notice a little unneeded var(gone now)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  9. Offline

    SilverstarX

    Whats the source of the onCommand() you are using?

    Try it? Looks ok on a quick look.
     
  10. Offline

    Flammantis

    Nope I've tried it but it doesn't work, I've edited my code. It can't edit the file for some reason unknown to me, and I'm putting that as a side project because someone has requested an auto-kick. The only thing not working with the auto kick is writing it to the config file. Here is the code:
    PHP:
    //onEnable() code up here
            
    config getConfiguration();
            
    boolean word false;
            if (
    configFile.length()==0) {
                List<
    Stringwords Arrays.asList("crap","bum","idiot","noob");// Add some defaults to the banned-words list.
                
    config.setProperty("banned-words"words); // Set the list of banned words.
                
    config.setProperty("auto-kick"word); // Set the property auto-kick.
                
    config.save(); 
     
  11. Offline

    SilverstarX

    Ah, I saw something. Okay, hm, please paste your current, whole onEnable() and onCommand() methods please, including the onCommand(foobar...) line etc.
     
Thread Status:
Not open for further replies.

Share This Page