Skip to content

fix: Key command can be executed in invalid ways#132

Merged
AtriusX merged 3 commits into
mainfrom
fix/command-improper-execution
May 17, 2026
Merged

fix: Key command can be executed in invalid ways#132
AtriusX merged 3 commits into
mainfrom
fix/command-improper-execution

Conversation

@AtriusX
Copy link
Copy Markdown
Owner

@AtriusX AtriusX commented May 17, 2026

A bug/misunderstanding in how Brigadier handles the requires block previously resulted in the /ws key command being executable in the console without providing a target. This would result in a stack trace being sent to the console, which isn't ideal.

This PR fixes the problem by properly accounting for this change in logic. It also includes a few small enhancements.

AtriusX added 3 commits May 17, 2026 15:01
Brigadier's ArgumentBuilder.requires() overwrites the existing predicate
instead of chaining them. This caused subcommand requirements (e.g.,
'sender is Player') to be lost when BaseCommand applied the permission
check, allowing console to reach executes blocks that expected a Player.

Fix by capturing the existing requirement before applying the permission
check and composing both predicates with &&.
Add senderTypeName() extension function to CommandUtils that maps
CommandSender types to localized, human-readable names. Supports
ConsoleCommandSender, BlockCommandSender, RemoteConsoleCommandSender,
Player, and unknown sender types.

Add corresponding locale keys for English and Chinese translations.
Extract executeWithPlayer() helper in KeyCommand to eliminate duplicated
player-check-and-error logic. Replace 'as Player' hard casts with safe
'as? Player' casts that return a localized error message when the sender
is not a player.

Also fix unsafe 'holder as Player' cast in Item.kt addItemNaturally()
with a safe cast that returns early if the holder is not a Player.
@AtriusX AtriusX force-pushed the fix/command-improper-execution branch from d51c8ff to 1c7c423 Compare May 17, 2026 19:48
@AtriusX AtriusX merged commit 56e928d into main May 17, 2026
5 checks passed
@AtriusX AtriusX deleted the fix/command-improper-execution branch May 17, 2026 22:40
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