CommandHandler.kt and Command Template Code

This commit is contained in:
2025-05-07 21:08:54 -04:00
parent 64c2a95361
commit 56fb8f5a6e
11 changed files with 213 additions and 3 deletions

10
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Environment-dependent path to Maven home directory
/mavenHomeManager.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

16
.idea/gradle.xml generated Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

8
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="ms-21" project-jdk-type="JavaSDK" />
</project>

View File

@@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" factoryName="Application" name="Minecraft Client" type="Application">
<option name="MAIN_CLASS_NAME" value="dev.architectury.transformer.TransformerRuntime"/>
<module name="Fabric-Kotlin.main"/>
<option name="PROGRAM_PARAMETERS" value=""/>
<option name="VM_PARAMETERS" value="-Dfabric.dli.config=/home/sirblob/Documents/Com@@0020Sci/Github/Organization/GMU@@0020Craft/Cobblesync/.gradle/loom-cache/launch.cfg -Dfabric.dli.env=client -Dfabric.dli.main=net.fabricmc.loader.impl.launch.knot.KnotClient &quot;-Darchitectury.main.class=/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/.main_class&quot; &quot;-Darchitectury.runtime.transformer=/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/.transforms&quot; &quot;-Darchitectury.properties=/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/.properties&quot; -Djdk.attach.allowAttachSelf=true &quot;-javaagent:/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/architectury-transformer-agent.jar&quot;"/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/"/>
<method v="2">
<option enabled="true" name="Make"/>
</method>
<envs>
</envs>
<shortenClasspath name="ARGS_FILE"/>
<classpathModifications/></configuration>
</component>

View File

@@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" factoryName="Application" name="Minecraft Server" type="Application">
<option name="MAIN_CLASS_NAME" value="dev.architectury.transformer.TransformerRuntime"/>
<module name="Fabric-Kotlin.main"/>
<option name="PROGRAM_PARAMETERS" value="nogui"/>
<option name="VM_PARAMETERS" value="-Dfabric.dli.config=/home/sirblob/Documents/Com@@0020Sci/Github/Organization/GMU@@0020Craft/Cobblesync/.gradle/loom-cache/launch.cfg -Dfabric.dli.env=server -Dfabric.dli.main=net.fabricmc.loader.impl.launch.knot.KnotServer &quot;-Darchitectury.main.class=/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/.main_class&quot; &quot;-Darchitectury.runtime.transformer=/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/.transforms&quot; &quot;-Darchitectury.properties=/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/.properties&quot; -Djdk.attach.allowAttachSelf=true &quot;-javaagent:/home/sirblob/Documents/Com Sci/Github/Organization/GMU Craft/Cobblesync/.gradle/architectury/architectury-transformer-agent.jar&quot;"/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/"/>
<method v="2">
<option enabled="true" name="Make"/>
</method>
<envs>
</envs>
<shortenClasspath name="ARGS_FILE"/>
<classpathModifications><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/com.mojang/patchy/2.2.10/da05971b07cbb379d002cf7eaec6a2048211fefc/patchy-2.2.10.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-jemalloc/3.3.3/b543467b7ff3c6920539a88ee602d34098628be5/lwjgl-jemalloc-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-tinyfd/3.3.3/82d755ca94b102e9ca77283b9e2dc46d1b15fbe5/lwjgl-tinyfd-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-stb/3.3.3/25dd6161988d7e65f71d5065c99902402ee32746/lwjgl-stb-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-openal/3.3.3/daada81ceb5fc0c291fbfdd4433cb8d9423577f2/lwjgl-openal-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/com.mojang/text2speech/1.17.9/3cad216e3a7f0c19b4b394388bc9ffc446f13b14/text2speech-1.17.9.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.jcraft/jorbis/0.0.17/8872d22b293e8f5d7d56ff92be966e6dc28ebdc6/jorbis-0.0.17.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.26.0/659feffdd12280201c8aacb8f7be94f9a883c824/commons-compress-1.26.0.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.16.0/4e3eb3d79888d76b54e28b350915b5dc3919c9de/commons-codec-1.16.0.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.16/51cf043c87253c9f58b539c9f7e44c8894223850/httpcore-4.4.16.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-opengl/3.3.3/2f6b0147078396a58979125a4c947664e98293a/lwjgl-opengl-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/com.mojang/blocklist/1.0.10/5c685c5ffa94c4cd39496c7184c1d122e515ecef/blocklist-1.0.10.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-glfw/3.3.3/efa1eb78c5ccd840e9f329717109b5e892d72f8e/lwjgl-glfw-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-freetype/3.3.3/a0db6c84a8becc8ca05f9dbfa985edc348a824c7/lwjgl-freetype-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl/3.3.3/29589b5f87ed335a6c7e7ee6a5775f81f97ecb84/lwjgl-3.3.3.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.13/e5f6cae5ca7ecaac1ec2827a9e2d65ae2869cada/httpclient-4.5.13.jar"/><entry exclude="true" path="/home/sirblob/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/73.2/61ad4ef7f9131fcf6d25c34b817f90d6da06c9e9/icu4j-73.2.jar"/></classpathModifications></configuration>
</component>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -1,2 +1,19 @@
org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.14
loom_version=1.10-SNAPSHOT
fabric_kotlin_version=1.13.2+kotlin.2.1.20
# Mod Properties
mod_version=1.0.0
maven_group=co.sirblob
archives_base_name=cobblesync
# Dependencies
fabric_version=0.115.6+1.21.1
cobblemon_version=1.6.1+1.21.1

