Files
TCOWW/src/main/kotlin/fr/azur/tcoww/utils/VoiceChatPlugin.kt

74 lines
2.4 KiB
Kotlin
Raw Normal View History

2025-11-30 17:22:48 +01:00
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
2025-12-06 16:40:12 +01:00
import de.maxhenkel.voicechat.api.events.LeaveGroupEvent
2025-11-30 17:22:48 +01:00
import de.maxhenkel.voicechat.api.events.VoicechatServerStartedEvent
2025-12-06 16:40:12 +01:00
import fr.azur.tcoww.game.Game
import fr.azur.tcoww.game.NightLightCycle
2025-11-30 17:22:48 +01:00
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)
2025-12-06 16:40:12 +01:00
registration.registerEvent(LeaveGroupEvent::class.java, this::onGroupRemove)
2025-11-30 17:22:48 +01:00
}
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()
}
2025-12-06 16:40:12 +01:00
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()
}
}
2025-11-30 17:22:48 +01:00
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
}
}