diff options
author | bowser0000 <bowser0000@gmail.com> | 2022-03-04 20:26:29 -0500 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2022-03-04 20:26:29 -0500 |
commit | 4a9c72be2c81059569f6cf75e854b9cdefc2891a (patch) | |
tree | 567cffed66a753d41598a3ccdfafc1bf961f3a66 /src/main/java/me/Danker/features/ColouredNames.java | |
parent | 2b57ccad6d21b325c3164117fe14e00e13399a7c (diff) | |
download | SkyblockMod-4a9c72be2c81059569f6cf75e854b9cdefc2891a.tar.gz SkyblockMod-4a9c72be2c81059569f6cf75e854b9cdefc2891a.tar.bz2 SkyblockMod-4a9c72be2c81059569f6cf75e854b9cdefc2891a.zip |
Add custom colours to titles
Diffstat (limited to 'src/main/java/me/Danker/features/ColouredNames.java')
-rw-r--r-- | src/main/java/me/Danker/features/ColouredNames.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/me/Danker/features/ColouredNames.java b/src/main/java/me/Danker/features/ColouredNames.java index f7f4d7a..aad1ab1 100644 --- a/src/main/java/me/Danker/features/ColouredNames.java +++ b/src/main/java/me/Danker/features/ColouredNames.java @@ -2,10 +2,12 @@ package me.Danker.features; import me.Danker.DankersSkyblockMod; import me.Danker.commands.ToggleCommand; +import me.Danker.events.PacketReadEvent; import me.Danker.utils.Utils; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.network.play.server.S45PacketTitle; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; @@ -16,7 +18,9 @@ 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 net.minecraftforge.fml.relauncher.ReflectionHelper; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -30,6 +34,8 @@ public class ColouredNames { 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}; + static Field messageField = ReflectionHelper.findField(S45PacketTitle.class, "message", "field_179810_b", "b"); + @SubscribeEvent public void onChat(ClientChatReceivedEvent event) { if (!ToggleCommand.customColouredNames || !Utils.inSkyblock || event.type != 0) return; @@ -91,6 +97,31 @@ public class ColouredNames { } @SubscribeEvent + public void onPacketRead(PacketReadEvent event) { + if (!ToggleCommand.customColouredNames || !Utils.inSkyblock) return; + + if (event.packet instanceof S45PacketTitle) { + S45PacketTitle packet = (S45PacketTitle) event.packet; + + if (packet.getMessage() == null) return; + + String message = packet.getMessage().getUnformattedText(); + for (String user : users) { + if (message.contains(user)) { + try { + messageField.setAccessible(true); + messageField.set(packet, replaceChat(packet.getMessage(), user)); + event.packet = packet; + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + } + break; + } + } + } + } + + @SubscribeEvent public void onWorldChange(WorldEvent.Load event) { nametags.clear(); } |