4
4
import com .datasiqn .commandcore .argument .ArgumentReader ;
5
5
import com .datasiqn .commandcore .argument .Arguments ;
6
6
import com .datasiqn .commandcore .argument .ListArguments ;
7
- import com .datasiqn .commandcore .command .CommandExecutor ;
7
+ import com .datasiqn .commandcore .command .Command ;
8
8
import com .datasiqn .commandcore .command .TabComplete ;
9
- import com .datasiqn .commandcore .command .context . CommandContext ;
9
+ import com .datasiqn .commandcore .command .CommandContext ;
10
10
import com .datasiqn .resultapi .None ;
11
11
import com .datasiqn .resultapi .Result ;
12
12
import org .bukkit .Bukkit ;
13
13
import org .bukkit .ChatColor ;
14
14
import org .jetbrains .annotations .Contract ;
15
15
import org .jetbrains .annotations .NotNull ;
16
+ import org .jetbrains .annotations .Nullable ;
16
17
17
18
import java .util .ArrayList ;
18
19
import java .util .Collections ;
19
20
import java .util .List ;
20
21
import java .util .Set ;
21
22
import java .util .function .Consumer ;
22
- import java .util .function .Function ;
23
23
24
- class BuilderExecutor implements CommandExecutor {
24
+ class BuilderCommand implements Command {
25
+ private final String name ;
26
+ private final String [] aliases ;
27
+ private final String description ;
28
+ private final String permission ;
29
+ private final List <String > usages ;
30
+
25
31
private final Set <CommandNode <?>> nodes ;
26
32
private final Consumer <CommandContext > executor ;
27
- private final List <Function <CommandContext , Result <None , String >>> requires ;
33
+ private final List <CommandLink .Require > requires ;
34
+
35
+ public BuilderCommand (@ NotNull CommandBuilder commandBuilder , List <String > usages ) {
36
+ this .name = commandBuilder .name ;
37
+ this .aliases = commandBuilder .aliases ;
38
+ this .description = commandBuilder .description ;
39
+ this .permission = commandBuilder .permission ;
40
+ this .usages = usages ;
41
+ this .nodes = commandBuilder .children ;
42
+ this .executor = commandBuilder .executor ;
43
+ this .requires = commandBuilder .requires ;
44
+ }
45
+
46
+ @ Override
47
+ public @ NotNull String getName () {
48
+ return name ;
49
+ }
28
50
29
- BuilderExecutor (Consumer <CommandContext > executor , Set <CommandNode <?>> nodes , List <Function <CommandContext , Result <None , String >>> requires ) {
30
- this .nodes = nodes ;
31
- this .executor = executor ;
32
- this .requires = requires ;
51
+ @ Override
52
+ public @ NotNull String @ NotNull [] getAliases () {
53
+ return aliases ;
33
54
}
34
55
35
56
@ Override
@@ -43,7 +64,7 @@ class BuilderExecutor implements CommandExecutor {
43
64
if (size >= 1 ) {
44
65
if (nodes .isEmpty ()) return Result .error (Collections .singletonList ("Expected no parameters, but got parameters instead" ));
45
66
46
- CurrentNode current = findCurrentNode (reader );
67
+ BuilderCommand . CurrentNode current = findCurrentNode (reader );
47
68
Result <CommandNode <?>, List <String >> resultNode = current .node ;
48
69
if (resultNode .isError ()) {
49
70
if (current .extraInput ) {
@@ -80,7 +101,7 @@ class BuilderExecutor implements CommandExecutor {
80
101
}
81
102
82
103
@ Override
83
- public @ NotNull TabComplete getTabComplete (@ NotNull CommandContext context ) {
104
+ public @ NotNull TabComplete tabComplete (@ NotNull CommandContext context ) {
84
105
Arguments args = context .getArguments ();
85
106
86
107
if (args .size () >= 1 ) {
@@ -91,7 +112,7 @@ class BuilderExecutor implements CommandExecutor {
91
112
String matchingString = args .getString (args .size () - 1 );
92
113
93
114
if (args .size () != 1 ) {
94
- CurrentNode current = findCurrentNode (reader );
115
+ BuilderCommand . CurrentNode current = findCurrentNode (reader );
95
116
List <CommandNode <?>> nodeList = current .nodes ;
96
117
if (nodeList .size () != 0 ) {
97
118
CommandNode <?> node = nodeList .get (nodeList .size () - 1 );
@@ -106,15 +127,40 @@ class BuilderExecutor implements CommandExecutor {
106
127
}
107
128
return new TabComplete (tabcomplete , matchingString );
108
129
}
109
- return CommandExecutor .super .getTabComplete (context );
130
+ return Command .super .tabComplete (context );
131
+ }
132
+
133
+ @ Override
134
+ public @ Nullable String getPermissionString () {
135
+ return permission ;
136
+ }
137
+
138
+ @ Override
139
+ public boolean hasPermission () {
140
+ return permission != null ;
141
+ }
142
+
143
+ @ Override
144
+ public @ Nullable String getDescription () {
145
+ return description ;
146
+ }
147
+
148
+ @ Override
149
+ public boolean hasDescription () {
150
+ return description != null ;
151
+ }
152
+
153
+ @ Override
154
+ public @ NotNull List <String > getUsages () {
155
+ return usages ;
110
156
}
111
157
112
158
@ Contract ("_, _ -> new" )
113
- private @ NotNull CommandContext buildContext (@ NotNull CommandContext context , @ NotNull CurrentNode result ) {
159
+ private @ NotNull CommandContext buildContext (@ NotNull CommandContext context , @ NotNull BuilderCommand . CurrentNode result ) {
114
160
return CommandCore .createContext (context .getSource (), context .getCommand (), context .getLabel (), new ListArguments (result .args ));
115
161
}
116
162
117
- private @ NotNull Result <ApplicableNode , List <String >> checkApplicable (@ NotNull ArgumentReader reader , @ NotNull Set <CommandNode <?>> nodes ) {
163
+ private @ NotNull Result <BuilderCommand . ApplicableNode , List <String >> checkApplicable (@ NotNull ArgumentReader reader , @ NotNull Set <CommandNode <?>> nodes ) {
118
164
List <CommandNode <?>> options = new ArrayList <>();
119
165
List <String > exceptions = new ArrayList <>();
120
166
if (reader .index () != 0 ) reader .next ();
@@ -131,25 +177,25 @@ class BuilderExecutor implements CommandExecutor {
131
177
String arg ;
132
178
if (reader .atEnd ()) arg = reader .splice (beforeIndex );
133
179
else arg = reader .splice (beforeIndex , reader .index ());
134
- return Result .ok (new ApplicableNode (options .get (0 ), arg ));
180
+ return Result .ok (new BuilderCommand . ApplicableNode (options .get (0 ), arg ));
135
181
}
136
182
137
183
@ Contract ("_ -> new" )
138
- private @ NotNull BuilderExecutor .CurrentNode findCurrentNode (@ NotNull ArgumentReader reader ) {
184
+ private @ NotNull BuilderCommand .CurrentNode findCurrentNode (@ NotNull ArgumentReader reader ) {
139
185
Set <CommandNode <?>> nodeSet = nodes ;
140
186
List <String > args = new ArrayList <>();
141
187
List <CommandNode <?>> nodeList = new ArrayList <>();
142
188
CommandNode <?> node = null ;
143
189
while (!reader .atEnd ()) {
144
- if (nodeSet .isEmpty ()) return new CurrentNode (Result .error (Collections .emptyList ()), nodeList , args , true );
145
- Result <ApplicableNode , List <String >> parseResult = checkApplicable (reader , nodeSet );
190
+ if (nodeSet .isEmpty ()) return new BuilderCommand . CurrentNode (Result .error (Collections .emptyList ()), nodeList , args , true );
191
+ Result <BuilderCommand . ApplicableNode , List <String >> parseResult = checkApplicable (reader , nodeSet );
146
192
if (parseResult .isError ()) {
147
193
System .out .println ("errors: " + String .join ("," , parseResult .unwrapError ()));
148
194
System .out .println ("args is " + String .join ("," , args ));
149
195
args .add (reader .splice (reader .index ()));
150
- return new CurrentNode (Result .error (parseResult .unwrapError ()), nodeList , args , false );
196
+ return new BuilderCommand . CurrentNode (Result .error (parseResult .unwrapError ()), nodeList , args , false );
151
197
}
152
- ApplicableNode applicableNode = parseResult .unwrap ();
198
+ BuilderCommand . ApplicableNode applicableNode = parseResult .unwrap ();
153
199
node = applicableNode .node ;
154
200
nodeSet = node .getChildren ();
155
201
nodeList .add (node );
@@ -158,7 +204,7 @@ class BuilderExecutor implements CommandExecutor {
158
204
if (reader .atEnd () && reader .get () == ' ' ) args .add ("" );
159
205
}
160
206
System .out .println ("args is " + String .join ("," , args ));
161
- return new CurrentNode (Result .ok (node ), nodeList , args , false );
207
+ return new BuilderCommand . CurrentNode (Result .ok (node ), nodeList , args , false );
162
208
}
163
209
164
210
private static class ApplicableNode {
0 commit comments