1616
1717package clientapi .command .handler ;
1818
19+ import clientapi .ClientAPI ;
1920import clientapi .command .Cmd ;
2021import clientapi .command .Command ;
2122import clientapi .command .exception .CommandException ;
2223import clientapi .command .exception .UnknownCommandException ;
2324import clientapi .command .exception .handler .ExceptionHandler ;
2425import clientapi .command .executor .CommandExecutor ;
2526import clientapi .command .executor .argument .ArgumentParser ;
27+ import clientapi .event .defaults .game .core .KeyEvent ;
2628import clientapi .event .defaults .internal .CommandExecutionEvent ;
2729import clientapi .manage .Manager ;
30+ import clientapi .util .interfaces .Helper ;
2831import me .zero .alpine .listener .EventHandler ;
2932import me .zero .alpine .listener .Listener ;
33+ import net .minecraft .client .gui .GuiChat ;
3034
3135import java .lang .reflect .Type ;
3236import java .util .ArrayList ;
4246 * @author Brady
4347 * @since 6/1/2017 3:03 PM
4448 */
45- public final class CommandHandler {
49+ public final class CommandHandler implements Helper {
4650
4751 /**
4852 * Handlers to process command exceptions
@@ -74,10 +78,27 @@ public final class CommandHandler {
7478 */
7579 private String prefix = "." ;
7680
81+ /**
82+ * Whether or not typing the prefix char should open the in-game chat gui
83+ */
84+ private boolean openChat = false ;
85+
7786 public CommandHandler (Manager <Command > commandManager ) {
7887 this .commandManager = commandManager ;
88+ ClientAPI .EVENT_BUS .subscribe (this );
7989 }
8090
91+ @ EventHandler
92+ private final Listener <KeyEvent > keyEventListener = new Listener <>(event -> {
93+ // Check if opening chat with the prefix is supported
94+ if (!openChat || prefix == null )
95+ return ;
96+
97+ // Ensure the prefix is a single character
98+ if (prefix .length () == 1 && prefix .charAt (0 ) == event .getCharacter ())
99+ mc .displayGuiScreen (new GuiChat (prefix ));
100+ });
101+
81102 @ EventHandler
82103 private final Listener <CommandExecutionEvent > commandExecutionListener = new Listener <>(event -> {
83104 try {
@@ -87,7 +108,7 @@ public CommandHandler(Manager<Command> commandManager) {
87108 }
88109 throw new UnknownCommandException ();
89110 } catch (CommandException e ) {
90- List <ExceptionHandler > handlers = findHandlers (e );
111+ List <ExceptionHandler > handlers = getExceptionHandlers (e );
91112 if (handlers .isEmpty ()) {
92113 e .printStackTrace ();
93114 return ;
@@ -103,7 +124,7 @@ public CommandHandler(Manager<Command> commandManager) {
103124 * @param exception The command exception
104125 * @return The list of handlers, empty if none
105126 */
106- private List <ExceptionHandler > findHandlers (CommandException exception ) {
127+ private List <ExceptionHandler > getExceptionHandlers (CommandException exception ) {
107128 return handlers .stream ().filter (handler -> handler .isTarget (exception .getClass ())).collect (Collectors .toList ());
108129 }
109130
@@ -180,4 +201,20 @@ public final void setPrefix(String prefix) {
180201 public final String getPrefix () {
181202 return this .prefix ;
182203 }
204+
205+ /**
206+ * Sets whether or not typing the prefix char should open the in-game chat gui
207+ *
208+ * @param openChat The new state
209+ */
210+ public final void setPrefixOpenChat (boolean openChat ) {
211+ this .openChat = openChat ;
212+ }
213+
214+ /**
215+ * @return Whether or not typing the prefix char should open the in-game chat gui
216+ */
217+ public final boolean doesPrefixOpenChat () {
218+ return this .openChat ;
219+ }
183220}
0 commit comments