From c648d6a541b7c1bacd33ed1599f461fc63356e35 Mon Sep 17 00:00:00 2001 From: Ivan Pekov Date: Thu, 6 Aug 2020 21:45:27 +0300 Subject: [PATCH] Fix trailing/leading space after placeholder once and for all (#427) --- .../placeholderapi/replacer/CharsReplacer.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java b/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java index 00a8b96..98ff409 100644 --- a/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java +++ b/src/main/java/me/clip/placeholderapi/replacer/CharsReplacer.java @@ -100,11 +100,13 @@ public final class CharsReplacer implements Replacer { boolean identified = false; boolean oopsitsbad = true; + boolean hadSpace = false; while (++i < chars.length) { final char p = chars[i]; if (p == ' ' && !identified) { + hadSpace = true; break; } if (p == closure.tail) { @@ -137,7 +139,9 @@ public final class CharsReplacer implements Replacer { builder.append('_').append(parametersString); } - builder.append(' '); + if (hadSpace) { + builder.append(' '); + } continue; } @@ -168,15 +172,7 @@ public final class CharsReplacer implements Replacer { builder.append(ChatColor.translateAlternateColorCodes('&', replacement)); } - if (builder.length() == 0) { - return ""; - } - char c = builder.charAt(builder.length() - 1); - if (c == ' ') { - return builder.substring(0, builder.length() - 1); - } else { - return builder.toString(); - } + return builder.toString(); } }