Best Method To Save Values To Memory

Discussion in 'Plugin Development' started by Flemingjp, Mar 18, 2013.

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

    Flemingjp

    Hello All

    Im currently developing a plugin in where the player has various skills and trades in which they can upgrade. The skills and trades are saved in a individual yml file for the respective player. The player will have about 20-30 ints which will be their skills levels.

    Whats the best/effecient way of storing the values once they have been loaded from the yml?

    Ive asked around on the IRC but im unsure which is the best and how to implement them.

    Some suggestions;
    • Hashmaps - One per int (20-30 in whole)
    • MetaData - Store in the players object. Saved frequently and on players exit.
    • New Seperate Object - Create a new object per player and store the values in there. Most unsure about

    YML Format.

    Code:
    Levels:
      SkillA: 12
      SkillB: 5
      SkillC: 3
      SkillD: 19
     
        
    Any help will be much appreciated,


    Thanks Flemingjp
     
  2. Offline

    skipperguy12

    Why are you looking for best?

    You listed three perfectly good ways, there will be nearly no difference with performance if you use one over the other.
    If you need help with any, then ask!
     
  3. Offline

    Tirelessly

    A new object would be the best way to do it, in my opinion. It'd be the most organized.
     
  4. Offline

    ELCHILEN0

    I would use the object approach. HashMaps may be good when you only have one value to save/load; however, when you have multiple values per player an object oriented approach seems like the best way.
     
  5. Offline

    Flemingjp

    Aha using an object is the method I'm most unsure about. How would I create a new one when a player joins, how would I add/values to it and remove it when the player disconnects?
     
  6. Offline

    bleachisback

    These are basic concepts that you learn when learning to program in an OOPL.

    Also, you can assign these values to memory from a yaml file simply by using getConfig() in your plugin. Adding and removing values are as simple as using config.set().
     
  7. I suggest a HashMap with a custom class, e.g. Map<String, PlayerAttributes>

    If you want to save them you can use the config system instead OR you can make your new class implement ConfigurationSerializable, read about that here: http://wiki.bukkit.org/Configuration_API_Reference#Serializing_and_Deserializing_Objects then you can save the entire class to a config for each player.

    You don't need Bukkit's MetaData if you don't want to share your values with other plugins in a common manner.
     
  8. Offline

    Flemingjp

    Aha I was going to make an edit about that, Oracle website has loads of docs about objects starting on the basic level :-P
     
Thread Status:
Not open for further replies.

Share This Page