[SOLVED] Simple question about configs

Discussion in 'Spigot Plugin Development' started by dadus33, Jul 2, 2015.

  1. I've always got a problem with understanding how memory stuff works... But I want to make some things clear for me:
    Firstly, I want to know whether it's necessary or not to save the config to disk each time you edit it... I mean, I usually did that only when running the plugin's reload command, but I don't know for sure if it's right or not. Let me explain you exactly what I mean:
    Let's say we want to save the last location a player teleported from into a data file, like this:
    Code (Text):
    AwesomeDude2341:
      lastloc: 120.0, 25.0, 31.0, world
    However, I don't want to save the config (yet). A few seconds later, I need to get that location with getConfig().getString("AwesomeDude2341.lastloc"). Will it work? Or do I have to save the config first? That's what I did till now, but I wasn't sure if that was the most efficient way to do it. Thanks!
     
  2. Make an instance of lastloc and use it like:
    Code (Text):
    getConfig().getString(p.getUniqueID + .LastLoc));
     
  3. Thank you, but that was just an example, I'm actually using the yml file to store data about the player. I only asked whether is it possible to get those values without saving them to disk, and fortunately found out I can!
     
  4. JustThiemo

    JustThiemo Previously TrinityDEV

    I would do it like this:
    Code (Text):
    MyFancyUserName:
      lastLoc:
        x: 1
        y: 1
        z: 1
        pitch: 1
        yaw: 1
    And then just new Location(bladiebla, config stuff)
     
  5. Thanks, but this is irrelevant. As I said, that was only an example, in fact, I'm not even trying to store a location into the config. I managed to solve my problem, as I stated in my latest post:
    But I guess it's my fault, I should have tagged this thread as solved.
     
    #5 dadus33, Jul 2, 2015
    Last edited: Jul 2, 2015