88import org .bukkit .command .CommandSender ;
99import org .bukkit .entity .Player ;
1010import xyz .damt .command .CommandHandler ;
11+ import xyz .damt .command .complete .TabComplete ;
1112import xyz .damt .command .exception .CommandProviderNullException ;
1213import xyz .damt .command .executor .CommandExecutor ;
1314import xyz .damt .command .help .HelpCommandService ;
@@ -30,6 +31,7 @@ public class Command {
3031
3132 private final CommandExecutor commandExecutor ;
3233 private final HelpCommandService helpCommandService ;
34+ private final TabComplete tabComplete ;
3335
3436 private final List <Command > subCommands = new ArrayList <>();
3537 private final List <CommandParameter > commandParameters = new ArrayList <>();
@@ -47,7 +49,7 @@ public class Command {
4749 * @param async if the command should be ran async or not
4850 */
4951
50- public Command (Object object , String name , String [] aliases , Method method , String description , String usage , HelpCommandService helpCommandService , boolean async ) {
52+ public Command (Object object , String name , String [] aliases , Method method , String description , String usage , HelpCommandService helpCommandService , TabComplete tabComplete , boolean async ) {
5153 this .object = object ;
5254
5355 this .name = name ;
@@ -58,6 +60,7 @@ public Command(Object object, String name, String[] aliases, Method method, Stri
5860 this .usage = usage ;
5961
6062 this .helpCommandService = helpCommandService ;
63+ this .tabComplete = tabComplete ;
6164 this .commandExecutor = new CommandExecutor (this );
6265 }
6366
@@ -103,12 +106,15 @@ public void execute(CommandSender commandSender, String[] args) {
103106 try {
104107 objects .add (commandParameter .getCommandProvider ().provide (args [commandParameters .indexOf (commandParameter )]));
105108 } catch (CommandProviderNullException e ) {
106- if (e .getMessage () == null ) {
107- commandSender .sendMessage (ChatColor .RED + "The argument '" + commandParameter .getName () + "' is null!" );
109+ if (!commandParameter .isOptional ()) {
110+ if (e .getMessage () == null ) {
111+ commandSender .sendMessage (ChatColor .RED + "The argument '" + commandParameter .getName () + "' is null!" );
112+ return ;
113+ }
114+
115+ commandSender .sendMessage (e .getMessage ());
108116 return ;
109117 }
110- commandSender .sendMessage (e .getMessage ());
111- return ;
112118 }
113119 }
114120
0 commit comments