Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dansplugins/playerlore/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> doubleQuoteArgs = argumentParser.getArgumentsInsideDoubleQuotes(args);
if (doubleQuoteArgs.size() == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading