Help storing player data?

Discussion in 'Plugin Development' started by AaronL98, Jul 18, 2013.

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

    AaronL98

    OK, so I'm new to Java and Bukkit kinda, but i have created a few plugins for my server. Now I'm creating a new plugin which I need to store data for the player. The plugin will be run on multiple servers (linked together with bungee cord) and i want to store a number of different variables for each player for example, the players level at combat etc which say the earned level 5 combat or something on server A and they hop onto server B and their combat level is still 5. I have seen other forum posts which are looking for ways to store data but I don't really think they fit my purpose. I have considered storing each players data in a yml file per player but I don't know how effective this will be and if it will work over multiple servers, I have also considered a MySQL database or SQLite but I have never experimented or used them before and don't really have a clue how they are used (except to store data). I'd really appreciate help and please remember, I'm kinda new to Bukkit, i would appreciate it if you are posting code to give me a short rundown of what each part of the code does :)
     
  2. Offline

    SuperOmegaCow

    AaronL98 I am trying the exact same thing just I don't even know how to store the hashmaps in YAML. Ya me :D
     
  3. Offline

    AaronL98

    SuperOmegaCow I Dont think you really can because hashmaps are cleared on /reload and server restarts
     
  4. AaronL98 this is hard guess, but if you have all those servers running in the same machine you can create a .yml file and save it on a location you want, and there access it throught the plugins, to that file location.

    Otherwise if they're not i cannot think of any other way but use some sort of Database to store all the data.
     
  5. Offline

    AaronL98

    The servers will be running on a dedicated machine I will be renting, though how would i achieve what im looking for? A per-player file which stores their info such as integers for what level they are and strings for what e.g. class they are?
     
  6. Offline

    SuperOmegaCow

    AaronL98 onDisable and reload you can save it to a YAML file I just don't know how.
     
  7. AaronL98 then i guess you can create a file on the root directory and save the .yml file Data there are acess it throught the plugins.
     
  8. Offline

    amitlin14

    What you are gonna need is this:
    http://forums.bukkit.org/threads/mysql-lib-fruitsql-super-simple-mysql-database-library.158207/

    plus some knowledge in MySQL(which you can learn practically everywhere, its very simple)
    here, ill even give you a snippet for free*:

    Code:java
    1. FruitSQL sql = new FruitSQL("localhost", "3306", "test", "root", "");
    2.  
    3. sql.createTable("crossServerStorage", new String[] {
    4. "id VARCHAR(16) PRIMARY KEY NOT NULL", "combatLevel SMALLINT",
    5. "otherStatYouWannaSave SMALLINT" });


    now when a player logs into a server, you check if the mysql table contains his name, if it does, grab the details, if it doesnt, insert a new line to the table containing his new stats:

    Code:java
    1. PreparedStatement st = connection.prepareStatement("INSERT INTO crossServerStorage(combatLevel,otherStatYouWannaSave) VALUES("+player.getName()+",0,0)");


    Youll get the hang of it once you start learning

    *Accepting these snippets for 'free' automatically registers you into the double value extra advantage snippet program which has a 10$ monthly fee and a 20$ registration fee on initial enrollment to the program. Cancellation fee is 40$
     
    TheTrixsta likes this.
  9. Offline

    AaronL98

    amitlin14 Thanks, but where can i find out more about fruitsql apart from its thread? I've looked for vids on youtube, ive googled it and nothing but the thread pops up.

    Buhmp

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  10. Offline

    amitlin14

    AaronL98 that is because it is a library created by one of the members in the bukkit community
     
  11. Offline

    AaronL98

    I think im going to go with the storing all yml files in a directory in my dedi-server, any ideas on how this could be done?
     
  12. Offline

    ChrisixStudios


    You can use the FileConfiguration and YamlConfiguration classes to read and write to a YAML file.
     
Thread Status:
Not open for further replies.

Share This Page