Skip to content

Commit

Permalink
small optimization with StringBuilder and String.format
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Apr 10, 2021
1 parent 1c4713e commit fcf5636
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ private List<SortingType> compile(String string){
* @return unique up to 16 character long sequence that sorts the player
*/
public String getTeamName(TabPlayer p) {
String teamName = "";
StringBuilder sb = new StringBuilder();
for (SortingType type : sorting) {
teamName += type.getChars(p);
sb.append(type.getChars(p));
}
if (teamName.length() > 12) {
teamName = teamName.substring(0, 12);
if (sb.length() > 12) {
sb.setLength(12);
}
teamName += p.getName();
if (teamName.length() > 15) {
teamName = teamName.substring(0, 15);
sb.append(p.getName());
if (sb.length() > 15) {
sb.setLength(15);
}
return checkTeamName(p, teamName, 65);
return checkTeamName(p, sb.toString(), 65);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public String getChars(TabPlayer p) {
String chars = sortedGroups.get(group.toLowerCase());
if (chars == null) {
chars = "9";
if (!group.equals("<null>")) TAB.getInstance().getErrorManager().oneTimeConsoleError("Group \"&e" + group + "&c\" is not defined in sorting list! This will result in players in that group not being sorted correctly. To fix this, add group \"&e" + group + "&c\" into &egroup-sorting-priority-list in config.yml&c. Your current list: " + sortedGroups.keySet());
if (!group.equals("<null>")) {
TAB.getInstance().getErrorManager().oneTimeConsoleError(String.format("Group \"&e%s&c\" is not defined in sorting list! This will result in players in that group not being sorted correctly. To fix this, add group \"&e%s&c\" into &egroup-sorting-priority-list in config.yml&c. Your current list: %s", group, group, sortedGroups.keySet()));
}
p.setTeamNameNote("&cPlayer's primary group is not in sorting list");
} else {
p.setTeamNameNote("Primary group is #" + Integer.parseInt(chars) + " in sorting list");
p.setTeamNameNote(String.format("Primary group is #%s in sorting list", Integer.parseInt(chars)));
}
return chars;
}
Expand Down

0 comments on commit fcf5636

Please sign in to comment.