mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 01:37:35 +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 $
|
// Move index past the $
|
||||||
index++;
|
index++;
|
||||||
int position = Character.getNumericValue(formatString.charAt(index));
|
int argStart = index;
|
||||||
// Move index past the position
|
while (index < formatString.length() && inRange(((int) formatString.charAt(index)) - 48, 0, 9)) {
|
||||||
index++;
|
// Move index past current digit
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
if (position == -1) {
|
// No numbers found
|
||||||
|
if (argStart == index) {
|
||||||
throw new IllegalArgumentException("Invalid replacement token");
|
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
|
// Convert position to 0 index
|
||||||
position--;
|
position--;
|
||||||
|
|
||||||
@ -125,4 +136,8 @@ public class FormattedCommandAlias extends Command {
|
|||||||
|
|
||||||
return formatString;
|
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