From bf88b7bd653f3582115a701a6fd4068644f95b7a Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Fri, 7 Aug 2026 02:57:41 -0600 Subject: [PATCH] Send usage message from /pl add instead of throwing on empty args AddCommand passed args straight into ArgumentParser.getArgumentsInsideDoubleQuotes, which throws IllegalArgumentException when the array is empty. EditCommand and RemoveCommand already guard against an empty args array before parsing; AddCommand now does the same and sends its usage message. The characterization test that asserted the thrown exception is replaced with a regression test matching the sibling execute_rejectsMissingArgs tests. Closes #10 Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 1 + .../java/dansplugins/playerlore/commands/AddCommand.java | 5 +++++ .../dansplugins/playerlore/commands/AddCommandTest.java | 9 +++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58204a4..494e76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - `/pl edit` and `/pl remove` now treat `lineIndex` as 1-based, matching `COMMANDS.md`/`USER_GUIDE.md`, instead of silently indexing into the lore list as 0-based - `/pl edit` and `/pl remove` no longer throw an uncaught exception when given a non-numeric index or no index at all; they now send a player-facing error message +- `/pl add` no longer throws an uncaught exception when invoked with no arguments; it now sends the usage message, matching `/pl edit` and `/pl remove` - The default (no-argument) command no longer tells players to type the non-existent `/lp help`; it now correctly says `/pl help` ## [1.1] diff --git a/src/main/java/dansplugins/playerlore/commands/AddCommand.java b/src/main/java/dansplugins/playerlore/commands/AddCommand.java index 9f9664c..42f68fd 100644 --- a/src/main/java/dansplugins/playerlore/commands/AddCommand.java +++ b/src/main/java/dansplugins/playerlore/commands/AddCommand.java @@ -38,6 +38,11 @@ public boolean execute(CommandSender commandSender, String[] args) { Player player = (Player) commandSender; // get line of lore + if (args.length == 0) { + player.sendMessage(ChatColor.RED + "Usage: /pl add \"line of lore\""); + return false; + } + ArgumentParser argumentParser = new ArgumentParser(); ArrayList doubleQuoteArgs = argumentParser.getArgumentsInsideDoubleQuotes(args); if (doubleQuoteArgs.size() == 0) { diff --git a/src/test/java/dansplugins/playerlore/commands/AddCommandTest.java b/src/test/java/dansplugins/playerlore/commands/AddCommandTest.java index 4e25e70..bc6d58a 100644 --- a/src/test/java/dansplugins/playerlore/commands/AddCommandTest.java +++ b/src/test/java/dansplugins/playerlore/commands/AddCommandTest.java @@ -1,7 +1,6 @@ package dansplugins.playerlore.commands; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -66,9 +65,11 @@ public void execute_appendsLoreLineWhenItemHasExistingLore() { } @Test - public void execute_missingArgs_throwsInsteadOfSendingUsageMessage() { - // Unlike EditCommand/RemoveCommand, AddCommand has no args.length guard before parsing (see #10). - assertThrows(IllegalArgumentException.class, () -> addCommand.execute(player, new String[]{})); + public void execute_rejectsMissingArgs() { + boolean result = addCommand.execute(player, new String[]{}); + + assertFalse(result); + verify(player).sendMessage(ChatColor.RED + "Usage: /pl add \"line of lore\""); } @Test