Skip to content

Commit

Permalink
feat: use actiovation's listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Mar 25, 2023
1 parent bb8a824 commit bba8db0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
43 changes: 18 additions & 25 deletions common/src/main/kotlin/su/plo/voice/groups/ActivationListener.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package su.plo.voice.groups

import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.api.event.EventPriority
import su.plo.voice.api.event.EventSubscribe
import su.plo.voice.api.server.PlasmoBaseVoiceServer
import su.plo.voice.api.server.audio.capture.SelfActivationInfo
import su.plo.voice.api.server.audio.capture.ServerActivation
import su.plo.voice.api.server.audio.source.ServerDirectSource
import su.plo.voice.api.server.event.audio.capture.ServerActivationUnregisterEvent
import su.plo.voice.api.server.event.audio.source.PlayerSpeakEndEvent
import su.plo.voice.api.server.event.audio.source.PlayerSpeakEvent
import su.plo.voice.api.server.event.audio.source.ServerSourcePacketEvent
import su.plo.voice.api.server.player.VoicePlayer
import su.plo.voice.proto.packets.tcp.clientbound.SourceAudioEndPacket
Expand All @@ -21,37 +17,34 @@ import su.plo.voice.proto.packets.udp.serverbound.PlayerAudioPacket
class ActivationListener(
voiceServer: PlasmoBaseVoiceServer,
private val groupManager: GroupsManager,
private val activation: ServerActivation
activation: ServerActivation
) {

private val selfActivationInfo = SelfActivationInfo(voiceServer.udpConnectionManager)

@EventSubscribe(priority = EventPriority.HIGHEST)
fun onPlayerSpeak(event: PlayerSpeakEvent) {
if (activation.id != event.packet.activationId) return

val player = event.player
val packet = event.packet
init {
activation.onPlayerActivation(this::onActivation)
activation.onPlayerActivationEnd(this::onActivationEnd)
}

if (!activation.checkPermissions(player)) return
private val selfActivationInfo = SelfActivationInfo(voiceServer.udpConnectionManager)

private fun onActivation(player: VoicePlayer, packet: PlayerAudioPacket): ServerActivation.Result {
groupManager.sourceByPlayer[player.instance.uuid]?.let {
sendAudioPacket(player, it, packet)
if (sendAudioPacket(player, it, packet)) {
return ServerActivation.Result.HANDLED
}
}
}

@EventSubscribe(priority = EventPriority.HIGHEST)
fun onPlayerSpeakEnd(event: PlayerSpeakEndEvent) {
if (activation.id != event.packet.activationId) return

val player = event.player
val packet = event.packet

if (!activation.checkPermissions(player)) return
return ServerActivation.Result.IGNORED
}

fun onActivationEnd(player: VoicePlayer, packet: PlayerAudioEndPacket): ServerActivation.Result {
groupManager.sourceByPlayer[player.instance.uuid]?.let {
sendAudioEndPacket(it, packet)
if (sendAudioEndPacket(it, packet)) {
return ServerActivation.Result.HANDLED
}
}

return ServerActivation.Result.IGNORED
}

@EventSubscribe(priority = EventPriority.HIGHEST)
Expand Down
2 changes: 2 additions & 0 deletions jar/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ val platforms = setOf(
project(":server")
)

platforms.forEach { evaluationDependsOn(":${it.name}") }

sourceSets {
main {
java {
Expand Down

0 comments on commit bba8db0

Please sign in to comment.