Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/kotlin/com/steelextractor/SteelExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.steelextractor.extractors.VillagerTypeRegistryExtractor
import com.steelextractor.extractors.CandleCakes
import com.steelextractor.extractors.ChunkStageHashes
import com.steelextractor.extractors.CustomStatRegistryExtractor
import com.steelextractor.extractors.Commands
import com.steelextractor.extractors.GameEvents
import com.steelextractor.extractors.Weathering
import com.steelextractor.extractors.Strippables
Expand Down Expand Up @@ -216,6 +217,7 @@ object SteelExtractor : ModInitializer {

addUnlessDisabled("BLOCKS") { Blocks() }
addUnlessDisabled("BLOCK_ENTITIES") { BlockEntities() }
addUnlessDisabled("COMMANDS") { Commands() }
addUnlessDisabled("DATA_COMPONENTS") { DataComponents() }
addUnlessDisabled("ITEMS") { Items() }
addUnlessDisabled("PARTICLE_TYPES") { ParticleTypeRegistryExtractor() }
Expand Down
32 changes: 32 additions & 0 deletions src/main/kotlin/com/steelextractor/extractors/Commands.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.steelextractor.extractors

import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.mojang.brigadier.tree.LiteralCommandNode
import com.steelextractor.SteelExtractor
import net.minecraft.server.MinecraftServer

class Commands : SteelExtractor.Extractor {
override fun fileName(): String {
// This should be placed in the Steel-Docs repository.
return "commands.json"
}

override fun extract(server: MinecraftServer): JsonElement {
val commands = JsonArray()

for (node in server.commands.dispatcher.root.children) {
if (node !is LiteralCommandNode) continue
val element = JsonObject()
element.addProperty("name", "/" + node.name)
val redirect = (node.redirect as? LiteralCommandNode)?.literal
element.addProperty("class", "/" + (redirect ?: node.literal))
commands.add(element)
}

val output = JsonObject()
output.add("commands", commands)
return output
}
}