11package top .gregtao .concerto .command ;
22
3- import com .mojang .brigadier .CommandDispatcher ;
43import com .mojang .brigadier .arguments .IntegerArgumentType ;
54import com .mojang .brigadier .arguments .StringArgumentType ;
65import com .mojang .brigadier .builder .ArgumentBuilder ;
76import com .mojang .brigadier .builder .LiteralArgumentBuilder ;
87import com .mojang .brigadier .tree .LiteralCommandNode ;
9- import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
10- import net .fabricmc .fabric .api .client .command .v2 .FabricClientCommandSource ;
8+ import net .fabricmc .fabric .api .client .command .v1 .ClientCommandManager ;
9+ import net .fabricmc .fabric .api .client .command .v1 .FabricClientCommandSource ;
1110import net .minecraft .client .network .ClientPlayerEntity ;
12- import net .minecraft .command . CommandRegistryAccess ;
11+ import net .minecraft .text . LiteralText ;
1312import net .minecraft .text .Text ;
13+ import net .minecraft .text .TranslatableText ;
1414import top .gregtao .concerto .api .CacheableMusic ;
1515import top .gregtao .concerto .api .Likeable ;
1616import top .gregtao .concerto .config .MusicCacheManager ;
4040
4141public class MusicCommand {
4242
43- public static void register (CommandDispatcher < FabricClientCommandSource > dispatcher , CommandRegistryAccess access ) {
44- LiteralCommandNode <FabricClientCommandSource > node = dispatcher .register (registerPlayerControllers (
43+ public static void register () {
44+ LiteralCommandNode <FabricClientCommandSource > node = ClientCommandManager . DISPATCHER .register (registerPlayerControllers (
4545 ClientCommandManager .literal ("music" )
4646 .then (addMusicCommand ())
4747 .then (insertMusicCommand ())
4848 ));
49- dispatcher .register (ClientCommandManager .literal ("concerto" ).redirect (node ));
49+ ClientCommandManager . DISPATCHER .register (ClientCommandManager .literal ("concerto" ).redirect (node ));
5050 }
5151
5252 private static final List <MusicAdderBuilder .MusicGetter <Music >> GETTERS = List .of (
5353 context -> {
5454 LocalFileMusic music = new LocalFileMusic (StringArgumentType .getString (context , "path" ));
55- return Pair .of (music , Text . translatable (Sources .LOCAL_FILE .getKey ("add" ), music .getRawPath ()));
55+ return Pair .of (music , new TranslatableText (Sources .LOCAL_FILE .getKey ("add" ), music .getRawPath ()));
5656 },
5757 context -> {
5858 HttpFileMusic music = new HttpFileMusic (StringArgumentType .getString (context , "path" ));
59- return Pair .of (music , Text . translatable (Sources .INTERNET .getKey ("add" ), music .getRawPath ()));
59+ return Pair .of (music , new TranslatableText (Sources .INTERNET .getKey ("add" ), music .getRawPath ()));
6060 },
6161 NeteaseCloudMusicCommand ::musicGetter
6262 );
@@ -68,20 +68,20 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
6868 ClientCommandManager .literal ("pause" ).executes (context -> {
6969 if (player .forcePaused ) {
7070 player .forceResume ();
71- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.resume" ));
71+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.resume" ));
7272 } else {
7373 player .forcePause ();
74- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.pause" ));
74+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.pause" ));
7575 }
7676 return 0 ;
7777 })
7878 ).then (
7979 ClientCommandManager .literal ("start" ).executes (context -> {
8080 if (!player .started ) {
8181 player .start ();
82- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.start" ));
82+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.start" ));
8383 } else {
84- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.already_started" ));
84+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.already_started" ));
8585 }
8686 return 0 ;
8787 })
@@ -91,48 +91,48 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
9191 player .playNextLock = true ;
9292 player .stop ();
9393 MusicPlayerHandler .INSTANCE .resetInfo ();
94- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.stop" ));
94+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.stop" ));
9595 return 0 ;
9696 })
9797 ).then (
9898 ClientCommandManager .literal ("skip" ).executes (context -> {
9999 MusicPlayer .INSTANCE .stop ();
100- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.skip" ));
100+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.skip" ));
101101 return 0 ;
102102 }).then (
103103 ClientCommandManager .argument ("index" , IntegerArgumentType .integer (1 )).executes (context -> {
104104 int index = IntegerArgumentType .getInteger (context , "index" );
105105 MusicPlayer .INSTANCE .skipTo (index - 1 );
106- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.skip_to" , index ));
106+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.skip_to" , index ));
107107 return 0 ;
108108 })
109109 )
110110 ).then (
111111 ClientCommandManager .literal ("cut" ).executes (context -> {
112112 MusicPlayer .INSTANCE .cut (() -> {});
113- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.cut" ));
113+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.cut" ));
114114 return 0 ;
115115 })
116116 ).then (
117117 ClientCommandManager .literal ("clear" ).executes (context -> {
118118 MusicPlayer .INSTANCE .clear ();
119119 MusicPlayer .resetInstance ();
120- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.clear" ));
120+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.clear" ));
121121 return 0 ;
122122 })
123123 ).then (
124124 ClientCommandManager .literal ("mode" ).then (
125125 ClientCommandManager .argument ("mode" , OrderTypeArgumentType .orderType ()).executes ((context -> {
126126 OrderType type = OrderTypeArgumentType .getOrderType (context , "mode" );
127127 MusicPlayerHandler .INSTANCE .setOrderType (type );
128- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.mode" , type .getName ().getString ()));
128+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.mode" , type .getName ().getString ()));
129129 return 0 ;
130130 }))
131131 )
132132 ).then (
133133 ClientCommandManager .literal ("reload" ).executes (context -> {
134134 MusicPlayer .INSTANCE .reloadConfig (() ->
135- TextUtil .commandMessageClient (context , Text . translatable ("concerto.player.reload" )));
135+ TextUtil .commandMessageClient (context , new TranslatableText ("concerto.player.reload" )));
136136 ClientConfig .INSTANCE .readOptions ();
137137 MusicPlayer .resetInstance ();
138138 return 0 ;
@@ -148,7 +148,7 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
148148 clientPlayer .sendMessage (TextUtil .PAGE_SPLIT , false );
149149 for (int i = 10 * (page - 1 ); i < Math .min (10 * page , list .size ()); ++i ) {
150150 MusicMetaData meta = list .get (i ).getMeta ();
151- clientPlayer .sendMessage (Text . literal (
151+ clientPlayer .sendMessage (new LiteralText (
152152 (i + 1 ) + ". " + meta .title () + " | " + meta .author ()
153153 + " | " + meta .getSource () + " | " + meta .getDuration ().toShortString ())
154154 .setStyle (TextUtil .getRunCommandStyle ("/concerto skip " + (i + 1 ))), false );
@@ -162,18 +162,18 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
162162 ClientCommandManager .literal ("save" ).executes (context -> {
163163 ClientPlayerEntity clientPlayer = context .getSource ().getPlayer ();
164164 if (MusicPlayerHandler .INSTANCE .currentMusic == null ) {
165- clientPlayer .sendMessage (Text . translatable ("concerto.unknown" ), false );
165+ clientPlayer .sendMessage (new TranslatableText ("concerto.unknown" ), false );
166166 } else if (MusicPlayerHandler .INSTANCE .currentMusic instanceof CacheableMusic music ) {
167167 MusicPlayer .run (() -> {
168168 try {
169169 MusicCacheManager .INSTANCE .addMusic (music );
170- clientPlayer .sendMessage (Text . translatable ("concerto.success" ), false );
170+ clientPlayer .sendMessage (new TranslatableText ("concerto.success" ), false );
171171 } catch (IOException | UnsupportedAudioFileException e ) {
172172 throw new RuntimeException (e );
173173 }
174174 });
175175 } else {
176- clientPlayer .sendMessage (Text . translatable ("concerto.not_cacheable" ), false );
176+ clientPlayer .sendMessage (new TranslatableText ("concerto.not_cacheable" ), false );
177177 }
178178 return 0 ;
179179 })
@@ -183,11 +183,11 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
183183 Music music = MusicPlayerHandler .INSTANCE .getCurrentMusic ();
184184 if (music instanceof Likeable likeable ) {
185185 CompletableFuture .supplyAsync (likeable ::likeIt , MusicPlayer .RUNNERS_POOL ).thenAcceptAsync (success ->
186- clientPlayer .sendMessage (success ? Text . translatable ("concerto.like" ,
186+ clientPlayer .sendMessage (success ? new TranslatableText ("concerto.like" ,
187187 music .getMeta ().title (), music .getMeta ().getSource ()) :
188- Text . translatable ("concerto.fail" ), false ), MusicPlayer .RUNNERS_POOL );
188+ new TranslatableText ("concerto.fail" ), false ), MusicPlayer .RUNNERS_POOL );
189189 } else {
190- clientPlayer .sendMessage (Text . translatable ("concerto.error.unsupported_operation" ), false );
190+ clientPlayer .sendMessage (new TranslatableText ("concerto.error.unsupported_operation" ), false );
191191 }
192192 return 0 ;
193193 })
@@ -197,11 +197,11 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
197197 Music music = MusicPlayerHandler .INSTANCE .getCurrentMusic ();
198198 if (music instanceof Likeable likeable ) {
199199 CompletableFuture .supplyAsync (likeable ::dislikeIt , MusicPlayer .RUNNERS_POOL ).thenAcceptAsync (success ->
200- clientPlayer .sendMessage (success ? Text . translatable ("concerto.dislike" ,
200+ clientPlayer .sendMessage (success ? new TranslatableText ("concerto.dislike" ,
201201 music .getMeta ().title (), music .getMeta ().getSource ()) :
202- Text . translatable ("concerto.fail" ), false ), MusicPlayer .RUNNERS_POOL );
202+ new TranslatableText ("concerto.fail" ), false ), MusicPlayer .RUNNERS_POOL );
203203 } else {
204- clientPlayer .sendMessage (Text . translatable ("concerto.error.unsupported_operation" ), false );
204+ clientPlayer .sendMessage (new TranslatableText ("concerto.error.unsupported_operation" ), false );
205205 }
206206 return 0 ;
207207 })
@@ -229,9 +229,9 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
229229 ),
230230 false
231231 ))) {
232- clientPlayer .sendMessage (Text . translatable ("concerto.playlist.export.success" ), false );
232+ clientPlayer .sendMessage (new TranslatableText ("concerto.playlist.export.success" ), false );
233233 } else {
234- clientPlayer .sendMessage (Text . translatable ("concerto.playlist.export.fail" ), false );
234+ clientPlayer .sendMessage (new TranslatableText ("concerto.playlist.export.fail" ), false );
235235 }
236236 return 0 ;
237237 })
@@ -251,7 +251,7 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> registerPlayerCo
251251 MusicPlayer .INSTANCE .addMusic (
252252 () -> LocalFileMusic .getMusicsInFolder (new File (path )),
253253 () -> context .getSource ().getPlayer ().sendMessage (
254- Text . translatable (Sources .LOCAL_FILE .getKey ("add" ), path ), false )
254+ new TranslatableText (Sources .LOCAL_FILE .getKey ("add" ), path ), false )
255255 );
256256 return 0 ;
257257 })
0 commit comments