mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 16:57:42 +01:00
[Bleeding] Support any number of arguments in aliases
By: t00thpick1 <t00thpick1dirko@gmail.com>
This commit is contained in:
parent
6da9e19042
commit
5e5173aeb4
@ -80,13 +80,24 @@ public class FormattedCommandAlias extends Command {
|
||||
|
||||
// Move index past the $
|
||||
index++;
|
||||
int position = Character.getNumericValue(formatString.charAt(index));
|
||||
// Move index past the position
|
||||
index++;
|
||||
int argStart = index;
|
||||
while (index < formatString.length() && inRange(((int) formatString.charAt(index)) - 48, 0, 9)) {
|
||||
// Move index past current digit
|
||||
index++;
|
||||
}
|
||||
|
||||
if (position == -1) {
|
||||
// No numbers found
|
||||
if (argStart == index) {
|
||||
throw new IllegalArgumentException("Invalid replacement token");
|
||||
}
|
||||
|
||||
int position = Integer.valueOf(formatString.substring(argStart, index));
|
||||
|
||||
// Arguments are not 0 indexed
|
||||
if (position == 0) {
|
||||
throw new IllegalArgumentException("Invalid replacement token");
|
||||
}
|
||||
|
||||
// Convert position to 0 index
|
||||
position--;
|
||||
|
||||
@ -125,4 +136,8 @@ public class FormattedCommandAlias extends Command {
|
||||
|
||||
return formatString;
|
||||
}
|
||||
|
||||
private static boolean inRange(int i, int j, int k) {
|
||||
return i >= j && i <= k;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user