Solved Config Problems When Getting From It

Discussion in 'Plugin Development' started by EscapeMC, Jan 22, 2018.

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

    EscapeMC

    So I have a stupid problem and it is driving me nuts. I am trying to get from the config onEnable and for some reason even though I know there is content where I am trying to grab from, nothing is coming up when I do getConfig().getStringList("#the location#").

    Some things you'll want to see:
    Code:
        public List<String> getAndSetArenaNames(){
            arenaNames.clear();
            for(Arena a : arenas){
                arenaNames.add(a.getName());
            }
            return arenaNames;
        }
    
    This generates the list of all of the arena names, which is successful.

    onDisable had this, which sets the config
    Code:
    getConfig().set("arenaplugin.arenas", am.getAndSetArenaNames());
    
    The config is this, in case anyone wants to see a basic result.
    Code:
    arenaplugin:
      arenas:
        one: []
    
    And my problem is
    Code:
    loadingList = getConfig().getStringList("arenaplugin.arenas");
    
    gives me nothing (it is in onEnable).

    Thanks for the help, and if I need to give more information I will be glad to.
     
  2. Offline

    RunsWithShovels

    @EscapeMC Try to debug by sending messages to the console.

    Try sending a message like this.
    getserver.getconsolesender.sendmessage("This is in loadingList : " + loadingList) to see if your even populating it.

    But I'll tell you, that youre not trying to get a list. You need to get a configurationsection.
     
  3. Offline

    ipodtouch0218

    You have to use the saveConfig() method after writing to the config.
     
  4. Offline

    EscapeMC

    @RunsWithShovels I have tried that and yes, it still gives off nothing. I even have a check to see if it is equal to another list that is blank as well, and it comes as true.

    EDIT: not sure what you mean by to get a configuration section, because the place in my config "arenaplugin.arenas" is not a configuration section, it is a List<String>


    @ipodtouch0218 I did, I even said in the thread that the config gives result (it saves correctly)
     
    Last edited: Jan 22, 2018
  5. Offline

    RunsWithShovels

    @EscapeMC

    This is a configurationsection:
    Code:
    arenaplugin:
      arenas:
        arena1:
        arena2:
    arenaplugin.arena is a section within a configuration.

    This is a stringlist
    Code:
    arenaplugin:
      arenas:
        - arena1
        - arena2
     
  6. Offline

    EscapeMC

    @RunsWithShovels Ok, that is something. I am saving to the config with getConfig().set(List<String>, "arenaplugin.arenas"), is there something else I should be doing?
     
  7. Offline

    RunsWithShovels

    Your setting seems alright. Its the getting part.

    Set<String> arenas = getconfig.getconfigurationsection("arenaplugin.arenas").getkeys(false);

    then print out arenas in a debug message and see if you get the file contents then.

    getkeys is a boolean that says whether or not it should grab all children keys or not, in this case you only want to get the arenas, so it is set to false.
     
  8. Offline

    EscapeMC

    I figured it out.
    So, I was setting arenaplugin.arenas as a String list

    BUT

    then, when I was setting the teams for each arena, it would override it, putting it as a configuration section.

    So, I will now be moving the teams tab in the config :D

    Thank you @RunsWithShovels for helping me realize this error.
     
  9. Offline

    RunsWithShovels

    @EscapeMC No problem, glad you got it working.
     
Thread Status:
Not open for further replies.

Share This Page