39
39
* @author Despical
40
40
* @since 1.0.0
41
41
*/
42
- public class CommandArguments {
42
+ public final class CommandArguments {
43
43
44
+ final me .despical .commandframework .annotations .Command command ;
44
45
private final CommandSender commandSender ;
45
- private final Command command ;
46
+ private final Command bukkitCommand ;
46
47
private final String label , arguments [];
47
48
48
- public CommandArguments (CommandSender commandSender , Command command , String label , String ... arguments ) {
49
+ CommandArguments (CommandSender commandSender ,
50
+ Command bukkitCommand ,
51
+ me .despical .commandframework .annotations .Command command ,
52
+ String label ,
53
+ String ... arguments ) {
49
54
this .commandSender = commandSender ;
55
+ this .bukkitCommand = bukkitCommand ;
50
56
this .command = command ;
51
57
this .label = label ;
52
58
this .arguments = arguments ;
@@ -69,11 +75,22 @@ public <T extends CommandSender> T getSender() {
69
75
/**
70
76
* Retrieves the base command associated with this object.
71
77
*
72
- * @return The base command.
78
+ * @return the base command.
79
+ * @since 1.4.8
80
+ */
81
+ @ Nullable
82
+ public me .despical .commandframework .annotations .Command getCommand () {
83
+ return this .command ;
84
+ }
85
+
86
+ /**
87
+ * Retrieves the Bukkit command associated with this object.
88
+ *
89
+ * @return the base command as a Bukkit command.
73
90
*/
74
91
@ NotNull
75
- public Command getCommand () {
76
- return command ;
92
+ public Command getBukkitCommand () {
93
+ return bukkitCommand ;
77
94
}
78
95
79
96
/**
@@ -101,7 +118,7 @@ public String[] getArguments() {
101
118
/**
102
119
* Retrieves the argument at the specified index.
103
120
*
104
- * @param index the index of desired argument.
121
+ * @param index the index of desired argument.
105
122
* @return indexed element or null if index out of bounds
106
123
*/
107
124
@ Nullable
@@ -113,8 +130,8 @@ public String getArgument(int index) {
113
130
* Returns the indexed element from the arguments array, or the {@code defaultValue}
114
131
* if and only if index is out the bounds.
115
132
*
116
- * @param index the index of desired argument.
117
- * @param defaultValue the default value to return if the index is out of bounds.
133
+ * @param index the index of desired argument.
134
+ * @param defaultValue the default value to return if the index is out of bounds.
118
135
* @return the argument at the specified index, or the default value if the index is out of bounds.
119
136
*/
120
137
@ NotNull
@@ -125,9 +142,9 @@ public String getArgument(int index, String defaultValue) {
125
142
/**
126
143
* Returns the integer value of the indexed element from the arguments array.
127
144
*
128
- * @param index the index of desired argument.
145
+ * @param index the index of desired argument.
129
146
* @return Integer if indexed element is primitive type of int
130
- * or 0 if element is null.
147
+ * or 0 if element is null.
131
148
*/
132
149
public int getArgumentAsInt (int index ) {
133
150
return Utils .getInt (this .getArgument (index ));
@@ -136,9 +153,9 @@ public int getArgumentAsInt(int index) {
136
153
/**
137
154
* Returns the double value of the indexed element from the arguments array.
138
155
*
139
- * @param index the index of desired argument.
156
+ * @param index the index of desired argument.
140
157
* @return Double if indexed element is primitive type of double
141
- * or 0 if element is null.
158
+ * or 0 if element is null.
142
159
*/
143
160
public double getArgumentAsDouble (int index ) {
144
161
return Utils .getDouble (this .getArgument (index ));
@@ -147,9 +164,9 @@ public double getArgumentAsDouble(int index) {
147
164
/**
148
165
* Returns the float value of the indexed element from the arguments array.
149
166
*
150
- * @param index the index of desired argument.
167
+ * @param index the index of desired argument.
151
168
* @return Float if indexed element is primitive type of float
152
- * or 0 if element is null.
169
+ * or 0 if element is null.
153
170
*/
154
171
public float getArgumentAsFloat (int index ) {
155
172
return Utils .getFloat (this .getArgument (index ));
@@ -158,9 +175,9 @@ public float getArgumentAsFloat(int index) {
158
175
/**
159
176
* Returns the long value of the indexed element from the arguments array.
160
177
*
161
- * @param index the index of desired argument.
178
+ * @param index the index of desired argument.
162
179
* @return Long if indexed element is primitive type of long
163
- * or 0 if element is null.
180
+ * or 0 if element is null.
164
181
*/
165
182
public long getArgumentAsLong (int index ) {
166
183
return Utils .getLong (this .getArgument (index ));
@@ -169,9 +186,9 @@ public long getArgumentAsLong(int index) {
169
186
/**
170
187
* Returns the boolean value of the indexed element from the arguments array.
171
188
*
172
- * @param index the index of desired argument.
189
+ * @param index the index of desired argument.
173
190
* @return Boolean if indexed element is primitive type of boolean
174
- * or 0 if element is null.
191
+ * or 0 if element is null.
175
192
*/
176
193
public boolean getArgumentAsBoolean (int index ) {
177
194
return "true" .equalsIgnoreCase (this .getArgument (index ));
@@ -191,25 +208,29 @@ public boolean isArgumentsEmpty() {
191
208
/**
192
209
* Sends message to sender without receiving the command sender.
193
210
*
194
- * @param message the message will be sent to sender.
211
+ * @param message the message will be sent to sender.
195
212
*/
196
213
public void sendMessage (String message ) {
197
214
if (message == null )
198
215
return ;
199
- commandSender .sendMessage (CommandFramework . instance . colorFormatter . apply (message ));
216
+ commandSender .sendMessage (Message . applyColorFormatter (message ));
200
217
}
201
218
202
219
/**
203
220
* Sends message to sender without receiving command
204
221
* sender with the given parameters.
205
222
*
206
- * @param message the message will be sent to sender.
207
- * @param params the parameters to format the message.
223
+ * @param message the message will be sent to sender.
224
+ * @param params the parameters to format the message.
208
225
*/
209
226
public void sendMessage (String message , Object ... params ) {
210
227
if (message == null )
211
228
return ;
212
- commandSender .sendMessage (CommandFramework .instance .colorFormatter .apply (MessageFormat .format (message , params )));
229
+ commandSender .sendMessage (Message .applyColorFormatter (MessageFormat .format (message , params )));
230
+ }
231
+
232
+ public boolean sendMessage (Message message ) {
233
+ return message .sendMessage (command , this );
213
234
}
214
235
215
236
/**
@@ -226,7 +247,7 @@ public boolean isSenderConsole() {
226
247
* Returns {@code true} if, and only if, command sender is player.
227
248
*
228
249
* @return {@code true} if, and only if, command sender is player, otherwise
229
- * {@code false}.
250
+ * {@code false}.
230
251
*/
231
252
public boolean isSenderPlayer () {
232
253
return commandSender instanceof Player ;
@@ -236,9 +257,9 @@ public boolean isSenderPlayer() {
236
257
* Returns {@code true} if the command sender has required {@code permission} or, if
237
258
* {@code permission} is empty.
238
259
*
239
- * @param permission the permission to check.
260
+ * @param permission the permission to check.
240
261
* @return {@code true} if the command sender has required {@code permission} or, if
241
- * {@code permission} is empty, otherwise {@code false}.
262
+ * {@code permission} is empty, otherwise {@code false}.
242
263
*/
243
264
public boolean hasPermission (String permission ) {
244
265
return permission .isEmpty () || commandSender .hasPermission (permission );
@@ -256,14 +277,10 @@ public int getLength() {
256
277
/**
257
278
* Gets player object from the server with given {@code name}.
258
279
*
259
- * @param name
260
- * the name of player.
261
- *
280
+ * @param name the name of player.
262
281
* @return player with the given name if online, otherwise
263
- * empty optional.
264
- *
282
+ * empty optional.
265
283
* @throws IllegalArgumentException if the {@code name} is null.
266
- *
267
284
* @see Optional#empty()
268
285
* @since 1.3.6
269
286
*/
@@ -274,21 +291,17 @@ public Optional<Player> getPlayer(String name) {
274
291
/**
275
292
* Gets player object from the server with given argument.
276
293
*
277
- * @param index
278
- * the index of desired argument.
279
- *
294
+ * @param index the index of desired argument.
280
295
* @return player with the given name if online, otherwise
281
- * empty optional.
282
- *
296
+ * empty optional.
283
297
* @throws IllegalArgumentException if given index is out
284
- * of bounds.
285
- *
298
+ * of bounds.
286
299
* @see Optional#empty()
287
300
* @since 1.3.6
288
301
*/
289
302
public Optional <Player > getPlayer (int index ) {
290
- return this .getPlayer (this .getArgument (index ));
291
- }
303
+ return this .getPlayer (this .getArgument (index ));
304
+ }
292
305
293
306
/**
294
307
* Concatenates all arguments into a single {@code String}
@@ -308,10 +321,10 @@ public String concatenateArguments() {
308
321
* @param from the starting index (inclusive) of the range.
309
322
* @param to the ending index (exclusive) of the range.
310
323
* @return a string containing the concatenated elements within
311
- * the specified range, separated by a space.
324
+ * the specified range, separated by a space.
312
325
* @throws ArrayIndexOutOfBoundsException if {@code from} is negative,
313
- * {@code to} is greater than the length of the array,
314
- * or {@code from} is greater than {@code to}.
326
+ * {@code to} is greater than the length of the array,
327
+ * or {@code from} is greater than {@code to}.
315
328
* @since 1.3.8
316
329
*/
317
330
public String concatenateRangeOf (int from , int to ) {
@@ -322,9 +335,9 @@ public String concatenateRangeOf(int from, int to) {
322
335
* Checks if the value obtained from the argument at the specified index is numeric,
323
336
* i.e., if it contains only digit characters (0-9).
324
337
*
325
- * @param index The index of the argument from which the value is retrieved.
338
+ * @param index The index of the argument from which the value is retrieved.
326
339
* @return {@code true} if the value at the specified argument index is numeric, {@code false} otherwise.
327
- * Returns {@code false} for null or empty values obtained from the argument.
340
+ * Returns {@code false} for null or empty values obtained from the argument.
328
341
*/
329
342
public boolean isNumeric (int index ) {
330
343
return this .isNumeric (this .getArgument (index ));
@@ -333,9 +346,9 @@ public boolean isNumeric(int index) {
333
346
/**
334
347
* Checks if the given string is numeric, i.e., if it contains only digit characters (0-9).
335
348
*
336
- * @param string The input string to be checked for numeric content.
349
+ * @param string The input string to be checked for numeric content.
337
350
* @return {@code true} if the input string is numeric, {@code false} otherwise.
338
- * Returns {@code false} for null or empty strings.
351
+ * Returns {@code false} for null or empty strings.
339
352
*/
340
353
public boolean isNumeric (String string ) {
341
354
if (string == null || string .isEmpty ())
@@ -348,10 +361,10 @@ public boolean isNumeric(String string) {
348
361
* Checks if the value obtained from the argument at the specified index can be successfully
349
362
* parsed into an integer using {@code Integer.parseInt}.
350
363
*
351
- * @param index The index of the argument from which the value is retrieved.
364
+ * @param index The index of the argument from which the value is retrieved.
352
365
* @return {@code true} if the value at the specified argument index can be parsed into an integer,
353
- * {@code false} otherwise. Returns {@code false} for null or empty values obtained from the argument.
354
- * Also returns {@code false} for values that cannot be parsed into an integer.
366
+ * {@code false} otherwise. Returns {@code false} for null or empty values obtained from the argument.
367
+ * Also returns {@code false} for values that cannot be parsed into an integer.
355
368
*/
356
369
public boolean isInteger (int index ) {
357
370
return this .isInteger (this .getArgument (index ));
@@ -360,9 +373,9 @@ public boolean isInteger(int index) {
360
373
/**
361
374
* Checks if the given string can be successfully parsed into an integer using {@code Integer.parseInt}.
362
375
*
363
- * @param string The input string to be checked for its ability to be parsed into an integer.
376
+ * @param string The input string to be checked for its ability to be parsed into an integer.
364
377
* @return {@code true} if the string can be parsed into an integer, {@code false} otherwise.
365
- * Returns {@code false} for null strings or strings that cannot be parsed into an integer.
378
+ * Returns {@code false} for null strings or strings that cannot be parsed into an integer.
366
379
*/
367
380
public boolean isInteger (String string ) {
368
381
try {
@@ -377,10 +390,10 @@ public boolean isInteger(String string) {
377
390
* Checks if the value obtained from the argument at the specified index can be successfully
378
391
* parsed into a floating-point decimal using {@code Double.parseDouble}.
379
392
*
380
- * @param index The index of the argument from which the value is retrieved.
393
+ * @param index The index of the argument from which the value is retrieved.
381
394
* @return {@code true} if the value at the specified argument index can be parsed into a floating-point decimal,
382
- * {@code false} otherwise. Returns {@code false} for null or empty values obtained from the argument.
383
- * Also returns {@code false} for values that cannot be parsed into a floating-point decimal.
395
+ * {@code false} otherwise. Returns {@code false} for null or empty values obtained from the argument.
396
+ * Also returns {@code false} for values that cannot be parsed into a floating-point decimal.
384
397
*/
385
398
public boolean isFloatingDecimal (int index ) {
386
399
return this .isFloatingDecimal (this .getArgument (index ));
@@ -390,9 +403,9 @@ public boolean isFloatingDecimal(int index) {
390
403
* Checks if the given string can be successfully parsed into a floating decimal using {@code Double.parseDouble}.
391
404
* Supports primitive types such as {@code Integer}, {@code Float}, {@code Double}, {@code Long}, etc.
392
405
*
393
- * @param string The input string to be checked for its ability to be parsed into a decimal.
406
+ * @param string The input string to be checked for its ability to be parsed into a decimal.
394
407
* @return {@code true} if the string can be parsed into a decimal, {@code false} otherwise.
395
- * Returns {@code false} for null strings or strings that cannot be parsed into a decimal.
408
+ * Returns {@code false} for null strings or strings that cannot be parsed into a decimal.
396
409
*/
397
410
public boolean isFloatingDecimal (String string ) {
398
411
try {
@@ -402,4 +415,8 @@ public boolean isFloatingDecimal(String string) {
402
415
return false ;
403
416
}
404
417
}
418
+
419
+ public boolean checkCooldown () {
420
+ return CommandFramework .instance .getCooldownManager ().hasCooldown (this );
421
+ }
405
422
}
0 commit comments