save arraylist of enums to config

Discussion in 'Plugin Development' started by Reinified, Dec 23, 2018.

Thread Status:
Not open for further replies.
  1. as the title suggests, I have an arraylist of Enums I need to save to my config. How do i do that?

    Thanks in advance.

    Edit: More importantly, how do I load the arraylist back into my plugin (with the enums usable, not as strings)
     
    Last edited: Dec 23, 2018
  2. Offline

    Robnoo

    Hi,

    I have 2 suggestions:
    1) Iterate over the array and add every Enum.toString() followed by a "," to a normal string. You can save that string in your config. You can recreate the array from the string using getConfig().getString(YourKey).split(","). Iterate over that new array and save every element in a new array with your EnumType using EnumType.valueof(element).
    2) Add every element of the array to an ArrayList and save that list into your config. I recommand here too to convert to a string. Iterate over the arraylist and add every item to a new array to get back your original array.
    This is what I can think of from my own experience. There are probably way more solutions.

    Robnoo
     
    KarimAKL likes this.
  3. Thanks for the suggestions, I'll try that out now.
     
  4. Offline

    The_Spaceman

Thread Status:
Not open for further replies.

Share This Page