1717
1818package 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
2123import com.mojang.authlib.GameProfile
22- import net.minecraft.server .network.ServerPlayerEntity
24+ import net.minecraft.client .network.OtherClientPlayerEntity
2325import 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