Skip to content

Commit

Permalink
NPC name coloration quick-patch
Browse files Browse the repository at this point in the history
this section of code could really stand a total rewrite. Fixes issues with longer-than-16-character coloration, doesn't fix trouble with longer-than-32 if there is any (based on Discord reports)
  • Loading branch information
mcmonkey4eva committed Apr 13, 2019
1 parent aea3cd3 commit 043b9e8
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions main/src/main/java/net/citizensnpcs/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ public static String[] splitPlayerName(String coloredName) {
prefix = coloredName.substring(0, 16);
int len = 30;
name = coloredName.substring(16, 30);
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
if (coloredName.length() >= 32) {
len = 32;
name = coloredName.substring(16, 32);
} else if (coloredName.length() == 31) {
len = 31;
name = coloredName.substring(16, 31);
}
} else {
String prefixColors = ChatColor.getLastColors(prefix);
if (prefixColors.isEmpty()) {
String prefixColors = ChatColor.getLastColors(prefix);
if (prefixColors.isEmpty()) {
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
if (coloredName.length() >= 32) {
len = 32;
name = coloredName.substring(16, 32);
} else if (coloredName.length() == 31) {
len = 31;
name = coloredName.substring(16, 31);
}
} else {
prefixColors = ChatColor.RESET.toString();
}
else if (prefixColors.length() > 2) {
prefixColors = prefixColors.substring(prefixColors.length() - 2);
}
name = prefixColors + name;
}
else if (prefixColors.length() > 2) {
prefixColors = prefixColors.substring(prefixColors.length() - 2);
}
name = prefixColors + name;
suffix = coloredName.substring(len);
} else {
prefix = coloredName.substring(0, coloredName.length() - 16);
Expand All @@ -74,16 +74,14 @@ else if (prefixColors.length() > 2) {
prefix = prefix.substring(0, prefix.length() - 1);
name = ChatColor.COLOR_CHAR + name;
}
if (!NON_ALPHABET_MATCHER.matcher(name).matches()) {
String prefixColors = ChatColor.getLastColors(prefix);
if (prefixColors.isEmpty()) {
prefixColors = ChatColor.RESET.toString();
}
else if (prefixColors.length() > 2) {
prefixColors = prefixColors.substring(prefixColors.length() - 2);
}
name = prefixColors + name;
String prefixColors = ChatColor.getLastColors(prefix);
if (prefixColors.isEmpty() && !NON_ALPHABET_MATCHER.matcher(name).matches()) {
prefixColors = ChatColor.RESET.toString();
}
else if (prefixColors.length() > 2) {
prefixColors = prefixColors.substring(prefixColors.length() - 2);
}
name = prefixColors + name;
if (name.length() > 16) {
suffix = name.substring(16);
name = name.substring(0, 16);
Expand Down

0 comments on commit 043b9e8

Please sign in to comment.