Checking if a player has logged in before.

Discussion in 'Plugin Development' started by Daniel Heppner, Apr 25, 2011.

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

    Daniel Heppner

    Hello, I'm making a plugin that will check to see if the player, upon logging in, is new, and if he/she is, it'll give them a welcome inventory.

    What I'm wondering is how I should go about checking to see if a player has logged in before. Should I use persistence? A text file? Yaml?

    Also, how should I do the config file? Yaml (I don't like Yaml)? Json? Text file?

    Anything, I need your suggestions and help. Thank you.
     
  2. Offline

    CypherX

    Personally, I would use persistence to store the names of players that have logged in before. All you would really need is two fields, Id and playerName. Then when a player joins the server you would just query the persistence table for the player's name. If it returns null, then they've never been on the server so give them the welcome inventory and add their name to the database.

    As for the config file, I recommend just using Bukkit's Configuration class (which unfortunately for you is Yaml).
     
  3. I don't really know how to use persistence so if you want a simpler, but slightly less efficient way:

    • On player login - load text file and loop through all the names
    • If name is found then do nothing
    • Else, if name found give the player the starting inventory and add their name to the file.
     
  4. Offline

    Sammy

    No no no, no need of making a file or looping through all the names:
    Code:
    File plydat = new File("world/players/"+ JonhDoe.getName() + ".dat");
    if(! plydat.exists())
    {
    //wtf boom !!!
    }
    If the player is new, the JonhDoe.dat won't exist
     
    Daniel Heppner and RonnSama like this.
  5. You could use SQLite maybe, but I have no Idea on how to do that :p
     
  6. Offline

    Xaw4

    in this case its helpfull, that Minecraft crates a file for every player ...
     
  7. Offline

    Daniel Heppner

    That is an awesome idea, thank you Sammy!

    I'm doing this plugin more to learn, I'm aware there are already plugins that can do similar things. :D
     
  8. Offline

    Sammy

    Thats a great way to learn, after doing it have a look at similar plugins, they may help you =)
     
    Daniel Heppner likes this.
  9. Thats what I do, remake plugins pretty much to learn then add unique features :p

    I've learnt a lot, just need to move on to databases and file storage & records :)

    Yay, just got plugin developer status :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 14, 2016
Thread Status:
Not open for further replies.

Share This Page