diff options
author | t00thpick1 <t00thpick1dirko@gmail.com> | 2014-02-09 20:12:04 -0500 |
---|---|---|
committer | t00thpick1 <t00thpick1dirko@gmail.com> | 2014-02-09 20:12:04 -0500 |
commit | c9836819df930fdad0984b4bc1d9c3fbe7fae724 (patch) | |
tree | 080124be49a15346040d73fb583409308b44194a /src/main/java/org | |
parent | bab6db48cca78ce9f39a24bd77a3a56a4c2364f5 (diff) | |
download | bukkit-c9836819df930fdad0984b4bc1d9c3fbe7fae724.tar bukkit-c9836819df930fdad0984b4bc1d9c3fbe7fae724.tar.gz bukkit-c9836819df930fdad0984b4bc1d9c3fbe7fae724.tar.lz bukkit-c9836819df930fdad0984b4bc1d9c3fbe7fae724.tar.xz bukkit-c9836819df930fdad0984b4bc1d9c3fbe7fae724.zip |
[Bleeding] Support any number of arguments in aliases
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/command/FormattedCommandAlias.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java index bb46a4da..84199292 100644 --- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java +++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java @@ -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++; + } + + // No numbers found + if (argStart == index) { + throw new IllegalArgumentException("Invalid replacement token"); + } + + int position = Integer.valueOf(formatString.substring(argStart, index)); - if (position == -1) { + // 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; + } } |