Skip to content

Commit d7deb71

Browse files
committed
fix: Improved permission filtering
1 parent a3a53f5 commit d7deb71

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ tasks {
3737
runVelocity {
3838
velocityVersion(libs.versions.velocity.get())
3939
downloadPlugins {
40-
url("https://cdn.modrinth.com/data/1iWA0pjH/versions/3PY3lTnr/MCKotlinVelocity-1.5.1-k2.0.21.jar")
41-
url("https://cdn.modrinth.com/data/HQyibRsN/versions/pxgKwgNJ/MiniPlaceholders-Velocity-2.2.4.jar")
40+
modrinth("mckotlin", "3PY3lTnr")
41+
modrinth("miniplaceholders", "Nsctgs29")
4242
}
4343
}
4444
shadowJar {
@@ -73,7 +73,7 @@ sourceSets {
7373

7474
kotlin {
7575
jvmToolchain {
76-
languageVersion.set(JavaLanguageVersion.of(17))
76+
languageVersion.set(JavaLanguageVersion.of(21))
7777
}
7878
}
7979

src/main/kotlin/io/github/_4drian3d/clientcatcher/ClientCatcher.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ class ClientCatcher @Inject constructor(
7777
}.exceptionally {
7878
componentLogger.error("Cannot load configuration", it)
7979
false
80-
}!!
80+
}
8181
}

src/main/kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.github._4drian3d.clientcatcher
22

33
import com.velocitypowered.api.command.CommandSource
44
import com.velocitypowered.api.proxy.ConsoleCommandSource
5+
import com.velocitypowered.api.proxy.ProxyServer
56
import io.github._4drian3d.clientcatcher.configuration.Configuration
67
import io.github._4drian3d.clientcatcher.webhook.Replacer
78
import io.github._4drian3d.jdwebhooks.Embed
@@ -21,6 +22,11 @@ val hasMiniPlaceholders by lazy {
2122
}
2223
}
2324

25+
fun ProxyServer.doWithFilteredAudience(permission: String, action: (CommandSource) -> Unit) {
26+
action.invoke(this.consoleCommandSource)
27+
allPlayers.forEach { if (it.hasPermission(permission)) action.invoke(it) }
28+
}
29+
2430
private fun String.asMiniMessage(resolver: TagResolver) = MiniMessage.miniMessage().deserialize(this, resolver)
2531

2632
fun CommandSource.sendMini(message: String, logger: ComponentLogger, resolver: TagResolver) {

src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/BrandListener.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package io.github._4drian3d.clientcatcher.listener
33
import com.velocitypowered.api.event.EventTask
44
import com.velocitypowered.api.event.player.PlayerClientBrandEvent
55
import io.github._4drian3d.clientcatcher.ClientCatcher
6+
import io.github._4drian3d.clientcatcher.doWithFilteredAudience
67
import io.github._4drian3d.clientcatcher.event.BlockedClientEvent
78
import io.github._4drian3d.clientcatcher.objects.CatcherCommandSource
89
import io.github._4drian3d.clientcatcher.sendMini
910
import io.github._4drian3d.clientcatcher.sendWebHook
1011
import io.github._4drian3d.clientcatcher.webhook.Replacer
11-
import net.kyori.adventure.permission.PermissionChecker
1212

1313
class BrandListener(private val plugin: ClientCatcher) : Listener<PlayerClientBrandEvent> {
1414
override fun executeAsync(event: PlayerClientBrandEvent): EventTask {
@@ -20,12 +20,9 @@ class BrandListener(private val plugin: ClientCatcher) : Listener<PlayerClientBr
2020

2121
sendWebHook(plugin, resolver, plugin.configuration.webHook.client)
2222

23-
plugin.proxyServer
24-
.filterAudience {
25-
it.get(PermissionChecker.POINTER).map { pointer ->
26-
pointer.test("clientcatcher.alert.client")
27-
}.orElse(false)
28-
}.sendMini(plugin.messages.alert.client, plugin.componentLogger, resolver)
23+
plugin.proxyServer.doWithFilteredAudience("clientcatcher.alert.client") {
24+
it.sendMini(plugin.messages.alert.client, plugin.componentLogger, resolver)
25+
}
2926

3027
for (client in plugin.configuration.blocked.clients) {
3128
if (event.brand.equals(client.name, ignoreCase = true)) {

src/main/kotlin/io/github/_4drian3d/clientcatcher/listener/ModListener.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package io.github._4drian3d.clientcatcher.listener
33
import com.velocitypowered.api.event.EventTask
44
import com.velocitypowered.api.event.player.PlayerModInfoEvent
55
import io.github._4drian3d.clientcatcher.ClientCatcher
6+
import io.github._4drian3d.clientcatcher.doWithFilteredAudience
67
import io.github._4drian3d.clientcatcher.event.BlockedModEvent
78
import io.github._4drian3d.clientcatcher.objects.CatcherCommandSource
89
import io.github._4drian3d.clientcatcher.sendMini
910
import io.github._4drian3d.clientcatcher.sendWebHook
1011
import io.github._4drian3d.clientcatcher.webhook.Replacer
11-
import net.kyori.adventure.permission.PermissionChecker
1212

1313
class ModListener(private val plugin: ClientCatcher) : Listener<PlayerModInfoEvent> {
1414
override fun executeAsync(event: PlayerModInfoEvent): EventTask {
@@ -20,12 +20,9 @@ class ModListener(private val plugin: ClientCatcher) : Listener<PlayerModInfoEve
2020

2121
sendWebHook(plugin, resolver, plugin.configuration.webHook.mods)
2222

23-
plugin.proxyServer
24-
.filterAudience {
25-
it.get(PermissionChecker.POINTER).map { pointer ->
26-
pointer.test("clientcatcher.alert.mods")
27-
}.orElse(false)
28-
}.sendMini(plugin.messages.alert.mods, plugin.componentLogger, resolver)
23+
plugin.proxyServer.doWithFilteredAudience("clientcatcher.alert.mods") {
24+
it.sendMini(plugin.messages.alert.mods, plugin.componentLogger, resolver)
25+
}
2926

3027
for (mod in event.modInfo.mods) for (blocked in plugin.configuration.blocked.mods) {
3128
if (blocked.name.equals(mod.id, ignoreCase = true)) {

0 commit comments

Comments
 (0)