Skip to content

Commit

Permalink
feat: Don't send empty alert messages
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Jul 9, 2023
1 parent 5edad3a commit ed811d2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down

0 comments on commit ed811d2

Please sign in to comment.