11package com.wolfyscript.customcrafting.core.commands
22
33import com.mojang.brigadier.CommandDispatcher
4+ import com.mojang.brigadier.context.CommandContext
45import com.wolfyscript.customcrafting.CustomCrafting
6+ import com.wolfyscript.customcrafting.CustomCraftingCommon
57import com.wolfyscript.customcrafting.util.CUSTOMCRAFTING_NAMESPACE
68import com.wolfyscript.scafall.ScafallProvider
9+ import com.wolfyscript.scafall.adventure.deser
10+ import com.wolfyscript.scafall.adventure.vanilla
711import com.wolfyscript.scafall.identifier.Key
12+ import com.wolfyscript.scafall.identifier.toScafall
813import net.minecraft.commands.CommandSourceStack
914import net.minecraft.commands.Commands
15+ import net.minecraft.commands.arguments.ResourceLocationArgument
16+ import net.minecraft.network.chat.Component
1017
1118object RecipesCommand {
1219
1320 const val ROOT_NAME = " recipes"
1421
15- fun register (customCrafting : CustomCrafting , dispatcher : CommandDispatcher <CommandSourceStack >) {
16- sequenceOf(ROOT_NAME , " cc:$ROOT_NAME " , " ${Key .CUSTOMCRAFTING_NAMESPACE } :$ROOT_NAME " ).forEach {
22+ fun register (customCrafting : CustomCraftingCommon , dispatcher : CommandDispatcher <CommandSourceStack >) {
23+ sequenceOf(ROOT_NAME , " cc:$ROOT_NAME " , " ${Key .CUSTOMCRAFTING_NAMESPACE } :$ROOT_NAME " ).forEach { alias ->
1724 dispatcher.register(
18- Commands .literal(it)
19- .then(Commands .literal(" reload" ).executes { reload(customCrafting) })
25+ Commands .literal(alias).requires { it.hasPermission(ADMIN_LVL ) }.apply {
26+ then(Commands .literal(" reload" ).executes { reload(customCrafting) })
27+ then(Commands .literal(" status" ).executes { ctx ->
28+ printStatus(ctx, customCrafting)
29+ return @executes SUCCESS_RESULT
30+ })
31+ then(
32+ Commands .literal(" disable" )
33+ .then(Commands .argument(" recipe" , ResourceLocationArgument .id()).executes { ctx ->
34+ val recipeKey = ResourceLocationArgument .getId(ctx, " recipe" ).toScafall()
35+ customCrafting.recipeManager.disableRecipe(recipeKey)
36+
37+ ctx.source.sendSuccess({ Component .literal(" Disabled Recipe $recipeKey " ) }, false )
38+ return @executes SUCCESS_RESULT
39+ }.suggests { ctx, builder ->
40+ customCrafting.recipeManager.recipesLoadedByCC
41+ .map { it.toString() }
42+ .filter { it.startsWith(builder.remaining) }
43+ .forEach { builder.suggest(it) }
44+
45+ return @suggests builder.buildFuture()
46+ })
47+ )
48+ then(
49+ Commands .literal(" enable" )
50+ .then(Commands .argument(" recipe" , ResourceLocationArgument .id()).executes { ctx ->
51+ val recipeKey = ResourceLocationArgument .getId(ctx, " recipe" ).toScafall()
52+ customCrafting.recipeManager.enableRecipe(recipeKey)
53+
54+ ctx.source.sendSuccess({ Component .literal(" Enabled Recipe $recipeKey " ) }, false )
55+ return @executes SUCCESS_RESULT
56+ }.suggests { ctx, builder ->
57+ customCrafting.recipeManager.disabledRecipes
58+ .map { it.toString() }
59+ .filter { it.startsWith(builder.remaining) }
60+ .forEach { builder.suggest(it) }
61+
62+ return @suggests builder.buildFuture()
63+ })
64+ )
65+ }
2066 )
2167 }
2268 }
@@ -28,4 +74,30 @@ object RecipesCommand {
2874 return SUCCESS_RESULT
2975 }
3076
77+ private fun printStatus (ctx : CommandContext <CommandSourceStack >, customCrafting : CustomCraftingCommon ) {
78+ val recipeManager = customCrafting.recipeManager
79+
80+ val totalRecipeCount = recipeManager.index.values().count()
81+ val ccRecipesCount = recipeManager.recipesLoadedByCC.size
82+ val thirdPartyRecipeCount = totalRecipeCount - ccRecipesCount
83+ val disabledRecipeCount = recipeManager.disabledRecipes.size
84+ val failedCount = recipeManager.invalidRecipes.size
85+ val missingDepsCount = recipeManager.awaitingDependenciesRecipes.size
86+
87+ val message = """
88+ <green>Loaded Recipes: <b>$totalRecipeCount </b>
89+ CustomCrafting: $ccRecipesCount
90+ 3rd-Parties: $thirdPartyRecipeCount
91+ </green>
92+ <red>Failed to load: <b>$failedCount </b></red>
93+ <gold>Missing Dependencies: <b>$missingDepsCount </b></gold>
94+
95+ <gray>Disabled Recipes: <b>$disabledRecipeCount </b></gray>
96+ """ .trimIndent()
97+
98+ ctx.source.sendSuccess({
99+ message.deser().vanilla()
100+ }, false )
101+ }
102+
31103}
0 commit comments