2929import io .github .communityradargg .fabric .utils .Utils ;
3030import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
3131import net .fabricmc .fabric .api .client .command .v2 .FabricClientCommandSource ;
32- import net .minecraft .client .MinecraftClient ;
33- import net .minecraft .client .network . ClientPlayNetworkHandler ;
34- import net .minecraft .client .network . PlayerListEntry ;
35- import net .minecraft .command . permission .Permission ;
36- import net .minecraft .command . permission .PermissionLevel ;
32+ import net .minecraft .client .Minecraft ;
33+ import net .minecraft .client .multiplayer . ClientPacketListener ;
34+ import net .minecraft .client .multiplayer . PlayerInfo ;
35+ import net .minecraft .server . permissions .Permission ;
36+ import net .minecraft .server . permissions .PermissionLevel ;
3737import org .jetbrains .annotations .NotNull ;
3838import java .util .List ;
3939import java .util .Optional ;
@@ -46,7 +46,7 @@ public class RadarCommand {
4646
4747 public static void register (final @ NotNull CommandDispatcher <FabricClientCommandSource > dispatcher ) {
4848 final LiteralCommandNode <FabricClientCommandSource > mainCommand = dispatcher .register (ClientCommandManager .literal (COMMAND_NAME )
49- .requires (source -> source .getPlayer ().getPermissions ().hasPermission (new Permission .Level (REQUIRED_PERMISSION_LEVEL )))
49+ .requires (source -> source .getPlayer ().permissions ().hasPermission (new Permission .HasCommandLevel (REQUIRED_PERMISSION_LEVEL )))
5050 .then (ClientCommandManager .literal ("help" )
5151 .executes (context -> handleHelpSubcommand (context .getSource ()))
5252 )
@@ -162,7 +162,7 @@ public static void register(final @NotNull CommandDispatcher<FabricClientCommand
162162 */
163163 private static int handleMissingArgs (final @ NotNull FabricClientCommandSource source ) {
164164 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .MISSING_ARGS )
165- .build ().toText ());
165+ .build ().toComponent ());
166166 return Command .SINGLE_SUCCESS ;
167167 }
168168
@@ -175,7 +175,7 @@ private static int handleMissingArgs(final @NotNull FabricClientCommandSource so
175175 private static int handleHelpSubcommand (final @ NotNull FabricClientCommandSource source ) {
176176 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .HELP )
177177 .replace ("{code_version}" , CommunityRadarMod .getVersion ())
178- .excludePrefix ().build ().toText ());
178+ .excludePrefix ().build ().toComponent ());
179179 return Command .SINGLE_SUCCESS ;
180180 }
181181
@@ -197,11 +197,11 @@ private static void handleListsSubcommand(final @NotNull FabricClientCommandSour
197197 // players on the list
198198 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Lists .FOUND )
199199 .replace ("{lists}" , listsText .substring (0 , listsText .length () - 2 ))
200- .build ().toText ());
200+ .build ().toComponent ());
201201 } else {
202202 // list is empty
203203 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Lists .EMPTY )
204- .build ().toText ());
204+ .build ().toComponent ());
205205 }
206206 }
207207
@@ -228,21 +228,21 @@ private static int handleCheckSubcommand(final @NotNull FabricClientCommandSourc
228228 */
229229 private static void handleCheckPlayerSubcommand (final @ NotNull FabricClientCommandSource source , final @ NotNull String playerArgument ) {
230230 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .INPUT_PROCESSING )
231- .build ().toText ());
231+ .build ().toComponent ());
232232
233233 Utils .getUUID (playerArgument ).thenAccept (checkPlayerOptional -> {
234234 if (checkPlayerOptional .isEmpty ()) {
235235 // player uuid could not be fetched
236236 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Check .FAILED )
237- .build ().toText ());
237+ .build ().toComponent ());
238238 return ;
239239 }
240240
241241 final Optional <RadarListEntry > entryOptional = CommunityRadarMod .getListManager ().getRadarListEntry (checkPlayerOptional .get ());
242242 if (entryOptional .isEmpty ()) {
243243 // player uuid is on no list
244244 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Check .FAILED )
245- .build ().toText ());
245+ .build ().toComponent ());
246246 return ;
247247 }
248248
@@ -253,7 +253,7 @@ private static void handleCheckPlayerSubcommand(final @NotNull FabricClientComma
253253 .replace ("{cause}" , entry .cause ())
254254 .replace ("{entryCreationDate}" , Utils .formatDateTime (entry .entryCreationDate ()))
255255 .replace ("{entryUpdateDate}" , Utils .formatDateTime (entry .entryUpdateDate ()))
256- .build ().toText ());
256+ .build ().toComponent ());
257257 });
258258 }
259259
@@ -263,29 +263,29 @@ private static void handleCheckPlayerSubcommand(final @NotNull FabricClientComma
263263 * @param source The command source, which executed the subcommand.
264264 */
265265 private static void handleCheckAllSubcommand (final @ NotNull FabricClientCommandSource source ) {
266- final ClientPlayNetworkHandler networkHandler = MinecraftClient .getInstance ().getNetworkHandler ();
267- if (networkHandler == null ) {
266+ final ClientPacketListener clientPacketListener = Minecraft .getInstance ().getConnection ();
267+ if (clientPacketListener == null ) {
268268 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Check .NOT_FOUND )
269- .build ().toText ());
269+ .build ().toComponent ());
270270 return ;
271271 }
272272
273273 boolean anyPlayerFound = false ;
274- for (final PlayerListEntry player : networkHandler . getPlayerList ()) {
275- if (player .getProfile ().id () == null ) {
274+ for (final PlayerInfo playerInfo : clientPacketListener . getOnlinePlayers ()) {
275+ if (playerInfo .getProfile ().id () == null ) {
276276 continue ;
277277 }
278278
279279 final Optional <RadarListEntry > listEntryOptional = CommunityRadarMod .getListManager ()
280- .getRadarListEntry (player .getProfile ().id ());
280+ .getRadarListEntry (playerInfo .getProfile ().id ());
281281 if (listEntryOptional .isEmpty ()) {
282282 // player uuid is on no list
283283 continue ;
284284 }
285285
286286 if (!anyPlayerFound ) {
287287 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Check .EVERYONE )
288- .build ().toText ());
288+ .build ().toComponent ());
289289 anyPlayerFound = true ;
290290 }
291291
@@ -296,12 +296,12 @@ private static void handleCheckAllSubcommand(final @NotNull FabricClientCommandS
296296 .replace ("{cause}" , entry .cause ())
297297 .replace ("{entryCreationDate}" , Utils .formatDateTime (entry .entryCreationDate ()))
298298 .replace ("{entryUpdateDate}" , Utils .formatDateTime (entry .entryUpdateDate ()))
299- .build ().toText ());
299+ .build ().toComponent ());
300300 }
301301
302302 if (!anyPlayerFound ) {
303303 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Check .NOT_FOUND )
304- .build ().toText ());
304+ .build ().toComponent ());
305305 }
306306 }
307307
@@ -317,37 +317,37 @@ private static void handlePlayerAddSubcommand(final @NotNull FabricClientCommand
317317 if (listOptional .isEmpty ()) {
318318 // list not existing
319319 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Player .ADD_FAILED )
320- .build ().toText ());
320+ .build ().toComponent ());
321321 return ;
322322 }
323323
324324 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .INPUT_PROCESSING )
325- .build ().toText ());
325+ .build ().toComponent ());
326326 Utils .getUUID (player ).thenAccept (uuidOptional -> {
327327 if (uuidOptional .isEmpty ()) {
328328 // player uuid could not be fetched
329329 source .sendFeedback (new RadarMessage .RadarMessageBuilder (player .startsWith ("!" ) ? Messages .Player .NAME_INVALID_BEDROCK : Messages .Player .NAME_INVALID )
330- .build ().toText ());
330+ .build ().toComponent ());
331331 return ;
332332 }
333333
334334 final UUID uuid = uuidOptional .get ();
335335 if (listOptional .get ().isInList (uuid )) {
336336 // player already on list
337337 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Player .ADD_IN_LIST )
338- .build ().toText ());
338+ .build ().toComponent ());
339339 return ;
340340 }
341341
342342 if (!CommunityRadarMod .getListManager ().addRadarListEntry (namespace , uuid , player , cause )) {
343343 // list is not private
344344 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Player .ADD_FAILED )
345- .build ().toText ());
345+ .build ().toComponent ());
346346 return ;
347347 }
348348
349349 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Player .ADD_SUCCESS )
350- .build ().toText ());
350+ .build ().toComponent ());
351351 });
352352 }
353353
@@ -362,32 +362,32 @@ private static void handlePlayerRemoveSubcommand(final @NotNull FabricClientComm
362362 if (listOptional .isEmpty ()) {
363363 // list is not existing
364364 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Player .REMOVE_FAILED )
365- .build ().toText ());
365+ .build ().toComponent ());
366366 return ;
367367 }
368368
369369 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .INPUT_PROCESSING )
370- .build ().toText ());
370+ .build ().toComponent ());
371371 final RadarList list = listOptional .get ();
372372 Utils .getUUID (player ).thenAccept (uuidOptional -> {
373373 if (uuidOptional .isEmpty ()) {
374374 // player uuid could not be fetched
375375 source .sendFeedback (new RadarMessage .RadarMessageBuilder (player .startsWith ("!" ) ? Messages .Player .NAME_INVALID_BEDROCK : Messages .Player .NAME_INVALID )
376- .build ().toText ());
376+ .build ().toComponent ());
377377 return ;
378378 }
379379
380380 final UUID uuid = uuidOptional .get ();
381381 if (!list .isInList (uuid )) {
382382 // player uuid not on list
383383 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Player .REMOVE_NOT_IN_LIST )
384- .build ().toText ());
384+ .build ().toComponent ());
385385 return ;
386386 }
387387
388388 list .getPlayerMap ().remove (uuid );
389389 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .Player .REMOVE_SUCCESS )
390- .build ().toText ());
390+ .build ().toComponent ());
391391 });
392392 }
393393
@@ -400,19 +400,19 @@ private static void handleListAddSubcommand(final @NotNull FabricClientCommandSo
400400 if (CommunityRadarMod .getListManager ().getRadarList (namespace ).isPresent ()) {
401401 // list already existing
402402 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .CREATE_FAILED )
403- .build ().toText ());
403+ .build ().toComponent ());
404404 return ;
405405 }
406406
407407 if (!CommunityRadarMod .getListManager ().registerPrivateList (namespace , prefix )) {
408408 // list could not be registered
409409 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .CREATE_FAILED )
410- .build ().toText ());
410+ .build ().toComponent ());
411411 return ;
412412 }
413413
414414 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .CREATE_SUCCESS )
415- .build ().toText ());
415+ .build ().toComponent ());
416416 }
417417
418418 /**
@@ -425,12 +425,12 @@ private static void handleListDeleteSubcommand(final @NotNull FabricClientComman
425425 if (!listManager .unregisterList (namespace )) {
426426 // list is not existing, list is not private, file cannot be deleted
427427 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .DELETE_FAILED )
428- .build ().toText ());
428+ .build ().toComponent ());
429429 return ;
430430 }
431431
432432 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .DELETE_SUCCESS )
433- .build ().toText ());
433+ .build ().toComponent ());
434434 }
435435
436436 /**
@@ -443,15 +443,15 @@ private static void handleListShowSubcommand(final @NotNull FabricClientCommandS
443443 if (listOptional .isEmpty ()) {
444444 // list is not existing
445445 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .SHOW_FAILED )
446- .build ().toText ());
446+ .build ().toComponent ());
447447 return ;
448448 }
449449
450450 final RadarList list = listOptional .get ();
451451 if (list .getPlayerMap ().isEmpty ()) {
452452 // list is empty
453453 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .SHOW_EMPTY )
454- .build ().toText ());
454+ .build ().toComponent ());
455455 return ;
456456 }
457457
@@ -461,7 +461,7 @@ private static void handleListShowSubcommand(final @NotNull FabricClientCommandS
461461 .replace ("{list}" , list .getNamespace ())
462462 .replaceWithColorCodes ("{prefix}" , listOptional .get ().getPrefix ())
463463 .replace ("{players}" , players .substring (0 , players .length () - 2 ))
464- .build ().toText ());
464+ .build ().toComponent ());
465465 }
466466
467467 /**
@@ -475,7 +475,7 @@ private static void handleListPrefixSubcommand(final @NotNull FabricClientComman
475475 if (listOptional .isEmpty ()) {
476476 // list is not existing
477477 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .PREFIX_FAILED )
478- .build ().toText ());
478+ .build ().toComponent ());
479479 return ;
480480 }
481481
@@ -485,6 +485,6 @@ private static void handleListPrefixSubcommand(final @NotNull FabricClientComman
485485
486486 source .sendFeedback (new RadarMessage .RadarMessageBuilder (Messages .List .PREFIX_SUCCESS )
487487 .replaceWithColorCodes ("{prefix}" , prefix )
488- .build ().toText ());
488+ .build ().toComponent ());
489489 }
490490}
0 commit comments