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