How to save points properly?

Discussion in 'Plugin Development' started by Tomass, Dec 28, 2015.

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


    Hello guys,

    I have one theoretical question: how to save points properly into mysql database? I know how to send info to the database and stuff. But.. sometimes my points reset. I don't even know why. Now, I'm sending info to mysql when player leaves the game (PlayerQuitEvent) and onDisable(), but sending through Asynchronously Task (only on PlayerQuiteEvent). Maybe there are some more places where I should send player info?

    Thanks guys!
  2. Offline


    Maybe you can create a file or even save it in a config.yml

    I've tried using my config to store data and it worked pretty well.
  3. Offline


    @The_BloodHound I don't think that's what hes aiming for.

    @Tomass What i think could be happening is this:
    When you try to save the data with an asynchronous task, bukkit doesn't have the time to wait for your task to finish running. I could be completely wrong, as I do not have much experience with mySQL databases (I'm more of an sqlite person)
    Any reason your making it run asynchronously rather than making is synchronous with the server?
    Also any reason your making it run as a task?
    Is there delay for the task?
    That could ALL be causing your problem
  4. Offline


    This way to store players points/stats is not effective and optimized.


    I use asynchronously task because MySQL queries have some delays and it might cause some sort of lag. I have tested it and it proves my assumptions. And onDisable() I don't use any tasks, I send info to database directly. Anyway, thanks.

    Maybe someone has any suggestions?

    BUMP. Please help me!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Dec 29, 2015
  5. Offline



    Are you sure there aren't mistakes your queries? Are you using transactional databases incorrectly? We have no clue how to answer your question without seeing your code.
  6. Offline


    Okey, you also save points in QuiteEvent and onDisable? Maybe PlayerQuiteEvent sometimes doesn't activate, for example, when client crash or something else?
  7. Offline


    It does. There are two ways a client can disconnect:
    A) He sends a packet about his login information (I think 0x1 is the logout, or 0x3)
    B) He doen't answer to ping packets.
    Either way, the server closes the socket with the players
  8. Offline


    Good afternoon,

    Could you perhaps upload your MySQL query? Without seeing that we can't fix much.

    Without that query, my guess is that you are overwriting an entry. Are you using the MySQL command Insert or Update?
Thread Status:
Not open for further replies.

Share This Page