Skip to content

Commit

Permalink
slightly optimize width calculation & partially avoid #347
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Dec 4, 2021
1 parent acdd994 commit c222061
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,17 @@ public String formatNameAndUpdateLeader(TabPlayer player, TabPlayer viewer) {
}

public String formatName(String prefixAndName, String suffix) {
if (suffix.length() == 0) return prefixAndName;
int playerNameWidth = getTextWidth(IChatBaseComponent.fromColoredText(prefixAndName + suffix));
StringBuilder newFormat = new StringBuilder(prefixAndName);
newFormat.append(EnumChatFormat.COLOR_CHAR);
newFormat.append("r");
StringBuilder newFormat = new StringBuilder(prefixAndName).append(EnumChatFormat.RESET.getFormat());
try {
newFormat.append(buildSpaces(maxWidth + 12 - playerNameWidth));
} catch (IllegalArgumentException e) {
//will investigate later
newFormat.append(buildSpaces(12));
TAB.getInstance().getErrorManager().printError("Could not build space consisting of " + (maxWidth + 12 - playerNameWidth) + " pixels", e);
}
newFormat.append(EnumChatFormat.getLastColors(prefixAndName));
newFormat.append(suffix);
return newFormat.toString();
return newFormat.append(EnumChatFormat.getLastColors(prefixAndName)).append(suffix).toString();
}

/**
Expand Down

0 comments on commit c222061

Please sign in to comment.