Skip to content

Commit 92b0753

Browse files
committed
fix: wrong player property extension
1 parent d299f71 commit 92b0753

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

common/src/main/kotlin/com/lambda/friend/FriendManager.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@
1717

1818
package com.lambda.friend
1919

20-
import com.lambda.friend.FriendRegistry.friends
20+
import com.lambda.config.Configurable
21+
import com.lambda.config.configurations.FriendConfig
22+
import com.lambda.core.Loadable
2123
import com.mojang.authlib.GameProfile
22-
import net.minecraft.server.network.ServerPlayerEntity
24+
import net.minecraft.client.network.OtherClientPlayerEntity
2325
import java.util.*
2426

25-
object FriendManager {
26-
fun add(profile: GameProfile) = friends.add(profile)
27+
object FriendManager : Configurable(FriendConfig), Loadable {
28+
override val name = "friends"
29+
val friends by setting("friends", listOf<GameProfile>(), hackDelegates = true)
2730

28-
fun remove(profile: GameProfile) = friends.remove(profile)
31+
fun add(profile: GameProfile) { if (!contains(profile)) friends.add(profile) }
32+
33+
fun remove(profile: GameProfile) { friends.remove(profile) }
2934

3035
fun get(name: String) = friends.firstOrNull { it.name == name }
3136
fun get(uuid: UUID) = friends.firstOrNull { it.id == uuid }
@@ -36,9 +41,14 @@ object FriendManager {
3641

3742
fun clear() = friends.clear()
3843

39-
val ServerPlayerEntity.isFriend: Boolean
44+
val OtherClientPlayerEntity.isFriend: Boolean
4045
get() = contains(gameProfile)
4146

42-
fun ServerPlayerEntity.befriend() = add(gameProfile)
43-
fun ServerPlayerEntity.unfriend() = remove(gameProfile)
47+
fun OtherClientPlayerEntity.befriend() = add(gameProfile)
48+
fun OtherClientPlayerEntity.unfriend() = remove(gameProfile)
49+
50+
override fun load(): String {
51+
// TODO: Because the settings are loaded after the property and the loadables, the friend list is empty at that point
52+
return "Loaded ${friends.size} friends"
53+
}
4454
}

0 commit comments

Comments
 (0)