Plugin Help how to get all strings that begin with a certain word

Discussion in 'Plugin Help/Development/Requests' started by Randomguy, Aug 7, 2015.

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

    Randomguy

    how to get all strings that begin with a certain word is what I have a question about... Basically I want to read in everything a player adds in the config that begins with a key word... like for example, if someone writes in the config "smile1", I want it to check every one and do something with every String that has the word smile somewhere in it. I think this is possible, but not certain how. I have no code or errors or anything so don't ask for code... THX

    I think its
    Code:
    this.getConfig().contains(arg0);
    but it gives me an error when I put a string there... asking for a boolean

    Is this how it's used?
    Code:
    if(this.getConfig().contains("option1"))
                {
                   
                }
     
    Last edited by a moderator: Aug 7, 2015
  2. Offline

    Scorpionvssub

    First of might be best to get the words from the config into some form of a string like an ArrayList or Array in general, then something like if (this.<arrayname>.contains(args[0]) { //do something }

    not sure but that i reckon would work best
    Code:
    if (plugin.myarray.contains(args[0])) {
    p.sendmessage("Please dont do that")
    }
    Replace plugin with this, or leave it out completely if "this" isnt required


    But dont quote me on this, :p
     
  3. @Randomguy This is easy to do, but we would need an example of your configuration file. Are you using a String List, or a bunch of different sections? The difference is one could be called in using getConfig().getStringList( path ), and the other getConfig().getConfigurationSection( path ).
     
  4. Offline

    Randomguy

    I was thinking in a config, you enter something after it, but there are a certain amount of options. And you can add more options, like option1: option2: option3: and you can add more options after that, so I can't make a list if I don't know how much options... I think

    something like this:
    Code:
    #ADD YOUR OPTIONS AFTER EACH OPTION. TO ADD MORE OPTIONS CONTINUE THE LIST EXACTLY!
    option1:
    option2:
    option3:
    option4:
    option5:
    I'm not sure this is possible but maybe get everything that begins with option and add it to a list?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  5. Offline

    Randomguy

    how would i register each option? could I do something like while getConfig().hasNextLine()? (Not sure that exists)
     
Thread Status:
Not open for further replies.

Share This Page