update to alpha.10

This commit is contained in:
okx-code
2018-08-23 23:32:19 +01:00
parent 703342024d
commit be5ee90036
9 changed files with 54 additions and 35 deletions
@@ -11,6 +11,8 @@ import sh.okx.rankup.ranks.Rank;
import sh.okx.rankup.ranks.requirements.Requirement;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MessageBuilder {
private String message;
@@ -24,7 +26,13 @@ public class MessageBuilder {
}
public MessageBuilder replace(Variable variable, Object value) {
this.message = variable.replace(message, String.valueOf(value));
return replace(variable.name(), value);
}
public MessageBuilder replace(String name, Object value) {
Pattern pattern = Pattern.compile("\\{" + name + "}", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(message);
this.message = matcher.replaceAll(String.valueOf(value));
return this;
}
@@ -11,20 +11,13 @@ public enum Variable {
RANK_NAME,
MONEY,
MONEY_NEEDED,
AMOUNT,
AMOUNT_NEEDED,
PERCENT_DONE,
PERCENT_LEFT;
public static Variable getVariable(String name) {
for(Variable variable : values()) {
if(variable.toString().equalsIgnoreCase(name)) {
return variable;
}
}
return null;
}
public String replace(String message, String value) {
Pattern pattern = Pattern.compile("\\{" + this + "}", Pattern.CASE_INSENSITIVE);
public String replace(String message, String value, String type) {
Pattern pattern = Pattern.compile("\\{" + type + "_" + this + "}", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(message);
return matcher.replaceAll(value);
}