Removed dependency on lang3

This commit is contained in:
Nathan Adams 2017-06-22 09:34:30 +02:00
parent f372eb3b98
commit 7ac8998e5a
2 changed files with 11 additions and 3 deletions

View file

@ -19,7 +19,6 @@ repositories {
dependencies { dependencies {
api 'com.google.guava:guava:21.0' api 'com.google.guava:guava:21.0'
api 'org.apache.commons:commons-lang3:3.5'
testImplementation 'junit:junit-dep:4.10' testImplementation 'junit:junit-dep:4.10'
testImplementation 'org.hamcrest:hamcrest-library:1.2.1' testImplementation 'org.hamcrest:hamcrest-library:1.2.1'
testImplementation 'org.mockito:mockito-core:1.8.5' testImplementation 'org.mockito:mockito-core:1.8.5'

View file

@ -2,9 +2,12 @@ package com.mojang.brigadier.exceptions;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap; 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 { public class ParameterizedCommandExceptionType implements CommandExceptionType {
private static Pattern PATTERN = Pattern.compile("\\$\\{(\\w+)}");
private static final Joiner JOINER = Joiner.on(", "); private static final Joiner JOINER = Joiner.on(", ");
private final String name; private final String name;
@ -24,7 +27,13 @@ public class ParameterizedCommandExceptionType implements CommandExceptionType {
@Override @Override
public String getErrorMessage(CommandException exception) { 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) { public CommandException create(Object... values) {