1.14.4 Config loading, I need youre help!

Discussion in 'Spigot Plugin Development' started by Veteranfighter, Feb 29, 2020.

Thread Status:
Not open for further replies.
  1. Since I have no idea what to write here I just start and yeah ^-^ , so I started programming a few weeks ago and spontaneously decided to program a simple ReportSystem, I started a few days ago and quickly realized that this would not be as easy as I had imagined because I wanted to make a list in which the reports would be saved when I had finished the whole thing and was already trying it I was shocked to hear that array lists are emptied after a reload and therefore not suitable for this purpose. So I tried a little bit and also found out that I can save the reports in a config. I did this right away and it worked, I could delete reports from ingame and save them. It would have been too nice if everything would have worked because I noticed that I could not load values from the config into the game as easy as from an array list. I already knew that I could load values one by one with cfg.getString("string"); but not how to load multiple values from a list... I got the idea that you can make a kind of counter that whenever a player reports that he gets an Int. The problem is that I don't have a plan how to do that, can you help me somehow, especially with the automatic increase or decrease of the int's, it would be great if you could write me something like that or if there is a better and easier way to do that, have a nice day

    - Veteranfighter
     
  2. There's a config#getStringList function to help you retrieve lists from configs.
    All you need for the counter is an int in some class (e.g your main class), that you can access and increase whenever someone uses your report command.
     
  3. cfg.getKeys(false) will return you a Set(kind of Collection like List) of all the keys. So, if your structure is like
    Code (YAML):

    string1
    : hacks! HACKS EVERYWHERE!
    some-string
    : lololololo
    another-one
    : Test
     
    keys are "string1", "some-string", "another-one".
    And you can just iterate it like
    Code (Java):

    for(String key : cfg.getKeys(false)) {
        list.add(cfg.getString(key));
        // Do other stuff
    }
     
     
  4. And when someone deletes a commans how can I do this?
     
  5. You should store the reports in a HashMap, and let the report ID (the int) be the key. Remove it when report is handled, so when you list them in-game you won't get handled reports.
     

  6. Something that I just started doing is implementing databases with SQLite into my plugins, and for this I highly recommend it, especially as the reports config file could get huge depending on server traffic and issues.
     
    • Agree Agree x 1
  7. But hashmaps get cleared when the Server restarts right?
     
  8. I sadly dont know how to do this. /:
     
  9. That's not a problem. There are a few tutorials on it and it is definitely something I would consider as important especially if you ever want to make larger plugins. The tutorial that I followed is:

    https://www.spigotmc.org/threads/how-to-sqlite.56847/

    Before doing this though, I definitely reccomend learning SQL and making sure you understand how databases work.
     
  10. Thank you!
     
  11. I tried it and it works (-:
     
  12. Awesome, I am glad it works, make sure to mark this thread as solved :)
     
Thread Status:
Not open for further replies.