Skip to content

Commit 8cecc3b

Browse files
committed
Added profile methods
1 parent 5777845 commit 8cecc3b

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

common/src/main/kotlin/com/lambda/module/modules/combat/FakePlayer.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ import com.lambda.event.listener.SafeListener.Companion.listen
2424
import com.lambda.event.listener.SafeListener.Companion.listenConcurrently
2525
import com.lambda.module.Module
2626
import com.lambda.module.tag.ModuleTag
27-
import com.lambda.network.LambdaHttp
27+
import com.lambda.network.mojang.getProfile
2828
import com.lambda.threading.onShutdown
2929
import com.lambda.util.Timer
3030
import com.lambda.util.player.spawnFakePlayer
3131
import com.mojang.authlib.GameProfile
32-
import io.ktor.client.call.*
33-
import io.ktor.client.request.*
3432
import net.minecraft.client.network.OtherClientPlayerEntity
3533
import net.minecraft.client.network.PlayerListEntry
36-
import net.minecraft.entity.Entity
3734
import java.util.*
3835
import kotlin.time.Duration.Companion.seconds
3936

@@ -75,9 +72,8 @@ object FakePlayer : Module(
7572
onDisable { fakePlayer?.discard(); fakePlayer = null }
7673
}
7774

78-
suspend fun SafeContext.fetchProfile(key: String): GameProfile {
79-
val requestedProfile = LambdaHttp.get("https://api.mojang.com/users/profiles/minecraft/$key")
80-
.body<GameProfile>()
75+
suspend fun SafeContext.fetchProfile(user: String): GameProfile {
76+
val requestedProfile = getProfile(user).getOrElse { return nilProfile }
8177

8278
// Fetch the skin properties from mojang
8379
val properties = mc.sessionService.fetchProfile(requestedProfile.id, true)?.profile?.properties
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)