Solved If config list is empty

Discussion in 'Plugin Development' started by dajako, Nov 24, 2013.

Thread Status:
Not open for further replies.
  1. I am making a team plugin. If every player from a team leaves I want the team to be deleted.

    Some of my code:
    Code:java
    1. public String[] inteam = {};
    2. getConfig().set("team." + args[1], Arrays.asList(inteam));


    I have 2 questions:
    How can I check if a config list is empty?
    How can I delete a path and everything contained in the path within a config file?
     
  2. dajako
    1. This is how I typically do lists:

    Code:java
    1. List<String> list = getConfig().getStringList("some string"); //define the list
    2. list.add(something) //add something to the list
    3. getConfig().set("some string", list); //set it in the config
    4. this.saveDefaultConfig(); //save the config
    5. this.reloadConfig(); //reload the config

    2. Simply set it to null:

    Code:java
    1. getConfig().set("some string", null);
     
  3. Any idea for how I can check if it's empty though? Would I just get the path and use an if statement for if it's equal to null?
     
  4. dajako
    Basically

    Code:java
    1. if (!(getConfig().getString("some string") == null){
    2. //if the string isn't null, do something...
    3. }else{
    4. //do some stuff if it is null
    5. }
     
    dajako likes this.
  5. Thanks!
     
  6. np :)
     
Thread Status:
Not open for further replies.

Share This Page