Created
September 5, 2016 07:14
-
-
Save DenWav/4788b307737c78b13f310c3bf273aa25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun getPlayerId(uuid: UUID) = | |
| synchronized(this) { | |
| if (playerMap.contains(uuid)) { | |
| return@synchronized playerMap[uuid]!! | |
| } | |
| // We don't have this UUID cached, so check the database | |
| var result: Int? = null | |
| // byte array representation of the UUID | |
| val array = uuid.toByte() | |
| connection.use { | |
| result = getFirstColumn("SELECT p.id FROM players p WHERE p.uuid = ?", array) | |
| if (result == null) { | |
| // This uuid isn't in the database yet, so add it | |
| val name = plugin.getPlayerName(uuid) | |
| // Only add it to the database if we can actually get a player name | |
| if (name != null) { | |
| executeUpdate("INSERT INTO players (uuid, name) VALUES (?, ?)", array, name) | |
| result = getFirstColumn("SELECT p.id FROM players p WHERE p.uuid = ?", array) | |
| } | |
| } | |
| } | |
| if (result != null) { | |
| playerMap[uuid] = result!! | |
| } | |
| return@synchronized result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment