Skip to content

Commit

Permalink
/blueprint, root command executor
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Nov 15, 2023
1 parent 5dc5e5b commit 89111e4
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
package net.mcbrawls.blueprint.command

import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.context.CommandContext
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.ModContainer
import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata
import net.mcbrawls.blueprint.BlueprintMod
import net.mcbrawls.blueprint.BlueprintMod.MOD_NAME
import net.minecraft.server.command.CommandManager.RegistrationEnvironment
import net.minecraft.server.command.CommandManager.literal
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Text
import net.minecraft.util.Formatting

object BlueprintCommand {
fun register(dispatcher: CommandDispatcher<ServerCommandSource>, environment: RegistrationEnvironment) {
val builder = literal("blueprint")
val builder = literal("blueprint").executes(::execute)

//

dispatcher.register(builder)
}

private fun execute(context: CommandContext<ServerCommandSource>): Int {
// retrieve version
val loader = FabricLoader.getInstance()
val container = loader.getModContainer(BlueprintMod.MOD_ID)
val optionalVersion = container
.map(ModContainer::getMetadata)
.map(ModMetadata::getVersion)
.map(Version::getFriendlyString)
val version = optionalVersion.orElseGet { "Unknown" }

// feedback version
context.source.sendFeedback({ Text.literal("[$MOD_NAME] Version $version").formatted(Formatting.AQUA) }, false)
return 1
}
}

0 comments on commit 89111e4

Please sign in to comment.