File tree Expand file tree Collapse file tree 7 files changed +125
-0
lines changed
src/com/github/neverbolt/bserver Expand file tree Collapse file tree 7 files changed +125
-0
lines changed Original file line number Diff line number Diff line change 1+ # Eclipse
2+ .classpath
3+ .project
4+ .settings /
5+ .metadata
6+
7+ # Mac
8+ .DS_Store
9+
10+ # Java
11+ /bin /
12+ * .jar
Original file line number Diff line number Diff line change 1+ /bin
Original file line number Diff line number Diff line change 1+ package com .github .neverbolt .bserver ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+
7+ import com .github .neverbolt .bserver .commands .CommandHandler ;
8+
9+ public class InputHandler {
10+ private BufferedReader clIn ;
11+ private CommandHandler commands ;
12+
13+ public InputHandler () {
14+ clIn = new BufferedReader (new InputStreamReader (System .in ));
15+ commands = new CommandHandler ();
16+ }
17+
18+ public void run () {
19+ String temp ;
20+ System .out .print ("> " );
21+ while (!(temp = readLine ()).toLowerCase ().equals ("exit" )) {
22+ execute (temp );
23+
24+ System .out .print ("> " );
25+ }
26+
27+ System .out .println ("Shutting down!" );
28+ }
29+
30+ public String readLine () {
31+ String temp = null ;
32+ try {
33+ temp = clIn .readLine ();
34+ } catch (IOException e ) {
35+ System .out .println ("There has been an error with your command" );
36+ }
37+ return temp ;
38+ }
39+
40+ private void execute (String input ) {
41+ commands .run (input );
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ package com .github .neverbolt .bserver ;
2+
3+
4+ public class Main {
5+ /**
6+ *
7+ * @param args
8+ */
9+ public static void main (String [] args ) {
10+ InputHandler ih = new InputHandler ();
11+
12+ ih .run ();
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package com .github .neverbolt .bserver .commands ;
2+
3+ public interface Command {
4+ public void run (String ... params );
5+ }
Original file line number Diff line number Diff line change 1+ package com .github .neverbolt .bserver .commands ;
2+
3+ import java .util .HashMap ;
4+
5+ public class CommandHandler {
6+ private HashMap <String , Command > commands ;
7+
8+ /**
9+ * Initialize the command list
10+ */
11+ public CommandHandler () {
12+ commands = new HashMap <String , Command >();
13+ commands .put ("select" , new Select ());
14+ }
15+
16+ public void run (String input ) {
17+ String [] parts = input .split (" " );
18+ // Check if any parameter has been passed at all
19+ if (parts .length >=1 &&!input .trim ().isEmpty ()) {
20+ // Check for if the command exists
21+ if (commands .containsKey (parts [0 ].toLowerCase ())) {
22+ // Fetch the command and execute
23+ commands .get (parts [0 ].toLowerCase ()).run (parts );
24+ } else {
25+ System .out .println (parts [0 ] + ": command not found" );
26+ }
27+ }
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ package com .github .neverbolt .bserver .commands ;
2+
3+ /**
4+ *
5+ * @author Neverbolt
6+ * @version 0.1
7+ *
8+ * Select one or more bots via flags or ID's
9+ */
10+ public class Select implements Command {
11+
12+ @ Override
13+ public void run (String ... params ) {
14+ if (params .length <2 ||params .length >3 ) {
15+ System .out .println ("usage: select [-flag | -id] selector ..." );
16+ return ;
17+ }
18+
19+ System .out .println (params .length -1 );
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments