Skip to content

Commit 68024f5

Browse files
committed
impl(common): implement first commands
1 parent e5ddd2c commit 68024f5

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

common/src/main/kotlin/com/wolfyscript/customcrafting/core/commands/CCCommands.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import com.wolfyscript.customcrafting.CustomCraftingCommon
55
import net.minecraft.commands.CommandSourceStack
66

77
const val SUCCESS_RESULT = 1
8+
const val OWNER_LVL = 4
9+
const val ADMIN_LVL = 3
10+
const val GAME_MASTER_LVL = 2
11+
const val MODERATOR_LVL = 1
12+
const val ALL_LVL = 0
813

914
class CCCommands(val customCrafting: CustomCraftingCommon) {
1015

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,68 @@
11
package com.wolfyscript.customcrafting.core.commands
22

33
import com.mojang.brigadier.CommandDispatcher
4+
import com.mojang.brigadier.context.CommandContext
45
import com.wolfyscript.customcrafting.CustomCrafting
6+
import com.wolfyscript.customcrafting.CustomCraftingCommon
57
import com.wolfyscript.customcrafting.util.CUSTOMCRAFTING_NAMESPACE
68
import com.wolfyscript.scafall.ScafallProvider
9+
import com.wolfyscript.scafall.adventure.deser
10+
import com.wolfyscript.scafall.adventure.vanilla
711
import com.wolfyscript.scafall.identifier.Key
12+
import com.wolfyscript.scafall.identifier.toScafall
813
import net.minecraft.commands.CommandSourceStack
914
import net.minecraft.commands.Commands
15+
import net.minecraft.commands.arguments.ResourceLocationArgument
16+
import net.minecraft.network.chat.Component
1017

1118
object 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
}

common/src/main/kotlin/com/wolfyscript/customcrafting/recipes/RecipeIndex.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class RecipeIndex {
4141
if (recipeRef != null) {
4242
val recipe = recipeRef.value
4343
recipes.remove(recipe)
44-
byType.remove(recipeRef.key, recipeRef)
44+
byType.remove(recipeRef.type, recipeRef)
4545
byKey.remove(key)
4646
}
4747
}

0 commit comments

Comments
 (0)