@@ -31,6 +31,23 @@ public class SpooncraftNameLinkClient implements ClientModInitializer {
3131 // List of mappings for replacement and optional color changes
3232 private static List <DisplayMapping > mappings = new ArrayList <>();
3333
34+ /**
35+ * Retrieves a mapping matching either the UUID or the name of the Minecraft player.
36+ *
37+ * @param uuid The {@code UUID} of the Minecraft player
38+ * @param name The in-game name of the Minecraft player
39+ * @return The {@code DisplayMapping} object if found, otherwise null
40+ */
41+ public static DisplayMapping getMapping (UUID uuid , String name ) {
42+ // Iterate over the mappings to find the correct match based on UUID or Minecraft name
43+ for (DisplayMapping mapping : mappings ) {
44+ if (Objects .equals (mapping .mc_uuid , uuid ) || Objects .equals (mapping .mc_name , name )) {
45+ return mapping ;
46+ }
47+ }
48+ return null ;
49+ }
50+
3451 /**
3552 * Applies the mapping to a given message. It optionally replaces the Minecraft name with
3653 * the Discord nickname and applies the colour styling.
@@ -43,7 +60,7 @@ public class SpooncraftNameLinkClient implements ClientModInitializer {
4360 * @return A new MutableText object with the mapping applied (replacements and color changes)
4461 */
4562 static MutableText applyMapping (Text message , DisplayMapping mapping ,
46- boolean replaceName , boolean replaceColour ) {
63+ boolean replaceName , boolean replaceColour ) {
4764 if (message == null || message .getString ().isEmpty () || mapping == null ) {
4865 return Text .empty ();
4966 }
@@ -71,7 +88,7 @@ static MutableText applyMapping(Text message, DisplayMapping mapping,
7188 outputMessage .append (newText );
7289
7390 return Optional .empty (); // Continue visiting
74- }, Style .EMPTY );
91+ }, Style .EMPTY );
7592
7693 return outputMessage ;
7794 }
@@ -91,12 +108,9 @@ static MutableText applyMapping(Text message, DisplayMapping mapping,
91108 */
92109 public static Text getStyledName (Text displayName , UUID uuid , String name , boolean replaceName ,
93110 boolean replaceColour ) {
94- // Iterate over the mappings to find the correct match based on UUID or Minecraft name
95- for (DisplayMapping mapping : mappings ) {
96- // If the UUID matches or the name matches, apply the mapping and return it
97- if (Objects .equals (mapping .mc_uuid , uuid ) || Objects .equals (mapping .mc_name , name )) {
98- return applyMapping (displayName , mapping , replaceName , replaceColour );
99- }
111+ DisplayMapping mapping = getMapping (uuid , name );
112+ if (mapping != null ) {
113+ return applyMapping (displayName , mapping , replaceName , replaceColour );
100114 }
101115 return displayName ;
102116 }
@@ -113,7 +127,7 @@ public static Text getStyledName(Text displayName, UUID uuid, String name, boole
113127 */
114128 public static Text getStyledName (Text displayName , String name , boolean replaceName ,
115129 boolean replaceColour ) {
116- return getStyledName (displayName , UUID .fromString ( "00000000-0000-0000-0000-000000000000" ), name , replaceName , replaceColour );
130+ return getStyledName (displayName , UUID .randomUUID ( ), name , replaceName , replaceColour );
117131 }
118132
119133 /**
0 commit comments