Fix /roll command silently doing nothing when called without arguments#314
Fix /roll command silently doing nothing when called without arguments#314dmccoystephenson merged 4 commits intomainfrom
Conversation
…rn true on success Agent-Logs-Url: https://github.com/Dans-Plugins/Medieval-Roleplay-Engine/sessions/a18471e3-ba4b-4758-b249-ceebd2267aaa Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the /roll (and /dice) command handling so it no longer silently does nothing when called without arguments, improving user feedback and default behavior in the MedievalRoleplayEngine command layer.
Changes:
- Default
/roll(and/dice) to a d20 when no max argument is provided. - Add numeric validation and explicit
NumberFormatExceptionhandling with player-facing errors. - Add
descriptionandusageentries forrollanddiceinplugin.yml.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/main/java/dansplugins/rpsystem/commands/roll/RollCommand.java |
Adds default die size, validates max argument, and improves error handling/return values for /roll & /dice. |
src/main/resources/plugin.yml |
Adds command metadata (description, usage) for /roll and /dice. |
| Player player = (Player) sender; | ||
|
|
||
| if (!(player.hasPermission("rp.roll") || player.hasPermission("rp.dice") || player.hasPermission("rp.default"))) { | ||
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Sorry! In order to use this command, you need one of the following permissions: 'rp.roll', 'rp.dice'"); |
There was a problem hiding this comment.
The permission error message lists only 'rp.roll' and 'rp.dice', but this method also allows 'rp.default'. Please update the message to include 'rp.default' (or remove that permission from the check) so the feedback matches the actual access logic.
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Sorry! In order to use this command, you need one of the following permissions: 'rp.roll', 'rp.dice'"); | |
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Sorry! In order to use this command, you need one of the following permissions: 'rp.roll', 'rp.dice', 'rp.default'"); |
|
|
||
| if (!(player.hasPermission("rp.roll") || player.hasPermission("rp.dice") || player.hasPermission("rp.default"))) { | ||
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Sorry! In order to use this command, you need one of the following permissions: 'rp.roll', 'rp.dice'"); | ||
| return false; |
There was a problem hiding this comment.
With usage now defined in plugin.yml, returning false here will cause Bukkit to also print the usage message after your custom error text, resulting in duplicate/extra output. Consider returning true after sending the permission-denied message (since the command was handled), and reserve false only for cases where you actually want Bukkit's usage line to be printed.
| return false; | |
| return true; |
| if (max < 1) { | ||
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Please provide a positive number to roll."); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
With usage now defined in plugin.yml, returning false here will make Bukkit print the usage line in addition to this custom message. If you want to show only your own validation message, return true after sending it (or remove the custom message and rely on Bukkit usage instead).
| return false; | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "'" + args[0] + "' is not a valid number. Usage: /roll [max]"); |
There was a problem hiding this comment.
The error message hard-codes /roll [max], but this handler is also used for /dice (see CommandService). This will show the wrong usage when the player runs /dice .... Also, since plugin.yml now defines usage, returning false will cause Bukkit to print usage as well, duplicating the usage info you embed here. Consider either (a) not embedding the usage in the message and returning false, or (b) passing the command label into this method so you can format the correct usage and return true.
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "'" + args[0] + "' is not a valid number. Usage: /roll [max]"); | |
| player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "'" + args[0] + "' is not a valid number."); |
|
@copilot You are a coding agent tasked with resolving all open comments and review threads Instructions1. Discover all comments
2. For each comment, do the following:
3. Types of issues to handle:
4. Do NOT:
After making changes
Context
|
…andled cases Agent-Logs-Url: https://github.com/Dans-Plugins/Medieval-Roleplay-Engine/sessions/fd5e1444-ccf9-4a0e-baec-666c47cf5636 Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Addressed all four review threads in commit
|
|
@copilot fix failing CI check:
|
Agent-Logs-Url: https://github.com/Dans-Plugins/Medieval-Roleplay-Engine/sessions/39a4b3ee-48d6-46cd-b182-9dbf1379caa9 Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Fixed in commit Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
/rollcommand: add default d20 roll, improve error handling, returntrueon successdescriptionandusagetoroll/dicecommands inplugin.ymlrp.defaultin permission error messagetrue(notfalse) after sending custom error messages so Bukkit doesn't double-print the usage line/roll [max]from the invalid-number error (works correctly for both/rolland/dice)org.jetbrains:annotations:23.0.0(provided) topom.xml