Solved Remove from StringList in config

Discussion in 'Plugin Development' started by Roborack17, Sep 8, 2016.

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

    Roborack17

    Hey! Today, I was working on a plugin which saves strings to a stringlist in a config. BUT, after I save them, I want to somehow delete them but I don't know how. So, I don't want to clear stringlist, just remove a string line from a stringlist :D Hope you understand and reply soon ;)
     
  2. @Roborack17
    Get the string list from config, remove the entry, and save it to config again.
     
  3. Offline

    Roborack17

    Do you have any example for it? I actually want to remove string line by command like /remove 1 and it'll remove the first string I guess, so is it possible?
     
  4. @Roborack17
    Indeed, all you need to do is get the list from config like usual and save it to a variable. Then just use the "remove()" method, and then save the variable back to config.
     
  5. Offline

    Roborack17

    @AlvinB
    Well, how do save it to a variable? That's the problem I guess :)
     
  6. Offline

    Zombie_Striker

  7. Offline

    Roborack17

    I didn't find there what I was looking for. I looked to get the string line by typing the number of it and to remove it. Do you know to do that?
     
  8. @Roborack17
    I think it's time for some Java tutorials. Knowing what a variable is is an essential part of programming.
     
  9. Offline

    Roborack17

    I know what variable is, but I don't know how to turn string list to a varible :)
     
  10. @Roborack17
    Well, if you know how to get the list from config and know what a variable is, then you should be able to pull it off.
     
  11. Offline

    Roborack17

    But how do I get a string line?
     
  12. Offline

    Zombie_Striker

    @Roborack17
    To add onto what @AlvinB said, a variable is an object that can be referenced. To load a string out of a config, create a String variable and set it equal to the string from the config. If you don't know how to get an object from a config, please review the link.
     
    Last edited: Sep 9, 2016
  13. Offline

    Roborack17

    I do know how do get a string from a config, but not how to get a string from a string list. I think you didn't understand me very well
     
  14. @Roborack17
    Code:java
    1. getConfig().getStringList("path")
    ?
     
  15. Offline

    Roborack17

    @AlvinB
    Ok, I'm going to explain you a little bit more :)

    So, my string list in a config is like this:

    StringList:
    - String 1
    - String 2
    - String 3

    And I want to delete a string 2 by typing command like /string remove 2, but the String 2 is configurable and its content isn't always the same. There is command /string add string, and it adds the string to the string list. Hope you get it.

    Finally :D Thanks, I'll try it now

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 22, 2018
  16. Offline

    Zombie_Striker

    Do you mean List#get(index) and List#remove(index)?

    [edit] Yes, you are looking for this. Load the list, remove the object at that index (using List#remove(index). In your example, remove the object at index 1), and reset the list in the config.
     
  17. Offline

    Roborack17

    Thanks man! It worked :D
     
Thread Status:
Not open for further replies.

Share This Page