Skip to content

Commit 6606d1d

Browse files
committed
Added way to register multiple commands at one.
1 parent c91df19 commit 6606d1d

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/main/java/com/github/thiagotgm/modular_commands/api/CommandRegistry.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ public int compareTo( CommandRegistry cr ) {
488488
* (parent and sub registries) with the same name (eg the command name must be unique).
489489
* <p>
490490
* If the command was already registered to another registry (that is not part of the
491-
* hierarchy of the calling registry), it is unregistered from it first.
491+
* hierarchy of the calling registry), it is unregistered from it first.<br>
492+
* If it failed to be registered to this registry, it is not unregistered from the previous
493+
* registry.
492494
* <p>
493495
* Only main commands can be registered. Subcommands will simply fail to be added.
494496
*
@@ -551,6 +553,48 @@ public boolean registerCommand( ICommand command ) throws NullPointerException {
551553

552554
}
553555

556+
/**
557+
* Attempts to register all the commands in the given collection to this registry.
558+
* <p>
559+
* After the method returns, all the commands that did not fail to be registered
560+
* will be registered to this registry.<br>
561+
* They will also be unregistered from their previous registry, if any.
562+
* <p>
563+
* Commands that fail to be registered are unchanged.
564+
*
565+
* @param commands The commands to be registered.
566+
*/
567+
public void registerAllCommands( Collection<ICommand> commands ) {
568+
569+
for ( ICommand command : commands ) { // Register each command.
570+
571+
try {
572+
registerCommand( command );
573+
} catch ( NullPointerException e ) {
574+
LOG.error( "Command collection included null.", e );
575+
}
576+
577+
}
578+
579+
}
580+
581+
/**
582+
* Attempts to register all the commands in the given registry to this registry.
583+
* <p>
584+
* After the method returns, all the commands that did not fail to be registered
585+
* will be registered to this registry.<br>
586+
* They will also be unregistered from the given registry.
587+
* <p>
588+
* Commands that fail to be registered are unchanged.
589+
*
590+
* @param commands The commands to be registered.
591+
*/
592+
public void registerAllCommands( CommandRegistry registry ) {
593+
594+
registerAllCommands( registry.getRegisteredCommands() );
595+
596+
}
597+
554598
/**
555599
* Unregisters a command from this registry.
556600
*

src/main/java/com/github/thiagotgm/modular_commands/command/annotation/AnnotationParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
* and failure handlers of a single object instance. The commands and handlers parsed will call the methods
5050
* from the instance they were parsed from whenever they are invoked.
5151
* <p>
52-
* Handlers can be registered to be used across multiple Objects by marking static methods with the
53-
* handler tags and registering them with (TODO).
52+
* Handlers can be registered to be used across multiple Objects by marking their annotated methods static
53+
* and registering them with {@link #registerAnnotatedHandlers(Class)}.
5454
*
5555
* @version 1.0
5656
* @author ThiagoTGM

0 commit comments

Comments
 (0)