[TUT] How to check if the config contains a path ignoring case

Discussion in 'Resources' started by xGamingDudex, Nov 13, 2012.

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

    xGamingDudex

    If your config looks like this:
    Code:
    Test: hi
    TestBoolean: false
    how:
      are:
        you: good
        You: bad
    and use this code:
    Code:
    public boolean ConfigContains(){
    if(getConfig().contains("test")){
    return true;
    } else {
    return false;
    }
    it would return false, since the config contains "Test" not "test".
    To check if the config contains a string ignoring case use:
    Code:
      public boolean configContains(String arg){
            boolean boo = false;
            ArrayList<String> keys = new ArrayList<String>();
            keys.addAll(getConfig().getKeys(false));
            for(int i = 0; i < keys.size(); i++){
                if(keys.get(i).equalsIgnoreCase(arg)){
                    boo = true;
                }
            }
            if(boo){
                return true;
            } else {
            return false;
            }
    }
        }
     
  2. Offline

    Milkywayz

    I do something similar to this to add fields to config when I add a new configurable thing to my plugin, so that old configs have it automatically generated.
     
Thread Status:
Not open for further replies.

Share This Page