Solved Saving and retrieving Data From an Arraylist.

Discussion in 'Spigot Plugin Development' started by luwie556, May 7, 2017.

  1. Hello title says most of it but for some background I'm making a FactionNameBlacklist plugin which basically denies players from creating and renaming their factions to the names in the list and Im having trouble saving the data in the config since on reload it clears the data, i did some researching around but none of it gets to a solid answer. If you are able to go and help please do so.

    Main Class:
  2. When the plugin enables you're instructing it to set the configuration value to that blacklist variable. Well that list is going to be empty as no data has been inserted yet (any thing added previously won't persist beyond that reload).

    Basically you're having the plugin cancel itself out.
  3. Yeah i see what you mean, I just really added the ondisable method when i was poking around to find out how to do this. Is there an efficient way to save the confg after data has been added when the plugin disables since when the server is reloaded or restarted the data is cleared.
  4. I'm going to assume that "/nameblacklist" already properly handles the parsing of user-input & inserts that data into your list there.

    You have a few options:
    • Save the list every time it's updated (in other words, upon the command's execution)
    • Keep the list purely in memory until the plugin is disabled; then save it. (what you're trying to do now)
    • Save the list on a timer (bad news; probably shouldn't do this)

    I'm going to continue doing what you're already doing though. Our problem originates from onEnable()... instead attempting to set the value, load it instead! This way your data may persist from reload to reload. Using getStringList(String)

    For example:
    Code (Text):
    // modified
    public void onEnable()
        list = getConfig().getStringList(...)

    // already done
    public void onDisable()
       getConfig().set(..., list);

  5. Im more or less attempting the first option, because in my commandexecutor's code if you add something to the list of names it sets the list to the arraylist saves the config and reloads it, but then it works but when the plugin disables the config is wiped (which im wanting to save).

    EDIT: Command's Code if you are wanting to look at it.
    #5 luwie556, May 7, 2017
    Last edited: May 7, 2017
    • Like Like x 1
  6. Remove the reloadConfig() lines. It resets the default values; could be clearing your list.
  7. Tried both same result prevails each time
  8. Speaking to the noobs like me seeking this issue.
    if you look at my main class make sure you have an if statement around it says if it doesnt contain your list to create it. and then you should be good.