Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ object DatabaseManager {
this[Tables.Actions.blockState] = action.objectState
this[Tables.Actions.oldBlockState] = action.oldObjectState
this[Tables.Actions.sourceName] = getOrCreateSourceId(action.sourceName)
this[Tables.Actions.sourcePlayer] = action.sourceProfile?.let { getOrCreatePlayerId(it.id) }
this[Tables.Actions.sourcePlayer] = action.sourceProfile?.let { getOrCreatePlayerId(it.id, it.name) }
this[Tables.Actions.extraData] = action.extraData
}
}
Expand Down Expand Up @@ -594,8 +594,16 @@ object DatabaseManager {
].id.value.also { cache.put(obj!!, it) }
}

private fun getOrCreatePlayerId(playerId: UUID): Int =
getOrCreateObjectId(playerId, cache.playerKeys, Tables.Player, Tables.Players, Tables.Players.playerId)
private fun getOrCreatePlayerId(playerId: UUID, playerName: String): Int {
getObjectId(playerId, cache.playerKeys, Tables.Player, Tables.Players.playerId)?.let { return it }

return Tables.Player[
Tables.Players.insertAndGetId {
it[Tables.Players.playerId] = playerId
it[Tables.Players.playerName] = playerName
}
].id.value.also { cache.playerKeys[playerId] = it }
}

private fun getOrCreateSourceId(source: String): Int =
getOrCreateObjectId(source, cache.sourceKeys, Tables.Source, Tables.Sources, Tables.Sources.name)
Expand Down