diff options
| author | Vixid <52578495+Vixid1@users.noreply.github.com> | 2022-10-21 07:10:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-20 23:10:32 -0700 |
| commit | bbf48864fa4894352964f28be11d6686d49052ad (patch) | |
| tree | 28182ed70140ecabe4cdbd470deb0418d5bdff69 /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | |
| parent | 218e8048e345f4792cc1b696570fae29ac532ef8 (diff) | |
| download | notenoughupdates-bbf48864fa4894352964f28be11d6686d49052ad.tar.gz notenoughupdates-bbf48864fa4894352964f28be11d6686d49052ad.tar.bz2 notenoughupdates-bbf48864fa4894352964f28be11d6686d49052ad.zip | |
Entity Scale and Party and Guild chat social options (#363)
363/merge
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 2267cbea..1ee24ec8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -57,6 +57,7 @@ import net.minecraft.network.play.client.C0DPacketCloseWindow; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; import net.minecraft.util.Matrix4f; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; @@ -1999,4 +2000,20 @@ public class Utils { public static String getLastOpenChestName() { return SBInfo.getInstance().lastOpenChestName; } + + public static String getNameFromChatComponent(IChatComponent chatComponent) { + String unformattedText = cleanColour(chatComponent.getSiblings().get(0).getUnformattedText()); + String username = unformattedText.substring(unformattedText.indexOf(">") + 2, unformattedText.indexOf(":")); + // If the first character is a square bracket the user has a rank + // So we get the username from the space after the closing square bracket (end of their rank) + if (username.charAt(0) == '[') { + username = username.substring(unformattedText.indexOf(" ") + 2); + } + // If we still get any square brackets it means the user was talking in guild chat with a guild rank + // So we get the username up to the space before the guild rank + if (username.contains("[") || username.contains("]")) { + username = username.substring(0, unformattedText.indexOf(" ")); + } + return username; + } } |
