|
| 1 | +/* |
| 2 | + * Copyright 2025 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.network.mojang |
| 19 | + |
| 20 | +import com.lambda.network.LambdaHttp |
| 21 | +import com.mojang.authlib.GameProfile |
| 22 | +import io.ktor.client.call.* |
| 23 | +import io.ktor.client.request.* |
| 24 | +import java.util.UUID |
| 25 | + |
| 26 | +/** |
| 27 | + * Gets a game profile from a username |
| 28 | + * |
| 29 | + * Example: |
| 30 | + * - name: jeb_ |
| 31 | + * |
| 32 | + * @return result of [GameProfile] |
| 33 | + */ |
| 34 | +suspend fun getProfile(name: String) = runCatching { |
| 35 | + LambdaHttp.get("https://api.mojang.com/users/profiles/minecraft/$name").body<GameProfile>() |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * Gets a game profile from a [UUID] |
| 40 | + * |
| 41 | + * Example: |
| 42 | + * - name: ab24f5d6-dcf1-45e4-897e-b50a7c5e7422 |
| 43 | + * |
| 44 | + * @return result of [GameProfile] |
| 45 | + */ |
| 46 | +suspend fun getProfile(uuid: UUID) = runCatching { |
| 47 | + LambdaHttp.get("https://api.minecraftservices.com/minecraft/profile/lookup/$uuid").body<GameProfile>() |
| 48 | +} |
0 commit comments