Fix nickname regex bug

The previous implementation didn't consider tbe case when the last player in the list doesn't have a nickname, leaving an empty "always match" part which messed up the formatting
@FigyTuna
Also added editorconfig for GitHub formatting
This commit is contained in:
Norbi Peti 2019-01-02 23:30:46 +01:00
parent 720740dea3
commit aed7864a15
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 364 additions and 347 deletions

19
.editorconfig Normal file
View file

@ -0,0 +1,19 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = false
indent_style = space
indent_size = 4
[*.json]
indent_style = space
indent_size = 2
[*.java]
indent_style = tab
tab_width = 4
[{*.yml, *.yaml}]
indent_style = space
indent_size = 2

View file

@ -257,18 +257,16 @@ public class ChatProcessing {
namesb.append(")");
StringBuilder nicksb = new StringBuilder("(?i)(");
boolean addNickFormatter = false;
final int size = Bukkit.getOnlinePlayers().size();
int index = 0;
for (Player p : Bukkit.getOnlinePlayers()) {
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
if (nick != null) {
nicksb.append(nick);
if (index < size - 1)
nicksb.append("|");
nicksb.append(nick).append("|");
addNickFormatter = true; //Add it even if there's only 1 player online (it was in the if)
}
index++;
}
nicksb.deleteCharAt(nicksb.length() - 1);
nicksb.append(")");
Consumer<String> error = message -> {