Skip to content

Conversation

@lucgei231
Copy link
Owner

@lucgei231 lucgei231 commented Aug 27, 2025

Summary by Sourcery

Enhance command alias mod with robust config management, multi-command and dynamic variable support, and Quilt compatibility

New Features:

  • Add /setcmdvariable command to store per-player custom variables for use in aliases

Enhancements:

  • Initialize config in config/CommandMaker/aliases.json with example template and preserve comment header when loading/saving
  • Refactor /addcommand to include reload, add, and del subcommands with cleanup of previous alias registrations
  • Support alias definitions as JSON arrays or primitives and execute multiple commands per alias
  • Extend variable substitution to include player name, coordinates, argument placeholders, and custom per-player variables

Build:

  • Bump mod version to 1.0.2
  • Add Quilt Loader and Quilted Fabric API dependencies and include quilt.mod.json in jar packaging

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 27, 2025

Reviewer's Guide

This PR restructures alias management by enhancing config handling, refactoring alias execution to support JSON arrays and variable substitution (including per-player custom variables), improving command registration logic, and updating the build for Quilt compatibility with a version bump.

Sequence diagram for executing an alias with variable substitution and multiple commands

sequenceDiagram
actor Player
participant ServerCommandSource
participant ExampleMod
participant CommandDispatcher
Player->>ServerCommandSource: Issues alias command
ServerCommandSource->>ExampleMod: executeAlias(alias, ctx)
ExampleMod->>ExampleMod: Parse alias value (JSON string/array)
loop For each command in alias
    ExampleMod->>ExampleMod: substituteVariablesWithArgs(cmd, ctx, args)
    ExampleMod->>CommandDispatcher: parse(substitutedCmd, source)
    CommandDispatcher->>CommandDispatcher: execute(parsed)
end
ExampleMod->>ServerCommandSource: Return result
Loading

Sequence diagram for setting a per-player custom variable via /setcmdvariable

sequenceDiagram
actor Player
participant ServerCommandSource
participant ExampleMod
Player->>ServerCommandSource: /setcmdvariable <variable> <value>
ServerCommandSource->>ExampleMod: registerSetCmdVariable()
ExampleMod->>ExampleMod: Store variable in playerVariables[uuid]
ExampleMod->>ServerCommandSource: Send feedback to player
Loading

Class diagram for updated ExampleMod alias and variable management

classDiagram
class ExampleMod {
  +MOD_ID : String
  +LOGGER : Logger
  -CONFIG_PATH : Path
  -aliases : Map<String, String>
  -playerVariables : Map<UUID, Map<String, String>>
  +onInitialize()
  -ensureConfigExists()
  -registerAddCommand(CommandDispatcher)
  -registerSetCmdVariable(CommandDispatcher)
  -registerAliases(CommandDispatcher)
  -registerAlias(CommandDispatcher, String, String)
  -executeAlias(String, CommandContext)
  -substituteVariablesWithArgs(String, CommandContext, String[])
  -substituteVariables(String, CommandContext)
  -loadAliases()
  -saveAliases()
}
ExampleMod --> "*" Map
ExampleMod --> "*" Path
ExampleMod --> "*" UUID
Loading

File-Level Changes

Change Details Files
Enhanced configuration management and path handling
  • Moved CONFIG_PATH under "config/CommandMaker/aliases.json"
  • Added ensureConfigExists() to initialize folders and default JSON with comments
  • Updated loadAliases() to skip comment lines and rebuild JSON
  • Expanded saveAliases() to prepend header comments before writing JSON
ExampleMod.java
Refactored alias execution to support multiple commands and argument substitution
  • Extracted execution logic into executeAlias() for JSON parsing and command looping
  • Unified registerAlias() to call executeAlias() for both no-arg and with-arg cases
  • Introduced substituteVariablesWithArgs() to handle built-in, custom, and positional variables
ExampleMod.java
Added per-player custom variables via new command
  • Declared playerVariables map to store UUID→(var→value)
  • Implemented registerSetCmdVariable() for /setcmdvariable with player validation
  • Integrated custom variables into command substitution
ExampleMod.java
Improved /addcommand subcommands and alias re-registration
  • Reload now removes existing alias nodes before re-registering
  • Reformatted add and del branches for clearer command builder structure
  • Del subcommand provides feedback when alias is not found
ExampleMod.java
Updated build.gradle and resources for Quilt compatibility and version bump
  • Added Quilt Loader and Quilted Fabric API dependencies
  • Configured processResources to include quilt.mod.json
  • Bumped mod_version to 1.0.2 and updated VERSION file
build.gradle
gradle.properties
VERSION
src/main/resources/quilt.mod.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@lucgei231 lucgei231 merged commit 980ad49 into lucgei231:fabric-1.21.7 Aug 27, 2025
0 of 2 checks passed
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider extracting and reusing the duplicate logic in substituteVariablesWithArgs and substituteVariables into a single utility method to avoid code duplication.
  • The playerVariables map is never cleared—consider removing entries on player logout to prevent unbounded memory growth over time.
  • The header comments for the config file are duplicated in ensureConfigExists() and saveAliases(); extract them into a single constant to keep them in sync.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting and reusing the duplicate logic in substituteVariablesWithArgs and substituteVariables into a single utility method to avoid code duplication.
- The playerVariables map is never cleared—consider removing entries on player logout to prevent unbounded memory growth over time.
- The header comments for the config file are duplicated in ensureConfigExists() and saveAliases(); extract them into a single constant to keep them in sync.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lucgei231 lucgei231 deleted the fabric-1.21.7 branch August 27, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant