55import com .mojang .brigadier .context .CommandContext ;
66import com .mojang .brigadier .exceptions .CommandSyntaxException ;
77import com .mojang .brigadier .suggestion .SuggestionProvider ;
8- import eu .pb4 .placeholders .api .Placeholders ;
9- import eu .pb4 .placeholders .api .TextParserUtils ;
10- import eu .pb4 .placeholders .api .parsers .TextParserV1 ;
8+ import eu .pb4 .placeholders .api .ParserContext ;
119import eu .pb4 .stylednicknames .NicknameHolder ;
10+ import eu .pb4 .stylednicknames .ParserUtils ;
1211import eu .pb4 .stylednicknames .StyledNicknamesMod ;
12+ import eu .pb4 .stylednicknames .config .Config ;
1313import eu .pb4 .stylednicknames .config .ConfigManager ;
1414import me .drex .vanish .api .VanishAPI ;
1515import me .lucko .fabric .api .permissions .v0 .Permissions ;
@@ -93,30 +93,8 @@ private static int change(CommandContext<ServerCommandSource> context) throws Co
9393 var config = ConfigManager .getConfig ();
9494 var nickname = context .getArgument ("nickname" , String .class );
9595 if (config .configData .maxLength > 0 ) {
96- Map <String , TextParserV1 .TagNodeBuilder > handlers = new HashMap <>();
97- for (var entry : TextParserV1 .SAFE .getTags ()) {
98- if ((config .defaultFormattingCodes .getBoolean (entry .name ())
99- || Permissions .check (context .getSource (), "stylednicknames.format." + entry .name (), 2 ))) {
100-
101- handlers .put (entry .name (), entry .parser ());
102-
103- if (entry .aliases () != null ) {
104- for (var a : entry .aliases ()) {
105- handlers .put (a , entry .parser ());
106- }
107- }
108- }
109- }
110-
111- if (config .configData .allowLegacyFormatting ) {
112- for (Formatting formatting : Formatting .values ()) {
113- if (handlers .get (formatting .getName ()) != null ) {
114- nickname = nickname .replace (String .copyValueOf (new char []{'&' , formatting .getCode ()}), "<" + formatting .getName () + ">" );
115- }
116- }
117- }
118-
119- var output = TextParserUtils .formatText (nickname , handlers ::get );
96+ var parser = ParserUtils .getParser (context .getSource ().getPlayerOrThrow ());
97+ var output = parser .parseText (nickname , ParserContext .of ());
12098
12199 if (output .getString ().length () > config .configData .maxLength && !Permissions .check (context .getSource (), "stylednicknames.ignore_limit" , 2 )) {
122100 context .getSource ().sendFeedback (() -> ConfigManager .getConfig ().tooLongText , false );
@@ -126,17 +104,15 @@ private static int change(CommandContext<ServerCommandSource> context) throws Co
126104
127105 holder .styledNicknames$set (nickname , true );
128106 context .getSource ().sendFeedback (() ->
129- Placeholders . parseText ( ConfigManager .getConfig ().changeText , Placeholders . PREDEFINED_PLACEHOLDER_PATTERN , holder .styledNicknames$placeholdersCommand ()),
107+ ConfigManager .getConfig ().changeText . toText ( ParserContext . of ( Config . KEY , holder .styledNicknames$placeholdersCommand () )),
130108 false );
131109 return 0 ;
132110 }
133111
134112 private static int reset (CommandContext <ServerCommandSource > context ) throws CommandSyntaxException {
135113 NicknameHolder .of (context .getSource ().getPlayerOrThrow ()).styledNicknames$set (null , false );
136114 context .getSource ().sendFeedback (() ->
137- Placeholders .parseText (ConfigManager .getConfig ().resetText , Placeholders .PREDEFINED_PLACEHOLDER_PATTERN , Map .of (
138- "nickname" , context .getSource ().getPlayer ().getName (),
139- "name" , context .getSource ().getPlayer ().getName ()
115+ ConfigManager .getConfig ().resetText .toText (ParserContext .of (Config .KEY , (x ) -> context .getSource ().getPlayer ().getName ()
140116 )),
141117 false );
142118 return 0 ;
@@ -168,7 +144,7 @@ private static int realname(CommandContext<ServerCommandSource> context) {
168144 }
169145 }
170146 if (foundPlayers .isEmpty ()) {
171- context .getSource ().sendError (Text .translatable ("No player with that nickname is currently online." ));
147+ context .getSource ().sendError (Text .literal ("No player with that nickname is currently online." ));
172148 } else {
173149 if (foundPlayers .size () > 1 ) {
174150 context .getSource ().sendFeedback (() -> Text .translatable ("Found %s players with that nickname:" , foundPlayers .size ()), false );
0 commit comments