MySQL name updating

Discussion in 'Plugin Development' started by arjanforgames, Aug 11, 2014.

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

    arjanforgames

    Hey guys I need some help,

    I'm trying to change the players name in the MySQL database whenever they have changed their name (not yet possible, but for later versions of MC). I'm using their UUID to check wether they are registered and that works. But im running into a problem because when I still have the same name it says: "Your name has been changed from NOTCH to NOTCH!"

    This is my code:
    Code:java
    1. PreparedStatement sql = connection.prepareStatement("SELECT name FROM `player_data` WHERE uuid=?;");
    2. sql.setString(1, player.getUniqueId().toString());
    3. ResultSet result = sql.executeQuery();
    4. result.next();
    5. String playername = result.getString("name");
    6.  
    7. if(player.getName() != playername){
    8. player.sendMessage(ChatColor.WHITE + "[" + ChatColor.DARK_AQUA + "MC" + ChatColor.WHITE + "] " + "Your name has been changed from " + ChatColor.ITALIC + playername + ChatColor.WHITE + " to " + ChatColor.ITALIC + player.getName() + ChatColor.WHITE + "!");
    9. PreparedStatement updateName = connection.prepareStatement("UPDATE `player_data` SET name=? WHERE uuid=?;");
    10. updateName.setString(1, player.getName());
    11. updateName.setString(2, player.getUniqueId().toString());
    12. updateName.executeUpdate();
    13.  
    14. updateName.close();
    15. }
    16.  
    17. sql.close();
    18. result.close();
     
  2. Offline

    Garris0n

  3. Offline

    arjanforgames

Thread Status:
Not open for further replies.

Share This Page