aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/ColouredNames.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/Danker/features/ColouredNames.java')
-rw-r--r--src/main/java/me/Danker/features/ColouredNames.java33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/main/java/me/Danker/features/ColouredNames.java b/src/main/java/me/Danker/features/ColouredNames.java
index d0daf2a..dfd6d84 100644
--- a/src/main/java/me/Danker/features/ColouredNames.java
+++ b/src/main/java/me/Danker/features/ColouredNames.java
@@ -13,16 +13,21 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
+import net.minecraftforge.event.world.WorldEvent;
+import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ColouredNames {
public static List<String> users = new ArrayList<>();
+ public static Map<String, String> nametags = new HashMap<>();
public static final EnumChatFormatting[] RAINBOW_COLOURS = new EnumChatFormatting[]{EnumChatFormatting.RED, EnumChatFormatting.GOLD, EnumChatFormatting.YELLOW, EnumChatFormatting.GREEN, EnumChatFormatting.AQUA, EnumChatFormatting.BLUE, EnumChatFormatting.DARK_PURPLE};
@SubscribeEvent
@@ -58,20 +63,38 @@ public class ColouredNames {
}
}
- @SubscribeEvent
+ @SubscribeEvent(priority = EventPriority.LOW)
public void onRenderLiving(RenderLivingEvent.Specials.Pre<EntityLivingBase> event) {
if (!ToggleCommand.customColouredNames || !Utils.inSkyblock) return;
Entity entity = event.entity;
- if (entity instanceof EntityArmorStand && entity.hasCustomName()) {
- for (String user : users) {
- if (entity.getCustomNameTag().contains(user)) {
- entity.setCustomNameTag(replaceName(entity.getCustomNameTag(), user, getColourFromName(user)));
+ if (entity instanceof EntityArmorStand && !entity.isDead && entity.hasCustomName()) {
+ String name = entity.getCustomNameTag();
+ if (name.charAt(name.length() - 1) == '❤') return;
+
+ String id = entity.getUniqueID().toString();
+ String nametag = nametags.get(id);
+
+ if (name.equals(nametag)) {
+ entity.setCustomNameTag(nametag);
+ } else {
+ for (String user : users) {
+ if (name.contains(user)) {
+ name = replaceName(name, user, getColourFromName(user));
+ }
}
+
+ nametags.put(id, name);
+ entity.setCustomNameTag(name);
}
}
}
+ @SubscribeEvent
+ public void onWorldChange(WorldEvent.Load event) {
+ nametags.clear();
+ }
+
// https://github.com/SteveKunG/SkyBlockcatia/blob/1.8.9/src/main/java/com/stevekung/skyblockcatia/utils/SupporterUtils.java#L53
public static String replaceName(String text, String name, String colour) {
String namePattern = "(?:(?:\\u00a7[0-9a-fbr])\\B(?:" + name + ")\\b)|(?:\\u00a7[rb]" + name + "\\u00a7r)|\\b" + name + "\\b";