Skip to content

Commit cb0ad1b

Browse files
committed
Huge changes and improvements on codebase
1 parent 915793b commit cb0ad1b

20 files changed

+1019
-614
lines changed

src/main/java/me/despical/commandframework/CommandArguments.java

Lines changed: 76 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@
3939
* @author Despical
4040
* @since 1.0.0
4141
*/
42-
public class CommandArguments {
42+
public final class CommandArguments {
4343

44+
final me.despical.commandframework.annotations.Command command;
4445
private final CommandSender commandSender;
45-
private final Command command;
46+
private final Command bukkitCommand;
4647
private final String label, arguments[];
4748

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) {
4954
this.commandSender = commandSender;
55+
this.bukkitCommand = bukkitCommand;
5056
this.command = command;
5157
this.label = label;
5258
this.arguments = arguments;
@@ -69,11 +75,22 @@ public <T extends CommandSender> T getSender() {
6975
/**
7076
* Retrieves the base command associated with this object.
7177
*
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.
7390
*/
7491
@NotNull
75-
public Command getCommand() {
76-
return command;
92+
public Command getBukkitCommand() {
93+
return bukkitCommand;
7794
}
7895

7996
/**
@@ -101,7 +118,7 @@ public String[] getArguments() {
101118
/**
102119
* Retrieves the argument at the specified index.
103120
*
104-
* @param index the index of desired argument.
121+
* @param index the index of desired argument.
105122
* @return indexed element or null if index out of bounds
106123
*/
107124
@Nullable
@@ -113,8 +130,8 @@ public String getArgument(int index) {
113130
* Returns the indexed element from the arguments array, or the {@code defaultValue}
114131
* if and only if index is out the bounds.
115132
*
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.
118135
* @return the argument at the specified index, or the default value if the index is out of bounds.
119136
*/
120137
@NotNull
@@ -125,9 +142,9 @@ public String getArgument(int index, String defaultValue) {
125142
/**
126143
* Returns the integer value of the indexed element from the arguments array.
127144
*
128-
* @param index the index of desired argument.
145+
* @param index the index of desired argument.
129146
* @return Integer if indexed element is primitive type of int
130-
* or 0 if element is null.
147+
* or 0 if element is null.
131148
*/
132149
public int getArgumentAsInt(int index) {
133150
return Utils.getInt(this.getArgument(index));
@@ -136,9 +153,9 @@ public int getArgumentAsInt(int index) {
136153
/**
137154
* Returns the double value of the indexed element from the arguments array.
138155
*
139-
* @param index the index of desired argument.
156+
* @param index the index of desired argument.
140157
* @return Double if indexed element is primitive type of double
141-
* or 0 if element is null.
158+
* or 0 if element is null.
142159
*/
143160
public double getArgumentAsDouble(int index) {
144161
return Utils.getDouble(this.getArgument(index));
@@ -147,9 +164,9 @@ public double getArgumentAsDouble(int index) {
147164
/**
148165
* Returns the float value of the indexed element from the arguments array.
149166
*
150-
* @param index the index of desired argument.
167+
* @param index the index of desired argument.
151168
* @return Float if indexed element is primitive type of float
152-
* or 0 if element is null.
169+
* or 0 if element is null.
153170
*/
154171
public float getArgumentAsFloat(int index) {
155172
return Utils.getFloat(this.getArgument(index));
@@ -158,9 +175,9 @@ public float getArgumentAsFloat(int index) {
158175
/**
159176
* Returns the long value of the indexed element from the arguments array.
160177
*
161-
* @param index the index of desired argument.
178+
* @param index the index of desired argument.
162179
* @return Long if indexed element is primitive type of long
163-
* or 0 if element is null.
180+
* or 0 if element is null.
164181
*/
165182
public long getArgumentAsLong(int index) {
166183
return Utils.getLong(this.getArgument(index));
@@ -169,9 +186,9 @@ public long getArgumentAsLong(int index) {
169186
/**
170187
* Returns the boolean value of the indexed element from the arguments array.
171188
*
172-
* @param index the index of desired argument.
189+
* @param index the index of desired argument.
173190
* @return Boolean if indexed element is primitive type of boolean
174-
* or 0 if element is null.
191+
* or 0 if element is null.
175192
*/
176193
public boolean getArgumentAsBoolean(int index) {
177194
return "true".equalsIgnoreCase(this.getArgument(index));
@@ -191,25 +208,29 @@ public boolean isArgumentsEmpty() {
191208
/**
192209
* Sends message to sender without receiving the command sender.
193210
*
194-
* @param message the message will be sent to sender.
211+
* @param message the message will be sent to sender.
195212
*/
196213
public void sendMessage(String message) {
197214
if (message == null)
198215
return;
199-
commandSender.sendMessage(CommandFramework.instance.colorFormatter.apply(message));
216+
commandSender.sendMessage(Message.applyColorFormatter(message));
200217
}
201218

202219
/**
203220
* Sends message to sender without receiving command
204221
* sender with the given parameters.
205222
*
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.
208225
*/
209226
public void sendMessage(String message, Object... params) {
210227
if (message == null)
211228
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);
213234
}
214235

215236
/**
@@ -226,7 +247,7 @@ public boolean isSenderConsole() {
226247
* Returns {@code true} if, and only if, command sender is player.
227248
*
228249
* @return {@code true} if, and only if, command sender is player, otherwise
229-
* {@code false}.
250+
* {@code false}.
230251
*/
231252
public boolean isSenderPlayer() {
232253
return commandSender instanceof Player;
@@ -236,9 +257,9 @@ public boolean isSenderPlayer() {
236257
* Returns {@code true} if the command sender has required {@code permission} or, if
237258
* {@code permission} is empty.
238259
*
239-
* @param permission the permission to check.
260+
* @param permission the permission to check.
240261
* @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}.
242263
*/
243264
public boolean hasPermission(String permission) {
244265
return permission.isEmpty() || commandSender.hasPermission(permission);
@@ -256,14 +277,10 @@ public int getLength() {
256277
/**
257278
* Gets player object from the server with given {@code name}.
258279
*
259-
* @param name
260-
* the name of player.
261-
*
280+
* @param name the name of player.
262281
* @return player with the given name if online, otherwise
263-
* empty optional.
264-
*
282+
* empty optional.
265283
* @throws IllegalArgumentException if the {@code name} is null.
266-
*
267284
* @see Optional#empty()
268285
* @since 1.3.6
269286
*/
@@ -274,21 +291,17 @@ public Optional<Player> getPlayer(String name) {
274291
/**
275292
* Gets player object from the server with given argument.
276293
*
277-
* @param index
278-
* the index of desired argument.
279-
*
294+
* @param index the index of desired argument.
280295
* @return player with the given name if online, otherwise
281-
* empty optional.
282-
*
296+
* empty optional.
283297
* @throws IllegalArgumentException if given index is out
284-
* of bounds.
285-
*
298+
* of bounds.
286299
* @see Optional#empty()
287300
* @since 1.3.6
288301
*/
289302
public Optional<Player> getPlayer(int index) {
290-
return this.getPlayer(this.getArgument(index));
291-
}
303+
return this.getPlayer(this.getArgument(index));
304+
}
292305

293306
/**
294307
* Concatenates all arguments into a single {@code String}
@@ -308,10 +321,10 @@ public String concatenateArguments() {
308321
* @param from the starting index (inclusive) of the range.
309322
* @param to the ending index (exclusive) of the range.
310323
* @return a string containing the concatenated elements within
311-
* the specified range, separated by a space.
324+
* the specified range, separated by a space.
312325
* @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}.
315328
* @since 1.3.8
316329
*/
317330
public String concatenateRangeOf(int from, int to) {
@@ -322,9 +335,9 @@ public String concatenateRangeOf(int from, int to) {
322335
* Checks if the value obtained from the argument at the specified index is numeric,
323336
* i.e., if it contains only digit characters (0-9).
324337
*
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.
326339
* @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.
328341
*/
329342
public boolean isNumeric(int index) {
330343
return this.isNumeric(this.getArgument(index));
@@ -333,9 +346,9 @@ public boolean isNumeric(int index) {
333346
/**
334347
* Checks if the given string is numeric, i.e., if it contains only digit characters (0-9).
335348
*
336-
* @param string The input string to be checked for numeric content.
349+
* @param string The input string to be checked for numeric content.
337350
* @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.
339352
*/
340353
public boolean isNumeric(String string) {
341354
if (string == null || string.isEmpty())
@@ -348,10 +361,10 @@ public boolean isNumeric(String string) {
348361
* Checks if the value obtained from the argument at the specified index can be successfully
349362
* parsed into an integer using {@code Integer.parseInt}.
350363
*
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.
352365
* @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.
355368
*/
356369
public boolean isInteger(int index) {
357370
return this.isInteger(this.getArgument(index));
@@ -360,9 +373,9 @@ public boolean isInteger(int index) {
360373
/**
361374
* Checks if the given string can be successfully parsed into an integer using {@code Integer.parseInt}.
362375
*
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.
364377
* @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.
366379
*/
367380
public boolean isInteger(String string) {
368381
try {
@@ -377,10 +390,10 @@ public boolean isInteger(String string) {
377390
* Checks if the value obtained from the argument at the specified index can be successfully
378391
* parsed into a floating-point decimal using {@code Double.parseDouble}.
379392
*
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.
381394
* @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.
384397
*/
385398
public boolean isFloatingDecimal(int index) {
386399
return this.isFloatingDecimal(this.getArgument(index));
@@ -390,9 +403,9 @@ public boolean isFloatingDecimal(int index) {
390403
* Checks if the given string can be successfully parsed into a floating decimal using {@code Double.parseDouble}.
391404
* Supports primitive types such as {@code Integer}, {@code Float}, {@code Double}, {@code Long}, etc.
392405
*
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.
394407
* @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.
396409
*/
397410
public boolean isFloatingDecimal(String string) {
398411
try {
@@ -402,4 +415,8 @@ public boolean isFloatingDecimal(String string) {
402415
return false;
403416
}
404417
}
418+
419+
public boolean checkCooldown() {
420+
return CommandFramework.instance.getCooldownManager().hasCooldown(this);
421+
}
405422
}

0 commit comments

Comments
 (0)