59 lines
1.9 KiB
Kotlin
59 lines
1.9 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.VoicechatServerStartedEvent
|
||
|
|
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)
|
||
|
|
}
|
||
|
|
|
||
|
|
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()
|
||
|
|
}
|
||
|
|
|
||
|
|
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
|
||
|
|
}
|
||
|
|
}
|