Skip to content

Commit

Permalink
Use StringBuilder for mob display name in boss bar
Browse files Browse the repository at this point in the history
  • Loading branch information
wlhlm committed Nov 25, 2024
1 parent b7d4446 commit 285f4c4
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,16 @@ protected String[] getModNameSuffix() {
*/
public String getEntityDisplayName(EntityLivingBase target) {
if (bufferedEntityName == null) {
String buffer = target.getCommandSenderName();
if (buffer == null) {
buffer = target.getClass()
StringBuilder buffer = new StringBuilder();

String mobName = target.getCommandSenderName();
if (mobName == null) {
mobName = target.getClass()
.getSimpleName();
if (StringUtils.isNullOrEmpty(buffer)) {
buffer = buffer.replaceFirst("Entity", "");
if (!StringUtils.isNullOrEmpty(mobName)) {
mobName = mobName.replaceFirst("Entity", "");
} else {
buffer = "Monster";
mobName = "Monster";
}
}

Expand All @@ -411,26 +413,29 @@ public String getEntityDisplayName(EntityLivingBase target) {
modprefix = StatCollector.translateToLocal("translation.infernalmobs:prefix." + modprefix);
}

String prefix = size <= 5
? EnumChatFormatting.AQUA + StatCollector.translateToLocal("translation.infernalmobs:rareClass")
: size <= 10
? EnumChatFormatting.YELLOW + StatCollector.translateToLocal("translation.infernalmobs:ultraClass")
: EnumChatFormatting.GOLD
+ StatCollector.translateToLocal("translation.infernalmobs:infernalClass");

buffer = prefix + modprefix + buffer;
if (size <= 5) {
buffer.append(EnumChatFormatting.AQUA)
.append(StatCollector.translateToLocal("translation.infernalmobs:rareClass"));
} else if (size <= 10) {
buffer.append(EnumChatFormatting.YELLOW)
.append(StatCollector.translateToLocal("translation.infernalmobs:ultraClass"));
} else {
buffer.append(EnumChatFormatting.GOLD)
.append(StatCollector.translateToLocal("translation.infernalmobs:infernalClass"));
}
buffer.append(modprefix);
buffer.append(mobName);

if (size > 1) {
mod = mod.nextMod != null ? mod.nextMod : this;
if (mod.getModNameSuffix() != null) {
String pickedSuffix = mod.getModNameSuffix()[target.getRNG()
.nextInt(mod.getModNameSuffix().length)];
pickedSuffix = StatCollector.translateToLocal("translation.infernalmobs:suffix." + pickedSuffix);
buffer = buffer + pickedSuffix;
buffer.append(StatCollector.translateToLocal("translation.infernalmobs:suffix." + pickedSuffix));
}
}

bufferedEntityName = buffer;
bufferedEntityName = buffer.toString();
}

return bufferedEntityName;
Expand Down

0 comments on commit 285f4c4

Please sign in to comment.