Fix messages not being formatted correctly

This commit is contained in:
Luck 2016-09-24 17:22:33 +01:00
parent 462bea2a09
commit d8221f466a
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -27,8 +27,6 @@ import lombok.Getter;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import java.text.MessageFormat;
@SuppressWarnings("SpellCheckingInspection")
@AllArgsConstructor
public enum Message {
@ -367,15 +365,18 @@ public enum Message {
s = s.replace("{PREFIX}", PREFIX.getMessage()).replace("\\n", "\n");
}
try {
if (showPrefix) {
sender.sendMessage(Util.color(PREFIX + MessageFormat.format(s, objects)));
sender.sendMessage(Util.color(PREFIX + format(s, objects)));
} else {
sender.sendMessage(Util.color(MessageFormat.format(s, objects)));
}
} catch (IllegalArgumentException e) {
System.out.println("Could not format message: " + this);
e.printStackTrace();
sender.sendMessage(Util.color(format(s, objects)));
}
}
private static String format(String s, Object... objects) {
for (int i = 0, objsLength = objects.length; i < objsLength; i++) {
Object o = objects[i];
s = s.replace("{" + i + "}", o.toString());
}
return s;
}
}