View File

@@ -1,4 +1,4 @@
rootProject.name = "Fabric-Kotlin" //By default, this is how your built jar is called
rootProject.name = "CobbleSync" //By default, this is how your built jar is called
pluginManagement {
repositories {

View File

@@ -3,8 +3,6 @@ package co.sirblob
import net.fabricmc.api.ModInitializer
import org.slf4j.LoggerFactory
import com.cobblemon.mod.common.api.*
object CobbleSync : ModInitializer {
private val logger = LoggerFactory.getLogger("cobblesync")

View File

@@ -0,0 +1,23 @@
package co.sirblob.commands
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
/**
* Handles the registration of all commands for the mod.
*/
object CommandHandler {
/**
* Initializes and registers all commands.
* This method is typically called from your mod's main initializer.
*/
fun registerCommands() {
CommandRegistrationCallback.EVENT.register { dispatcher, registryAccess, environment ->
// Register your commands here
MyCommand.register(dispatcher)
// Example: AnotherCommand.register(dispatcher)
}
}
}

View File

@@ -0,0 +1,100 @@
package co.sirblob.commands
import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.IntegerArgumentType
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import com.mojang.brigadier.builder.RequiredArgumentBuilder
import com.mojang.brigadier.context.CommandContext
import net.minecraft.server.commands.ServerCommandSource
import net.minecraft.server.commands.CommandManager.* // Required for literal() and argument()
import net.minecraft.text.Text
// TEMPLATE CODE DOESN"T WORK BUT MEH
/**
* A template for a simple command.
*
* This command can be invoked in-game using:
* /mycommand
* /mycommand <number>
*/
object SaveParty {
private const val COMMAND_NAME = "mycommand" // The base name of the command
/**
* Registers the command and its subcommands/arguments.
*
* @param dispatcher The command dispatcher used to register commands.
*/
fun register(dispatcher: CommandDispatcher<>) {
// Create the literal argument builder for the base command
// A literal argument is a fixed string that must be typed by the user.
val commandBuilder = literal<ServerCommandSource>(COMMAND_NAME)
.executes(::runBaseCommand) // Action to perform if only /mycommand is typed
.then(
// Define an argument that follows the base command.
// In this case, we expect an integer argument named "number".
argument("number", IntegerArgumentType.integer())
.executes(::runWithNumberArgument) // Action to perform if /mycommand <number> is typed
// You can add more subcommands or arguments here
// .then(literal<ServerCommandSource>("subcommand").executes(::runSubCommand))
)
// Register the command
dispatcher.register(commandBuilder)
}
/**
* Executes when the base command is called (e.g., /mycommand).
*
* @param context The command context, providing information about the command's execution.
* @return An integer indicating command success (typically 1 for success, 0 for failure).
*/
private fun runBaseCommand(context: CommandContext<ServerCommandSource>): Int {
val source = context.source
source.sendFeedback({ Text.literal("You ran the base MyCommand!") }, false) // Send feedback to the player
// false means it won't be broadcast to other ops
// You can add more logic here, like interacting with the game world, player, etc.
// For example, to get the player who executed the command:
// val player = source.player
// player?.sendMessage(Text.literal("Hello from the command!"), false)
return Command.SINGLE_SUCCESS // Indicates the command was successful
}
/**
* Executes when the command is called with a number argument (e.g., /mycommand 123).
*
* @param context The command context, providing information about the command's execution.
* @return An integer indicating command success.
*/
private fun runWithNumberArgument(context: CommandContext<ServerCommandSource>): Int {
val source = context.source
val number = IntegerArgumentType.getInteger(context, "number") // Get the value of the "number" argument
source.sendFeedback({ Text.literal("MyCommand received number: $number") }, false)
// Add logic that uses the number argument
if (number > 100) {
source.sendFeedback({ Text.literal("That's a big number!") }, false)
} else {
source.sendFeedback({ Text.literal("That's a reasonable number.") }, false)
}
return Command.SINGLE_SUCCESS
}
/*
// Example of another subcommand function
private fun runSubCommand(context: CommandContext<ServerCommandSource>): Int {
val source = context.source
source.sendFeedback({ Text.literal("You ran the 'subcommand' of MyCommand!") }, false)
return Command.SINGLE_SUCCESS
}
*/
}