Solved Best way to store player data?

Discussion in 'Plugin Development' started by LordPyrak, Dec 8, 2013.

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

    LordPyrak

    Hello, I just started learning java a few days days ago. To help teach myself, I'm making a plugin that lets each player have skills (Woodcutting, mining, slaying, etc). What would be the best way to store the players level and experience in each skill, and have it available to all the classes in my plugin? I've seen some people say that using a hashmap is the best option for things like this, but I'm having a hard time finding any tutorial to fit what I need to do.
     
  2. Offline

    Wolfey

    You could use a config, like this: config.set("levels." + p.getName(), level);
    and then to get the level of a player: config.getInt("levels." + p.getName()); // if it is an integer
     
  3. Offline

    LordPyrak

    Ok, I found a tutorial on using config's to store data, but i can't seem to do it in classes other than my main class.​
    I have this:
    Code:
    final FileConfiguration config = this.getConfig();
    in my onEnable(), but I get errors when I try to read it in another class (a PlayerJoinEvent to be specific). I've tried placing this in my listener (from this tutorial - http://forums.bukkit.org/threads/config-from-another-class.61899/):​
    Code:
    Main plugin;
    public PlayerJoinController(Main instance) {
    plugin = instance;
    }
    
    But my Main class gives an error saying "The constructor PlayerjoinController() is undefined"
    I've tried moving my code around to fix it, but nothing seems to work. Any advice?​
     
  4. Offline

    xTrollxDudex

    LordPyrak
    PHP:
    new PlayerjoinListener(this)
     
  5. Offline

    LordPyrak

    Finally figured it out! :D
    I needed to change
    Bukkit.getPluginManager().registerEvents(new PlayerJoinController(), this)
    to
    Bukkit.getPluginManager().registerEvents(new PlayerJoinController(this), this)

    Such a big headache over one word :/

    Wolfey Thanks for the info <3
    xTrollxDudex Thanks for putting me on the right path <3
     
  6. Offline

    Garris0n


    Hah, welcome to programming...
     
Thread Status:
Not open for further replies.

Share This Page