44import org .broken .arrow .library .command .command .CommandProperty ;
55import org .broken .arrow .library .command .commandhandler .CommandExecutor ;
66import org .broken .arrow .library .command .commandhandler .CommandRegistering ;
7+ import org .broken .arrow .library .command .commandhandler .MainCommandHandler ;
8+ import org .broken .arrow .library .command .builers .CommandBuilder ;
9+ import org .broken .arrow .library .command .subcommand .CommandDisplayConfig ;
710import org .broken .arrow .library .logging .Logging ;
811import org .bukkit .Bukkit ;
912import org .bukkit .command .Command ;
1013import org .bukkit .command .CommandException ;
1114import org .bukkit .command .CommandMap ;
15+ import org .bukkit .plugin .Plugin ;
1216
17+ import javax .annotation .Nonnull ;
18+ import javax .annotation .Nullable ;
1319import java .lang .reflect .Field ;
1420import java .util .ArrayList ;
1521import java .util .Arrays ;
1622import java .util .Collections ;
1723import java .util .Comparator ;
1824import java .util .List ;
25+ import java .util .Locale ;
26+ import java .util .Map ;
1927import java .util .Objects ;
2028import java .util .Set ;
29+ import java .util .concurrent .ConcurrentHashMap ;
2130
2231/**
2332 * A utility class for registering and managing registered commands.The commandRegister provides
2433 * methods for registering subcommands, setting command label messages and permissions,
2534 * retrieving sub-commands, and registering the main command label.
2635 */
2736public class CommandRegister implements CommandRegistering {
28- private Logging log = new Logging (CommandRegister .class );
37+ private final Logging log = new Logging (CommandRegister .class );
2938
3039 private final List <CommandProperty > commands = Collections .synchronizedList (new ArrayList <>());
40+ private final Map <String , MainCommandHandler > commandsNew = new ConcurrentHashMap <>();
41+
3142 private String commandLabelMessage ;
3243 private String commandLabelMessageNoPerms ;
3344 private String commandLabelPermission ;
@@ -43,7 +54,6 @@ public CommandRegistering registerSubCommand(final CommandProperty subCommand) {
4354 if (addCommands (subCommand , commandLabels )) {
4455 return this ;
4556 }
46-
4757 commands .removeIf (oldCommandBuilder -> oldCommandBuilder .equals (subCommand ));
4858 commands .removeIf (oldCommandBuilder -> oldCommandBuilder .getCommandLabels ().equals (subCommand .getCommandLabels ()));
4959 commands .add (subCommand );
@@ -58,9 +68,49 @@ public CommandRegistering registerSubCommands(final CommandProperty... subComman
5868 for (CommandProperty registerSubCommand : subCommands ) {
5969 this .registerSubCommand (registerSubCommand );
6070 }
71+
72+ registerCommand (null , "test" )
73+ .setAliases ("before" )
74+ .registerSubCommandGroup (subCommand ->{
75+ subCommand .registerSubCommand (null );
76+ })
77+ .display (displayConfig -> {
78+ displayConfig .setCommandLabelMessage ("" );
79+ displayConfig .setSuffixMessage ("-----<suffix>-----" );
80+ displayConfig .setPrefixMessage ("-----<prefix>-----" );
81+ })
82+ .setAliases ("testings" );
83+
84+ registerCommand (null , "testing" )
85+ .setMainDescription ("something" )
86+ .setMainCommand (null )
87+ .setMainDescription ("a command" );
6188 return this ;
6289 }
6390
91+ /**
92+ * Registers a new command entry point for this plugin.
93+ *
94+ * <p>This is the primary entry method for creating and configuring a command.
95+ * It initializes the internal command handler and returns a {@link CommandBuilder}
96+ * used to define aliases, subcommands, execution behavior, and display settings.</p>
97+ *
98+ * <p>The plugin name is used as a fallback namespace for command registration.</p>
99+ *
100+ * @param plugin the owning plugin instance (used for namespace and registration context)
101+ * @param mainCommand the root command label (e.g. "plugin" in "/plugin menu")
102+ * @return a {@link CommandBuilder} used to configure the command structure
103+ */
104+ public CommandBuilder registerCommand (final Plugin plugin , final String mainCommand ) {
105+ final CommandDisplayConfig commandDisplayConfig = new CommandDisplayConfig ();
106+ final MainCommandHandler mainCommandHandler = new MainCommandHandler (commandDisplayConfig );
107+ final CommandBuilder commandBuilder = new CommandBuilder (mainCommandHandler );
108+
109+ commandsNew .put (mainCommand , mainCommandHandler );
110+ this .registerMainCommand (plugin .getName ().toLowerCase (Locale .ROOT ), mainCommand , commandBuilder );
111+ return commandBuilder ;
112+ }
113+
64114 /**
65115 * Returns the message to display as the command label.
66116 *
@@ -260,6 +310,7 @@ public List<CommandProperty> getCommands() {
260310 * @param label The sub-label of the command builder to retrieve.
261311 * @return The command builder with the specified sub-label, or null if not found.
262312 */
313+ @ Nullable
263314 @ Override
264315 public CommandProperty getCommandBuilder (String label ) {
265316 return getCommandBuilder (label , false );
@@ -272,8 +323,11 @@ public CommandProperty getCommandBuilder(String label) {
272323 * @param startsWith Specifies whether the sub-label should match the beginning of the command builder's sub-label.
273324 * @return The command builder with the specified sub-label, or null if not found.
274325 */
326+ @ Nullable
275327 @ Override
276328 public CommandProperty getCommandBuilder (String label , boolean startsWith ) {
329+ if (startsWith )
330+ System .out .println ("getCommandBuilder " + label );
277331 for (final CommandProperty command : commands ) {
278332 if (startsWith && (label .isEmpty () || command .firstLabelMatch (label , true ) != null ))
279333 return command ;
@@ -310,6 +364,7 @@ public CommandRegistering registerMainCommand(String fallbackPrefix, String main
310364 return this .registerMainCommand (fallbackPrefix , mainCommand , "" , "" , aliases );
311365 }
312366
367+
313368 /**
314369 * Registers the main command with the specified fallback prefix, command, description, usage message, and aliases.
315370 * If the main command has already been registered, this method does nothing.
@@ -322,16 +377,14 @@ public CommandRegistering registerMainCommand(String fallbackPrefix, String main
322377 * @return The CommandRegistering instance.
323378 */
324379 @ Override
325- public CommandRegistering registerMainCommand (String fallbackPrefix , String mainCommand , String description , String usageMessage , String ... aliases ) {
380+ public CommandRegistering registerMainCommand (@ Nonnull final String fallbackPrefix , @ Nonnull final String mainCommand , @ Nonnull final String description , @ Nonnull final String usageMessage , @ Nonnull final String ... aliases ) {
326381 final String [] main = mainCommand .split ("\\ |" );
327382 if (registeredMainCommand ) return this ;
328383 if (main .length > 1 )
329384 for (final String command : main )
330385 this .register (fallbackPrefix , new CommandExecutor (this , command , description , usageMessage , Arrays .asList (aliases )));
331386 else
332387 this .register (fallbackPrefix , new CommandExecutor (this , mainCommand , description , usageMessage , Arrays .asList (aliases )));
333- registeredMainCommand = true ;
334-
335388 return this ;
336389 }
337390
@@ -350,6 +403,14 @@ public boolean addCommands(CommandProperty subCommand, Set<String> commandLabels
350403 }
351404 }
352405
406+ private void registerMainCommand (@ Nonnull final String fallbackPrefix , @ Nonnull final String mainCommand , @ Nonnull final CommandBuilder commandBuilder ) {
407+ final String description = commandBuilder .getMainDescription ();
408+ final String usageMessage = commandBuilder .getMainUsageMessage ();
409+ final String [] aliases = commandBuilder .getAliases ();
410+ this .registerMainCommand (fallbackPrefix , mainCommand , description , usageMessage , aliases );
411+ }
412+
413+
353414 /**
354415 * Registers the specified command with the provided fallback prefix.
355416 * This method uses reflection to access the commandMap and register the command.
0 commit comments