Skip to content

Commit 238a918

Browse files
feat: update to surf-api-gradle-plugin 1.21.11, add GameRuleWrapper utility, and integrate into GameruleArgument
1 parent 2d01a5e commit 238a918

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
4-
version=1.21.10-2.0.6-SNAPSHOT
4+
version=1.21.11-2.0.6-SNAPSHOT

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ buildscript {
44
maven("https://repo.slne.dev/repository/maven-public/") { name = "maven-public" }
55
}
66
dependencies {
7-
classpath("dev.slne.surf:surf-api-gradle-plugin:1.21.10+")
7+
classpath("dev.slne.surf:surf-api-gradle-plugin:1.21.11+")
88
}
99
}

src/main/kotlin/dev/slne/surf/essentials/command/argument/GameruleArgument.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ import dev.jorel.commandapi.arguments.Argument
55
import dev.jorel.commandapi.arguments.ArgumentSuggestions
66
import dev.jorel.commandapi.arguments.CustomArgument
77
import dev.jorel.commandapi.arguments.StringArgument
8+
import dev.slne.surf.essentials.util.GameRuleWrapper
89
import dev.slne.surf.surfapi.core.api.messages.adventure.buildText
910
import org.bukkit.GameRule
10-
import org.bukkit.command.CommandSender
1111

1212
class GameruleArgument(nodeName: String) :
1313
CustomArgument<GameRule<*>, String>(StringArgument(nodeName), { info ->
14-
GameRule.getByName(info.input) ?: throw CustomArgumentException.fromAdventureComponent {
15-
buildText {
16-
appendPrefix()
17-
error("Die Spielregel wurde nicht gefunden.")
14+
GameRuleWrapper.getByName(info.input)
15+
?: throw CustomArgumentException.fromAdventureComponent {
16+
buildText {
17+
appendPrefix()
18+
error("Die Spielregel wurde nicht gefunden.")
19+
}
1820
}
19-
}
2021
}) {
2122
init {
2223
this.replaceSuggestions(
23-
ArgumentSuggestions.stringCollection<CommandSender> {
24-
GameRule.values().map { it.name }
24+
ArgumentSuggestions.stringCollection {
25+
GameRuleWrapper.all().map { it.key.asString() }
2526
}
2627
)
2728
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package dev.slne.surf.essentials.util
2+
3+
import io.papermc.paper.registry.RegistryAccess
4+
import io.papermc.paper.registry.RegistryKey
5+
6+
object GameRuleWrapper {
7+
private val registryAccess = RegistryAccess.registryAccess().getRegistry(RegistryKey.GAME_RULE)
8+
9+
fun all() = registryAccess.toList()
10+
fun getByName(namespacedKey: String) =
11+
registryAccess.firstOrNull { it.key.asString() == namespacedKey }
12+
}

0 commit comments

Comments
 (0)