Skip to content

Commit e63dc50

Browse files
committed
refactor(core-common): migrated from plain brigadier to cloud command framework
- Deleted the following files and their associated utility methods under `core-common`: - `BrigadierArguments.kt`: Removed command argument-related extensions (e.g., `string`, `integer`, `double`) to streamline and declutter core utilities. - `BrigadierCommand.kt`: Removed redundant Brigadier command-building extensions (e.g., `command`, `literal`, `executeWith`). - `BrigadierParameters.kt`: Removed parameter parsing extensions (e.g., `stringParam`, `intParam`, `booleanParam`) due to limited usage and redundancies. - `CommandHelpers.kt`: Removed an extensive collection of internal command helpers related to permission handling and scoped list querying. - Cleanup aligns with the shift toward a more minimalistic and modular command framework. - Updated references across the project to replace or eliminate dependencies on these utilities.
1 parent 24cf522 commit e63dc50

30 files changed

Lines changed: 4014 additions & 4494 deletions

‎.config/detekt.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ style:
654654
maxJumpCount: 1
655655
MagicNumber:
656656
active: true
657-
excludes: ['**/test/**', '**/*.kts', '**/dev/gradienttim/gradeway/config/**']
657+
excludes: ['**/test/**', '**/*.kts', '**/dev/gradienttim/gradeway/config/**', '**/dev/gradienttim/gradeway/commands/**']
658658
ignoreNumbers:
659659
- '-1'
660660
- '0'

‎core-common/build.gradle.kts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ plugins {
88

99
repositories {
1010
mavenCentral()
11-
maven("https://libraries.minecraft.net")
1211
}
1312

1413
dependencies {
1514
api(project(":core-api"))
1615

17-
implementation(libs.mojang.brigadier)
1816
implementation(libs.apache.commons.compress)
1917
implementation(libs.apache.commons.configuration2)
2018

@@ -26,6 +24,7 @@ dependencies {
2624
api(libs.koin.core)
2725
api(libs.bundles.exposed)
2826
implementation(libs.bundles.exposed.migration)
27+
api(libs.bundles.cloud)
2928
api(libs.bundles.ktoml)
3029
api(libs.bundles.kyori)
3130
api(libs.bundles.arrow)

‎core-common/src/main/kotlin/dev/gradienttim/gradeway/command/BrigadierArguments.kt‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎core-common/src/main/kotlin/dev/gradienttim/gradeway/command/BrigadierCommand.kt‎

Lines changed: 0 additions & 75 deletions
This file was deleted.

‎core-common/src/main/kotlin/dev/gradienttim/gradeway/command/BrigadierParameters.kt‎

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
MIT License
3+
Copyright (c) 2026 GradientTim
4+
*/
5+
package dev.gradienttim.gradeway.commands
6+
7+
import dev.gradienttim.gradeway.BuildInfo
8+
import dev.gradienttim.gradeway.CommonGradeway
9+
import dev.gradienttim.gradeway.commands.gradeway.*
10+
import dev.gradienttim.gradeway.extensions.formatUTC
11+
import net.kyori.adventure.text.Component
12+
import org.incendo.cloud.CommandManager
13+
import org.incendo.cloud.kotlin.extension.buildAndRegister
14+
import org.incendo.cloud.minecraft.extras.AudienceProvider
15+
import java.time.Instant
16+
17+
fun <C : Any> createGradewayCommand(
18+
literal: String,
19+
aliases: Array<String>,
20+
gradeway: CommonGradeway,
21+
commandManager: CommandManager<C>,
22+
audienceProvider: AudienceProvider<C>
23+
) {
24+
// MinecraftHelp is currently binary-incompatible with Paper builds on Adventure 5.x
25+
// (cloud-minecraft-extras 2.0.0-beta.17 was compiled against adventure-api 4.15.0) and
26+
// throws a NoSuchMethodError from its pagination/header rendering. Re-enable once cloud
27+
// publishes a release built against Adventure 5.x.
28+
// val help = MinecraftHelp.create("/$literal help", commandManager, audienceProvider)
29+
30+
commandManager.buildAndRegister(literal, aliases = aliases) {
31+
registerRoleCommand(gradeway, audienceProvider)
32+
registerGroupCommand(gradeway, audienceProvider)
33+
registerPlayerCommand(gradeway, audienceProvider)
34+
registerBackupCommand(gradeway, audienceProvider)
35+
registerMigrationCommand(literal, gradeway, audienceProvider)
36+
registerPermissionCommand(gradeway, audienceProvider)
37+
registerConfirmationCommand(gradeway, audienceProvider)
38+
39+
registerCopy("reload") {
40+
permission("gradeway.reload")
41+
42+
handler { context ->
43+
val audience = audienceProvider.apply(context.sender())
44+
45+
gradeway.reload()
46+
.onLeft { throwable ->
47+
audience.sendMessage(
48+
Component.translatable(
49+
"gradeway.command.reload.failed",
50+
Component.text(throwable.message ?: "Unknown")
51+
)
52+
)
53+
}
54+
.onRight {
55+
audience.sendMessage(Component.translatable("gradeway.command.reload.success"))
56+
}
57+
}
58+
}
59+
60+
// See the MinecraftHelp comment above - re-enable once cloud publishes a release
61+
// built against Adventure 5.x.
62+
// registerCopy("help") {
63+
// optional("query", StringParser.greedyStringParser())
64+
//
65+
// handler { context ->
66+
// help.queryCommands(context.getOrDefault("query", ""), context.sender())
67+
// }
68+
// }
69+
70+
handler { context ->
71+
val audience = audienceProvider.apply(context.sender())
72+
73+
var commitHash = BuildInfo.GIT_COMMIT_HASH
74+
if (BuildInfo.GIT_IS_DIRTY) {
75+
commitHash += "-dirty"
76+
}
77+
78+
val buildTimestamp = Instant
79+
.parse(BuildInfo.BUILD_TIMESTAMP)
80+
.formatUTC()
81+
82+
audience.sendMessage(
83+
Component.translatable(
84+
"gradeway.command.about.info",
85+
Component.text(BuildInfo.VERSION),
86+
Component.text(commitHash),
87+
Component.text(buildTimestamp)
88+
)
89+
)
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)