From bd9d6d5caec42d2e23bd76eb0ff3b16824577e57 Mon Sep 17 00:00:00 2001 From: Apehum Date: Sun, 31 Dec 2023 02:12:10 +0800 Subject: [PATCH] feat(paper): SuperVanish show and hide events integration --- gradle/libs.versions.toml | 4 +++ server/paper/build.gradle.kts | 2 ++ .../su/plo/voice/paper/PaperVoiceServer.kt | 8 ++++++ .../integration/SuperVanishIntegration.kt | 28 +++++++++++++++++++ server/paper/src/main/resources/plugin.yml | 2 ++ 5 files changed, 44 insertions(+) create mode 100644 server/paper/src/main/kotlin/su/plo/voice/paper/integration/SuperVanishIntegration.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2c0b2069..9eac64d2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,6 +5,8 @@ ustats = "1.0.2" universalcraft = "320" bstats = "3.0.2" +supervanish = "6.2.18-3" + [libraries] lombok = { module = "org.projectlombok:lombok", version = "1.18.24" } annotations = { module = "org.jetbrains:annotations", version = "23.0.0" } @@ -30,6 +32,8 @@ kotlinx-coroutines-jdk8 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-j crowdin-lib = { module = "su.plo.crowdin:lib", version.ref = "crowdin" } +supervanish = { module = "com.github.LeonMangler:SuperVanish", version.ref = "supervanish" } + [plugins] architectury-plugin = { id = "architectury-plugin", version = "3.4-SNAPSHOT" } architectury-loom = { id = "dev.architectury.loom", version = "0.12.0-SNAPSHOT" } diff --git a/server/paper/build.gradle.kts b/server/paper/build.gradle.kts index 85672663..5bc3d2aa 100644 --- a/server/paper/build.gradle.kts +++ b/server/paper/build.gradle.kts @@ -23,6 +23,8 @@ dependencies { compileOnly(project(":server:common")) + compileOnly(libs.supervanish) + // shadow projects listOf( project(":api:common"), diff --git a/server/paper/src/main/kotlin/su/plo/voice/paper/PaperVoiceServer.kt b/server/paper/src/main/kotlin/su/plo/voice/paper/PaperVoiceServer.kt index 86fa8fb4..4af060c4 100644 --- a/server/paper/src/main/kotlin/su/plo/voice/paper/PaperVoiceServer.kt +++ b/server/paper/src/main/kotlin/su/plo/voice/paper/PaperVoiceServer.kt @@ -10,6 +10,7 @@ import su.plo.ustats.UStats import su.plo.ustats.paper.PaperUStatsPlatform import su.plo.voice.paper.connection.PaperServerChannelHandler import su.plo.voice.paper.connection.PaperServerServiceChannelHandler +import su.plo.voice.paper.integration.SuperVanishIntegration import su.plo.voice.paper.integration.VoicePlaceholder import su.plo.voice.server.BaseVoiceServer import su.plo.voice.server.player.PermissionSupplier @@ -67,6 +68,13 @@ class PaperVoiceServer( if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { VoicePlaceholder(this).register() } + + if (Bukkit.getPluginManager().getPlugin("SuperVanish") != null || + Bukkit.getPluginManager().getPlugin("PremiumVanish") != null + ) { + plugin.server.pluginManager.registerEvents(SuperVanishIntegration(this), plugin) + LOGGER.info("SuperVanish event listener attached") + } } public override fun onShutdown() { diff --git a/server/paper/src/main/kotlin/su/plo/voice/paper/integration/SuperVanishIntegration.kt b/server/paper/src/main/kotlin/su/plo/voice/paper/integration/SuperVanishIntegration.kt new file mode 100644 index 00000000..7eae62ff --- /dev/null +++ b/server/paper/src/main/kotlin/su/plo/voice/paper/integration/SuperVanishIntegration.kt @@ -0,0 +1,28 @@ +package su.plo.voice.paper.integration + +import de.myzelyam.api.vanish.PlayerHideEvent +import de.myzelyam.api.vanish.PostPlayerShowEvent +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import su.plo.voice.api.server.PlasmoVoiceServer + +class SuperVanishIntegration( + private val voiceServer: PlasmoVoiceServer +) : Listener { + + @EventHandler + fun onPlayerHide(event: PlayerHideEvent) { + val player = voiceServer.playerManager.wrap(event.player) + if (!player.hasVoiceChat()) return + + voiceServer.tcpConnectionManager.broadcastPlayerDisconnect(player) + } + + @EventHandler + fun onPlayerShow(event: PostPlayerShowEvent) { + val player = voiceServer.playerManager.wrap(event.player) + if (!player.hasVoiceChat()) return + + voiceServer.tcpConnectionManager.broadcastPlayerInfoUpdate(player) + } +} diff --git a/server/paper/src/main/resources/plugin.yml b/server/paper/src/main/resources/plugin.yml index 9795a61d..2c7fc02f 100644 --- a/server/paper/src/main/resources/plugin.yml +++ b/server/paper/src/main/resources/plugin.yml @@ -7,6 +7,8 @@ authors: [ Apehum ] softdepend: - LuckPerms - PlaceholderAPI + - SuperVanish + - PremiumVanish #depend: # - kotlin-stdlib