From 2ee5a01e783b0ce1166fa274e5b12e4757ca46e6 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 8 Feb 2014 15:22:45 -0500 Subject: [PATCH] [Bleeding] Fix formatting of optional arguments. By: t00thpick1 --- .../bukkit/command/FormattedCommandAlias.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/paper-api/src/main/java/org/bukkit/command/FormattedCommandAlias.java index 250f6ecfd7..7e5df7cd2b 100644 --- a/paper-api/src/main/java/org/bukkit/command/FormattedCommandAlias.java +++ b/paper-api/src/main/java/org/bukkit/command/FormattedCommandAlias.java @@ -91,26 +91,23 @@ public class FormattedCommandAlias extends Command { throw new IllegalArgumentException("Missing required argument " + (position + 1)); } - String replacement = null; + StringBuilder replacement = new StringBuilder(); if (rest && position < args.length) { - StringBuilder builder = new StringBuilder(); for (int i = position; i < args.length; i++) { if (i != position) { - builder.append(' '); + replacement.append(' '); } - builder.append(args[i]); + replacement.append(args[i]); } - replacement = builder.toString(); } else if (position < args.length) { - replacement = args[position]; + replacement.append(args[position]); } - if (replacement != null && replacement.length() > 0) { - formatString = formatString.substring(0, start) + replacement + formatString.substring(end); - // Move index past the replaced data so we don't process it again - index = start + replacement.length(); - } + formatString = formatString.substring(0, start) + replacement.toString() + formatString.substring(end); + // Move index past the replaced data so we don't process it again + index = start + replacement.length(); + // Move to the next replacement token index = formatString.indexOf("$", index); }