From ed811d2661baa0e3d5f8571084b754f71e5c0346 Mon Sep 17 00:00:00 2001 From: Adrian Date: Sun, 9 Jul 2023 10:13:10 -0500 Subject: [PATCH] feat: Don't send empty alert messages --- build.gradle.kts | 5 +++-- gradle.properties | 2 +- .../kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt | 7 +++++++ .../_4drian3d/clientcatcher/listener/BrandListener.kt | 4 ++-- .../github/_4drian3d/clientcatcher/listener/ModListener.kt | 4 ++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 10ce541..dcbbac2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -47,8 +47,9 @@ tasks { } } compileKotlin { - kotlinOptions { - languageVersion = "1.8" + compilerOptions { + apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9) + languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9) } } } diff --git a/gradle.properties b/gradle.properties index 505c15c..e227360 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = io.github._4drian3d -version = 3.1.0 +version = 3.1.1-SNAPSHOT description = A simple Velocity plugin to catch the client version \ No newline at end of file diff --git a/src/main/kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt b/src/main/kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt index 9d5b619..c20bbf1 100644 --- a/src/main/kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt +++ b/src/main/kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt @@ -1,8 +1,15 @@ package io.github._4drian3d.clientcatcher +import net.kyori.adventure.audience.Audience import net.kyori.adventure.text.minimessage.MiniMessage import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver fun String.asMiniMessage() = MiniMessage.miniMessage().deserialize(this) fun String.asMiniMessage(vararg resolvers: TagResolver) = MiniMessage.miniMessage().deserialize(this, *resolvers) fun String.asMiniMessage(resolver: TagResolver) = MiniMessage.miniMessage().deserialize(this, resolver) + +fun Audience.sendMini(message: String, resolver: TagResolver) { + if (message.isNotBlank()) { + this.sendMessage(message.asMiniMessage(resolver)) + } +} diff --git a/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/BrandListener.kt b/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/BrandListener.kt index ad92535..9d686c8 100644 --- a/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/BrandListener.kt +++ b/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/BrandListener.kt @@ -4,9 +4,9 @@ import com.velocitypowered.api.event.Continuation import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.player.PlayerClientBrandEvent import io.github._4drian3d.clientcatcher.ClientCatcher -import io.github._4drian3d.clientcatcher.asMiniMessage import io.github._4drian3d.clientcatcher.event.BlockedClientEvent import io.github._4drian3d.clientcatcher.objects.CatcherCommandSource +import io.github._4drian3d.clientcatcher.sendMini import net.kyori.adventure.permission.PermissionChecker import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver @@ -24,7 +24,7 @@ class BrandListener(private val plugin: ClientCatcher) { it.get(PermissionChecker.POINTER).map { pointer -> pointer.test("clientcatcher.alert.client") }.orElse(false) - }.sendMessage(plugin.messages.alert.client.asMiniMessage(resolver)) + }.sendMini(plugin.messages.alert.client, resolver) for (client in plugin.configuration.blocked.clients) { if (event.brand.equals(client.name, ignoreCase = true)) { diff --git a/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/ModListener.kt b/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/ModListener.kt index b979b76..229e895 100644 --- a/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/ModListener.kt +++ b/src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/ModListener.kt @@ -4,9 +4,9 @@ import com.velocitypowered.api.event.Continuation import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.player.PlayerModInfoEvent import io.github._4drian3d.clientcatcher.ClientCatcher -import io.github._4drian3d.clientcatcher.asMiniMessage import io.github._4drian3d.clientcatcher.event.BlockedModEvent import io.github._4drian3d.clientcatcher.objects.CatcherCommandSource +import io.github._4drian3d.clientcatcher.sendMini import net.kyori.adventure.permission.PermissionChecker import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver @@ -28,7 +28,7 @@ class ModListener(private val plugin: ClientCatcher) { it.get(PermissionChecker.POINTER).map { pointer -> pointer.test("clientcatcher.alert.mods") }.orElse(false) - }.sendMessage(plugin.messages.alert.mods.asMiniMessage(resolver)) + }.sendMini(plugin.messages.alert.mods, resolver) for (mod in event.modInfo.mods) for (blocked in plugin.configuration.blocked.mods) { if (blocked.name.equals(mod.id, ignoreCase = true)) {