1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.cmdl;
21
22
23 /***
24 * This class is thread safe.
25 */
26 public class LocalExecuter {
27
28
29
30 private Command[] commands;
31
32
33
34 public LocalExecuter(Command[] commands)
35 {
36 this.commands = commands;
37 }
38
39
40
41 public Command getCommand(String command)
42 {
43 Command cmd = Executer.getCommand(command);
44 if (cmd == null) {
45 for (int i = 0; i < commands.length; i++) {
46 if (matches(commands[i], command)) {
47 cmd = commands[i];
48 break;
49 }
50 }
51 }
52 return cmd;
53 }
54
55 public boolean matches(Command cmd, String name)
56 {
57 if (name.equals(cmd.getCommand())) {
58 return true;
59 }
60 else {
61 String[] aliases = cmd.getAliases();
62 if (aliases != null) {
63 for (int i = 0; i < aliases.length; i++) {
64 if (name.equals(aliases[i])) {
65 return true;
66 }
67 }
68 }
69 }
70 return false;
71 }
72
73 public Command[] getCommands()
74 {
75 Command[] executerCmds = Executer.getCommands();
76 Command[] array = new Command[executerCmds.length + commands.length];
77 System.arraycopy(executerCmds, 0, array, 0, executerCmds.length);
78 System.arraycopy(commands, 0, array, executerCmds.length,
79 commands.length);
80 return array;
81 }
82
83 }