File tree Expand file tree Collapse file tree
src/main/java/org/mangorage/mangobotcore/jda Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import org .mangorage .commonutils .misc .Arguments ;
55import org .mangorage .commonutils .misc .TaskScheduler ;
66import org .mangorage .mangobotcore .jda .command .api .CommandManager ;
7+ import org .mangorage .mangobotcore .jda .command .api .CommandResult ;
78import org .mangorage .mangobotcore .jda .command .api .ICommand ;
89import org .mangorage .mangobotcore .jda .event .CommandEvent ;
910
@@ -44,14 +45,16 @@ public void handle(Message message) {
4445 var success = false ;
4546 for (ICommand command : commands .values ()) {
4647 if (command .commands ().contains (cmd [0 ])) {
47- command .execute (message , arguments );
48+ command .execute (message , arguments ). accept ( message ) ;
4849 success = true ;
4950 break ;
5051 }
5152 }
52- if (!success )
53- CommandEvent .BUS .post (new CommandEvent (message , cmd [0 ], arguments ));
54-
53+ if (!success ) {
54+ var event = CommandEvent .BUS .fire (new CommandEvent (message , cmd [0 ], arguments ));
55+ if (event .isHandled ())
56+ event .getResult ().accept (message );
57+ }
5558 if (silent ) {
5659 TaskScheduler .getExecutor ().schedule (() -> {
5760 message .delete ().queue ();
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public final class CommandEvent extends MutableEvent {
1313 private final String cmd ;
1414 private final Arguments arguments ;
1515
16- private boolean handled = false ;
16+ private CommandResult result = null ;
1717
1818 public CommandEvent (Message message , String cmd , Arguments arguments ) {
1919 this .message = message ;
@@ -33,11 +33,15 @@ public String getCommand() {
3333 return cmd ;
3434 }
3535
36- public void setHandled (CommandResult execute ) {
37- this .handled = true ;
36+ public void setHandled (CommandResult result ) {
37+ this .result = result ;
3838 }
3939
4040 public boolean isHandled () {
41- return handled ;
41+ return result != null ;
42+ }
43+
44+ public CommandResult getResult () {
45+ return result ;
4246 }
4347}
You can’t perform that action at this time.
0 commit comments