-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
568513e
commit ebb714d
Showing
5 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/ua/mei/minekord/bot/extension/RoleSyncExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ua.mei.minekord.bot.extension | ||
|
||
import dev.kord.core.entity.Member | ||
import net.fabricmc.loader.api.FabricLoader | ||
import net.luckperms.api.LuckPerms | ||
import net.luckperms.api.LuckPermsProvider | ||
import net.luckperms.api.node.types.InheritanceNode | ||
import net.minecraft.server.network.ServerPlayerEntity | ||
import ua.mei.minekord.bot.MinekordExtension | ||
import ua.mei.minekord.config.MinekordConfig | ||
import ua.mei.minekord.utils.AuthUtils | ||
|
||
class RoleSyncExtension : MinekordExtension() { | ||
override val name: String = "minekord.rolesync" | ||
|
||
override suspend fun setup() { | ||
|
||
} | ||
|
||
override suspend fun onPlayerJoin(player: ServerPlayerEntity) { | ||
if (FabricLoader.getInstance().isModLoaded("luckperms") && !MinekordConfig.LuckPerms.roles.isEmpty()) { | ||
val lp: LuckPerms = LuckPermsProvider.get() | ||
|
||
lp.userManager.loadUser(player.gameProfile.id).thenAcceptAsync { user -> | ||
val member: Member = AuthUtils.findMember(player.gameProfile.name) ?: return@thenAcceptAsync | ||
val roles: List<ULong> = member.roleIds.map { it.value } | ||
|
||
user.data().toCollection() | ||
.filterIsInstance<InheritanceNode>() | ||
.filter { groupNode -> groupNode.groupName != "default" && MinekordConfig.LuckPerms.roles[groupNode.groupName] !in roles } | ||
.forEach { user.data().remove(it) } | ||
|
||
MinekordConfig.LuckPerms.roles.forEach { entry -> | ||
if (entry.value in roles) { | ||
user.data().add(InheritanceNode.builder(entry.key).build()) | ||
} | ||
} | ||
|
||
lp.userManager.saveUser(user) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ua.mei.minekord.config.spec | ||
|
||
import com.uchuhimo.konf.ConfigSpec | ||
|
||
object LuckPermsSpec : ConfigSpec() { | ||
val roles by required<Map<String, ULong>>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters