aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-27 11:53:57 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-27 11:53:57 -0500
commitb09f774d422263ce15b97d6d0804beddf856176d (patch)
treee542258481d7496b15679f3c329ef9e087c7d8fc /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java
parent22cb02adbeb24b7ec98f843bcaba99cebe3e4f03 (diff)
downloadnotenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.gz
notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.bz2
notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.zip
feat: improve formating :)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java170
1 files changed, 89 insertions, 81 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java
index ba12235d..9c93b9c5 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java
@@ -14,86 +14,94 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DamageCommas {
- private static final WeakHashMap<EntityLivingBase, ChatComponentText> replacementMap = new WeakHashMap<>();
-
- private static final EnumChatFormatting[] coloursHypixel = {EnumChatFormatting.WHITE, EnumChatFormatting.YELLOW, EnumChatFormatting.GOLD, EnumChatFormatting.RED, EnumChatFormatting.RED, EnumChatFormatting.WHITE};
-
- private static final char STAR = '\u2727';
- private static final Pattern PATTERN_CRIT = Pattern.compile("\u00a7f" + STAR + "((?:\u00a7.\\d)+)\u00a7." + STAR + "(.*)");
- private static final Pattern PATTERN_NO_CRIT = Pattern.compile("\u00a77(\\d+)(.*)");
-
- public static IChatComponent replaceName(EntityLivingBase entity) {
- if (!entity.hasCustomName()) return entity.getDisplayName();
-
- IChatComponent name = entity.getDisplayName();
- if (NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle == 0) return name;
-
- if (replacementMap.containsKey(entity)) {
- ChatComponentText component = replacementMap.get(entity);
- if (component == null) return name;
- return component;
- }
-
- String formatted = name.getFormattedText();
-
- boolean crit = false;
- String numbers;
- String prefix;
- String suffix;
-
- Matcher matcherCrit = PATTERN_CRIT.matcher(formatted);
- if (matcherCrit.matches()) {
- crit = true;
- numbers = StringUtils.cleanColour(matcherCrit.group(1));
- prefix = "\u00a7f" + STAR;
- suffix = "\u00a7f" + STAR + matcherCrit.group(2);
- } else {
- Matcher matcherNoCrit = PATTERN_NO_CRIT.matcher(formatted);
- if (matcherNoCrit.matches()) {
- numbers = matcherNoCrit.group(1);
- prefix = "\u00A77";
- suffix = "\u00A7r" + matcherNoCrit.group(2);
- } else {
- replacementMap.put(entity, null);
- return name;
- }
- }
-
- StringBuilder newFormatted = new StringBuilder();
-
- try {
- int number = Integer.parseInt(numbers);
-
- if (number > 999 && NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle == 2) {
- newFormatted.append(Utils.shortNumberFormat(number, 0));
- } else {
- newFormatted.append(NumberFormat.getIntegerInstance().format(number));
- }
- } catch (NumberFormatException e) {
- replacementMap.put(entity, null);
- return name;
- }
-
- if (crit) {
- StringBuilder newFormattedCrit = new StringBuilder();
-
- int colourIndex = 0;
- for (char c : newFormatted.toString().toCharArray()) {
- if (c == ',') {
- newFormattedCrit.append(EnumChatFormatting.GRAY);
- } else {
- newFormattedCrit.append(coloursHypixel[colourIndex++ % coloursHypixel.length]);
- }
- newFormattedCrit.append(c);
- }
-
- newFormatted = newFormattedCrit;
- }
-
- ChatComponentText finalComponent = new ChatComponentText(prefix + newFormatted + suffix);
-
- replacementMap.put(entity, finalComponent);
- return finalComponent;
+ private static final WeakHashMap<EntityLivingBase, ChatComponentText> replacementMap = new WeakHashMap<>();
+
+ private static final EnumChatFormatting[] coloursHypixel = {
+ EnumChatFormatting.WHITE,
+ EnumChatFormatting.YELLOW,
+ EnumChatFormatting.GOLD,
+ EnumChatFormatting.RED,
+ EnumChatFormatting.RED,
+ EnumChatFormatting.WHITE
+ };
+
+ private static final char STAR = '\u2727';
+ private static final Pattern PATTERN_CRIT = Pattern.compile(
+ "\u00a7f" + STAR + "((?:\u00a7.\\d)+)\u00a7." + STAR + "(.*)");
+ private static final Pattern PATTERN_NO_CRIT = Pattern.compile("\u00a77(\\d+)(.*)");
+
+ public static IChatComponent replaceName(EntityLivingBase entity) {
+ if (!entity.hasCustomName()) return entity.getDisplayName();
+
+ IChatComponent name = entity.getDisplayName();
+ if (NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle == 0) return name;
+
+ if (replacementMap.containsKey(entity)) {
+ ChatComponentText component = replacementMap.get(entity);
+ if (component == null) return name;
+ return component;
+ }
+
+ String formatted = name.getFormattedText();
+
+ boolean crit = false;
+ String numbers;
+ String prefix;
+ String suffix;
+
+ Matcher matcherCrit = PATTERN_CRIT.matcher(formatted);
+ if (matcherCrit.matches()) {
+ crit = true;
+ numbers = StringUtils.cleanColour(matcherCrit.group(1));
+ prefix = "\u00a7f" + STAR;
+ suffix = "\u00a7f" + STAR + matcherCrit.group(2);
+ } else {
+ Matcher matcherNoCrit = PATTERN_NO_CRIT.matcher(formatted);
+ if (matcherNoCrit.matches()) {
+ numbers = matcherNoCrit.group(1);
+ prefix = "\u00A77";
+ suffix = "\u00A7r" + matcherNoCrit.group(2);
+ } else {
+ replacementMap.put(entity, null);
+ return name;
+ }
+ }
+
+ StringBuilder newFormatted = new StringBuilder();
+
+ try {
+ int number = Integer.parseInt(numbers);
+
+ if (number > 999 && NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle == 2) {
+ newFormatted.append(Utils.shortNumberFormat(number, 0));
+ } else {
+ newFormatted.append(NumberFormat.getIntegerInstance().format(number));
+ }
+ } catch (NumberFormatException e) {
+ replacementMap.put(entity, null);
+ return name;
+ }
+
+ if (crit) {
+ StringBuilder newFormattedCrit = new StringBuilder();
+
+ int colourIndex = 0;
+ for (char c : newFormatted.toString().toCharArray()) {
+ if (c == ',') {
+ newFormattedCrit.append(EnumChatFormatting.GRAY);
+ } else {
+ newFormattedCrit.append(coloursHypixel[colourIndex++ % coloursHypixel.length]);
+ }
+ newFormattedCrit.append(c);
+ }
+
+ newFormatted = newFormattedCrit;
+ }
+
+ ChatComponentText finalComponent = new ChatComponentText(prefix + newFormatted + suffix);
+
+ replacementMap.put(entity, finalComponent);
+ return finalComponent;
/*if (formatted.startsWith("\u00A7f\u2727")) System.out.println(formatted);
@@ -197,5 +205,5 @@ public class DamageCommas {
}
replacementMap.put(hashCode, null);
return name;*/
- }
+ }
}