Update MySQL player ranks

Discussion in 'Spigot Plugin Development' started by helmwet, May 5, 2017.

Thread Status:
Not open for further replies.
  1. I have a server and a self-made permission plugin that includes also ranks from a MySQL database.
    Admins can do /setrank or /setdonorrank to players in order to update their ranks. Then it will change their rank in the database.

    For example: /setrank Notch Moderator

    My player_data table has these columns:
    - uuid
    - playerName
    - rank
    - donorRank

    Then I will just update rank/donorRank according to playerName.

    Every time a player joins I update their playerName in the database due to name changes.

    Let's imagine a situation that a player called "Notch" has registered to the server, and then he has changed his name to "Notch2". "Notch2" hasn't connected to the server ever again... Then another player has changed his name to "Notch". "Notch" joins the server. Now there are two "Notch"es and if I set "Notch"'s rank to helper then I won't be able to control which player will be changed.

    I want you guys to give me ideas how to solve that issue.
    I think that I may get rid of playerName and fetch the UUID of a player from their name somehow from an API.

    What do you think should I do?
     
  2. I have two solutions for you:

    1st: You cann loop through the OfflinePlayers of your server and check if multiple entries exist. (Their names shouldn't be updated if they don't join the server; Not sure about this one) Then you print out an error saying that there are multiple entries and that you should specify the user you mean.
    (E.g. "Multiple players with the name 'Notch' have been found. Please specify the player you mean:
    1. Notch | Online
    2. Notch | Last played on: >Whateverday<")
    Then you'd have to implement a index parameter into your command (/setrank <player> <rank> [index]) where if the index parameter is present the command automatically chooses the given index on the list you printed out earlier.

    2nd: You can use Mojang's name history API and update the "other Notch's" current user name. (PlayerJoinEvent)
     
  3. In the event there are two "Notch" players you can simply ORDER BY for your sql and utilize the user with the newest timestamp on their name (it'd be good to track a column "last_updated" or such, which has the ON_UPDATE_CURRENT_TIMESTAMP attribute or is manually set when the name is updated).
     
  4. Just use UUID's as Primary key, that works great for me :D
     
  5. Yes, but I need to specify the player's name instead of UUID, and I don't use getPlayer or getOfflinePlayer because I have dynamic lobbies with BungeeCord.

    Thank you, but I used Mojang's API in order to avoid duplicates if I want to modify the table manually.

    Thank you guys, the problem is solved.
     
Thread Status:
Not open for further replies.