fix: Key command can be executed in invalid ways#132
Merged
Conversation
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.
d51c8ff to
1c7c423
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A bug/misunderstanding in how Brigadier handles the
requiresblock previously resulted in the/ws keycommand 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.