diff --git a/build.gradle b/build.gradle index 3701db9..4323f4a 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,6 @@ repositories { dependencies { api 'com.google.guava:guava:21.0' - api 'org.apache.commons:commons-lang3:3.5' testImplementation 'junit:junit-dep:4.10' testImplementation 'org.hamcrest:hamcrest-library:1.2.1' testImplementation 'org.mockito:mockito-core:1.8.5' diff --git a/src/main/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionType.java b/src/main/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionType.java index ac7f3d7..110c29b 100644 --- a/src/main/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionType.java +++ b/src/main/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionType.java @@ -2,9 +2,12 @@ package com.mojang.brigadier.exceptions; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; -import org.apache.commons.lang3.text.StrSubstitutor; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ParameterizedCommandExceptionType implements CommandExceptionType { + private static Pattern PATTERN = Pattern.compile("\\$\\{(\\w+)}"); private static final Joiner JOINER = Joiner.on(", "); private final String name; @@ -24,7 +27,13 @@ public class ParameterizedCommandExceptionType implements CommandExceptionType { @Override public String getErrorMessage(CommandException exception) { - return new StrSubstitutor(exception.getData()).replace(message); + final Matcher matcher = PATTERN.matcher(message); + final StringBuffer result = new StringBuffer(); + while (matcher.find()) { + matcher.appendReplacement(result, exception.getData().get(matcher.group(1)).toString()); + } + matcher.appendTail(result); + return result.toString(); } public CommandException create(Object... values) {