From bab6db48cca78ce9f39a24bd77a3a56a4c2364f5 Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Sun, 9 Feb 2014 19:25:27 -0500 Subject: [Bleeding] Implement escape sequence for aliases. --- .../java/org/bukkit/command/FormattedCommandAlias.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java index 7e5df7cd..bb46a4da 100644 --- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java +++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java @@ -65,6 +65,12 @@ public class FormattedCommandAlias extends Command { while (index != -1) { int start = index; + if (index > 0 && formatString.charAt(start - 1) == '\\') { + formatString = formatString.substring(0, start - 1) + formatString.substring(start); + index = formatString.indexOf("$", index); + continue; + } + boolean required = false; if (formatString.charAt(index + 1) == '$') { required = true; @@ -74,10 +80,16 @@ public class FormattedCommandAlias extends Command { // Move index past the $ index++; - int position = Character.getNumericValue(formatString.charAt(index)) - 1; + int position = Character.getNumericValue(formatString.charAt(index)); // Move index past the position index++; + if (position == -1) { + throw new IllegalArgumentException("Invalid replacement token"); + } + // Convert position to 0 index + position--; + boolean rest = false; if (index < formatString.length() && formatString.charAt(index) == '-') { rest = true; -- cgit v1.2.3