Files
TCOWW/src/main/kotlin/fr/azur/tcoww/utils/VoiceChatPlugin.kt
azur 97b73b0c55
All checks were successful
Auto Build / Build (push) Successful in 2m40s
🦋 Debugging for the 1.2.
2025-12-06 16:40:12 +01:00

74 lines
2.4 KiB
Kotlin

package fr.azur.tcoww.utils
import de.maxhenkel.voicechat.api.Group
import de.maxhenkel.voicechat.api.VoicechatPlugin
import de.maxhenkel.voicechat.api.VoicechatServerApi
import de.maxhenkel.voicechat.api.events.EventRegistration
import de.maxhenkel.voicechat.api.events.LeaveGroupEvent
import de.maxhenkel.voicechat.api.events.VoicechatServerStartedEvent
import fr.azur.tcoww.game.Game
import fr.azur.tcoww.game.NightLightCycle
import org.bukkit.entity.Player
import java.util.UUID
import kotlin.random.Random
object VoiceChatPlugin : VoicechatPlugin {
lateinit var api: VoicechatServerApi
lateinit var werewolfGroup: Group
override fun getPluginId(): String = "tcoww"
override fun registerEvents(registration: EventRegistration) {
registration.registerEvent(VoicechatServerStartedEvent::class.java, this::onServerStarted)
registration.registerEvent(LeaveGroupEvent::class.java, this::onGroupRemove)
}
private fun onServerStarted(event: VoicechatServerStartedEvent) {
api = event.voicechat
werewolfGroup =
api
.groupBuilder()
.setPersistent(true)
.setName("werewolf")
.setPassword(Random.nextInt().toString())
.setType(Group.Type.NORMAL)
.setHidden(true)
.build()
}
private fun onGroupRemove(event: LeaveGroupEvent) {
val current = Game.current ?: return
if ((
current.timeGestion.phase == NightLightCycle.Phase.NIGHT ||
current.timeGestion.phase == NightLightCycle.Phase.CREPUSCULAR
)
) {
event.cancel()
}
}
fun addWerewolf(player: Player) {
val connection = api.getConnectionOf(player.uniqueId) ?: return
connection.group = werewolfGroup
}
fun createSoloGroup(player: Player) {
val connection = api.getConnectionOf(player.uniqueId) ?: return
val soloGroup =
api
.groupBuilder()
.setName(UUID.randomUUID().toString())
.setHidden(true)
.setPassword(Random.nextInt().toString())
.setType(Group.Type.ISOLATED)
.setPersistent(false)
.build()
connection.group = soloGroup
}
fun degroupPlayer(player: Player) {
val connection = api.getConnectionOf(player.uniqueId) ?: return
connection.group = null
}
}