-
Notifications
You must be signed in to change notification settings - Fork 0
Add tab completion for commands and arguments #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
48ed1bf
fa1147e
2448eef
07245db
97e3fa8
27db9fe
e4dbece
6018c96
61483dd
d1119c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,15 +8,48 @@ | |||||||||||||||||||||||||||||||||||||||||||
| import dansplugins.mailboxes.services.*; | ||||||||||||||||||||||||||||||||||||||||||||
| import dansplugins.mailboxes.utils.*; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.Bukkit; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.command.Command; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.command.CommandSender; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.entity.Player; | ||||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.plugin.java.JavaPlugin; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import java.io.File; | ||||||||||||||||||||||||||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Arrays; | ||||||||||||||||||||||||||||||||||||||||||||
| import java.util.HashSet; | ||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||||||||||||||||||||||||||||
| import java.util.stream.Collectors; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| public final class Mailboxes extends JavaPlugin { | ||||||||||||||||||||||||||||||||||||||||||||
| private final String pluginVersion = "v" + getDescription().getVersion(); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Config option names for tab completion (in camelCase to match config file) | ||||||||||||||||||||||||||||||||||||||||||||
| private static final List<String> CONFIG_OPTIONS = Arrays.asList( | ||||||||||||||||||||||||||||||||||||||||||||
| "debugMode", | ||||||||||||||||||||||||||||||||||||||||||||
| "maxMessageIDNumber", | ||||||||||||||||||||||||||||||||||||||||||||
| "maxMailboxIDNumber", | ||||||||||||||||||||||||||||||||||||||||||||
| "preventSendingMessagesToSelf", | ||||||||||||||||||||||||||||||||||||||||||||
| "assignmentAlertEnabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "unreadMessagesAlertEnabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "welcomeMessageEnabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "quotesEnabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "attachmentsEnabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "maxAttachmentStackSize" | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Boolean config options (stored in lowercase for case-insensitive comparison) | ||||||||||||||||||||||||||||||||||||||||||||
| private static final Set<String> BOOLEAN_CONFIG_OPTIONS = new HashSet<>(Arrays.asList( | ||||||||||||||||||||||||||||||||||||||||||||
| "debugmode", | ||||||||||||||||||||||||||||||||||||||||||||
| "preventsendingmessagestoself", | ||||||||||||||||||||||||||||||||||||||||||||
| "assignmentalertenabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "unreadmessagesalertenabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "welcomemessageenabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "quotesenabled", | ||||||||||||||||||||||||||||||||||||||||||||
| "attachmentsenabled" | ||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| // Boolean config options (stored in lowercase for case-insensitive comparison) | |
| private static final Set<String> BOOLEAN_CONFIG_OPTIONS = new HashSet<>(Arrays.asList( | |
| "debugmode", | |
| "preventsendingmessagestoself", | |
| "assignmentalertenabled", | |
| "unreadmessagesalertenabled", | |
| "welcomemessageenabled", | |
| "quotesenabled", | |
| "attachmentsenabled" | |
| )); | |
| // Boolean config options (stored in lowercase for case-insensitive comparison). | |
| // Derived from CONFIG_OPTIONS to avoid duplicating constant names. | |
| private static final Set<String> BOOLEAN_CONFIG_OPTIONS = new HashSet<>( | |
| CONFIG_OPTIONS.stream() | |
| .filter(option -> | |
| option.endsWith("Enabled") | |
| || option.endsWith("Mode") | |
| || option.startsWith("prevent")) | |
| .map(String::toLowerCase) | |
| .collect(Collectors.toSet()) | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment noting that BOOLEAN_CONFIG_OPTIONS is derived from CONFIG_OPTIONS to maintain consistency. The constants are kept inline for now as they require manual maintenance when adding new config options (the pattern-based suggestion would incorrectly classify some options). Commit: e4dbece
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding permission checks for the main subcommands in tab completion to avoid showing commands that users don't have access to. For example, only show "config" in completions if the user has 'mailboxes.config' permission. This is consistent with how CommandInterpreter.java checks permissions before executing commands and prevents information leakage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added permission checks for all main subcommands and their completions to prevent information leakage. Commit: e4dbece
Outdated
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -attach flag suggestion is provided both at args.length == 2 (line 186) and args.length >= 3 (line 191). This means -attach will be suggested at position 2 (which is the player name position) alongside player names. The -attach flag should only be suggested after the player name is provided, not at the same position as the player name. Consider restricting -attach suggestions to args.length >= 3 only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed -attach flag to only suggest at position 3+ (after player name). Removed from position 2 suggestions. Commit: e4dbece
Outdated
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter method uses case-insensitive comparison (.toLowerCase()) but creates new strings for each comparison during streaming. For small lists this is fine, but consider caching the lowercased input outside the stream to avoid repeated toLowerCase() calls on the input string.
| return options.stream() | |
| .filter(option -> option.toLowerCase().startsWith(input.toLowerCase())) | |
| String lowerInput = input.toLowerCase(); | |
| return options.stream() | |
| .filter(option -> option.toLowerCase().startsWith(lowerInput)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cached lowercased input outside the stream to avoid repeated toLowerCase() calls. Commit: e4dbece
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config option 'version' is a valid option in ConfigService but is intentionally excluded from CONFIG_OPTIONS since it cannot be set by users. However, this should be documented with a comment explaining why 'version' is excluded, as it may not be obvious to future maintainers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment explaining why 'version' is excluded. Commit: e4dbece