1313import org .slf4j .Logger ;
1414import org .slf4j .LoggerFactory ;
1515
16- import java .util .*;
16+ import java .util .Map ;
17+ import java .util .Optional ;
18+ import java .util .UUID ;
1719
1820/**
1921 * Client-side mod initializer for the Minecraft mod "Spooncraft Name Link".
@@ -29,7 +31,7 @@ public class SCNicknamerClient implements ClientModInitializer {
2931 static SCNicknamerConfig config ;
3032
3133 // List of mappings for replacement and optional color changes
32- private static List < DisplayMapping > mappings = new ArrayList <> ();
34+ private static Map < UUID , DisplayMapping > mappings = Map . of ();
3335
3436 /**
3537 * Retrieves a mapping matching either the UUID or the name of the Minecraft player.
@@ -38,14 +40,8 @@ public class SCNicknamerClient implements ClientModInitializer {
3840 * @param name The in-game name of the Minecraft player
3941 * @return The {@code DisplayMapping} object if found, otherwise null
4042 */
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 ;
43+ public static DisplayMapping getMapping (UUID uuid ) {
44+ return mappings .get (uuid );
4945 }
5046
5147 /**
@@ -94,40 +90,22 @@ static MutableText applyMapping(Text message, DisplayMapping mapping,
9490 }
9591
9692 /**
97- * Retrieves and applies the correct name mapping (if any) for a given Minecraft username or
98- * UUID.
99- * Checks the mappings list to see if the provided displayName or uuid has a corresponding
100- * mapping, and if found, applies it by optionally altering the name and color.
93+ * Retrieves and applies the correct name mapping (if any) for a given UUID.
94+ * Checks the mappings list to see if the provided uuid has a corresponding mapping,
95+ * and if found, applies it by optionally altering the name and color.
10196 *
10297 * @param displayName The original in-game name to be displayed
10398 * @param uuid The UUID of the Minecraft player
104- * @param name The in-game name as a Text object
105- * @param replaceName Whether to replace the name with the name defined in the mapping
106- * @param replaceColour Whether to replace the colour with the colour defined in the mapping
107- * @return A Text object containing the potentially modified name with appropriate styling
108- */
109- public static Text getStyledName (Text displayName , UUID uuid , String name , boolean replaceName ,
110- boolean replaceColour ) {
111- DisplayMapping mapping = getMapping (uuid , name );
112- if (mapping != null ) {
113- return applyMapping (displayName , mapping , replaceName , replaceColour );
114- }
115- return displayName ;
116- }
117-
118- /**
119- * Retrieves and applies the correct name mapping (if any) for a given Minecraft username.
120- *
121- * @param displayName The original in-game name to be displayed
122- * @param name The in-game name as a Text object
12399 * @param replaceName Whether to replace the name with the name defined in the mapping
124100 * @param replaceColour Whether to replace the colour with the colour defined in the mapping
125101 * @return A Text object containing the potentially modified name with appropriate styling
126- * @see #getStyledName(Text, UUID, String, boolean, boolean)
127102 */
128- public static Text getStyledName (Text displayName , String name , boolean replaceName ,
103+ public static Text getStyledName (Text displayName , UUID uuid , boolean replaceName ,
129104 boolean replaceColour ) {
130- return getStyledName (displayName , UUID .randomUUID (), name , replaceName , replaceColour );
105+ DisplayMapping mapping = getMapping (uuid );
106+ return (mapping != null )
107+ ? applyMapping (displayName , mapping , replaceName , replaceColour )
108+ : displayName ;
131109 }
132110
133111 /**
@@ -149,16 +127,10 @@ public static Text getStyledChat(Text message, boolean replaceName, boolean repl
149127 MutableText newText = Text .literal (text ).setStyle (style );
150128
151129 HoverEvent event = style .getHoverEvent ();
152- if (event != null ) {
153-
154- if (event .getAction () == HoverEvent .Action .SHOW_ENTITY ) {
155- HoverEvent .EntityContent entity = ((HoverEvent .ShowEntity ) event ).entity ();
156-
157- newText = (MutableText ) getStyledName (newText , entity .uuid ,
158- String .valueOf (entity .name ),
159- replaceName , replaceColour );
160- newText .setStyle (newText .getStyle ().withHoverEvent (event ));
161- }
130+ if (event != null && event .getAction () == HoverEvent .Action .SHOW_ENTITY ) {
131+ HoverEvent .EntityContent entity = ((HoverEvent .ShowEntity ) event ).entity ();
132+ newText = (MutableText ) getStyledName (newText , entity .uuid , replaceName , replaceColour );
133+ newText .setStyle (newText .getStyle ().withHoverEvent (event ));
162134 }
163135
164136 outputMessage .append (newText );
@@ -177,7 +149,9 @@ public static Text getStyledChat(Text message, boolean replaceName, boolean repl
177149 * @return The number of mappings retrieved.
178150 */
179151 public static int getMappings (String source ) {
180- String s = (source == null || source .isEmpty ()) ? "https://gwaff.uqcloud.net/api/spooncraft" : source ;
152+ String s = (source == null || source .isEmpty ())
153+ ? "https://gwaff.uqcloud.net/scnicknamer/test/hashmappings"
154+ : source ;
181155 mappings = NameLinkAPI .getMappings (s );
182156 return mappings .size ();
183157 }
0 commit comments