@@ -326,9 +326,10 @@ private static int deleteMore(CommandContext<CommandSourceStack> context) {
326326 .withStyle (
327327 style -> style
328328 .withClickEvent (
329- new ClickEvent (ClickEvent .Action .RUN_COMMAND , String .format ("/savestate delete %s %s force" , index , indexTo ))
329+ createClickEvent (ClickEvent .Action .RUN_COMMAND , String .format ("/savestate delete %s %s force" , index , indexTo ))
330330 )
331- .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.deleteMore.hover" ).withStyle (ChatFormatting .DARK_RED )))
331+ .withHoverEvent (
332+ createHoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.deleteMore.hover" ).withStyle (ChatFormatting .DARK_RED )))
332333 )).withStyle (ChatFormatting .GREEN );
333334
334335
@@ -471,7 +472,9 @@ private static void showInfo(CommandContext<CommandSourceStack> context, Integer
471472
472473 //@formatter:off
473474 UnaryOperator <Style > hover = t ->
474- t .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , Component .literal (date ).withStyle (dateColor )));
475+ t .withHoverEvent (
476+ createHoverEvent (HoverEvent .Action .SHOW_TEXT , Component .literal (date ).withStyle (dateColor ))
477+ );
475478
476479 Component msg = null ;
477480
@@ -483,8 +486,8 @@ private static void showInfo(CommandContext<CommandSourceStack> context, Integer
483486 Component .translatable ("msg.lotaslight.savestate.info.error" , failedSavestate .getError ().getMessage ())
484487 .withStyle (ChatFormatting .RED ))
485488 .withStyle (t ->
486- t .withHoverEvent (new HoverEvent ( HoverEvent . Action . SHOW_TEXT ,
487- Component .literal (date ).withStyle (ChatFormatting .GOLD )
489+ t .withHoverEvent (
490+ createHoverEvent ( HoverEvent . Action . SHOW_TEXT , Component .literal (date ).withStyle (ChatFormatting .GOLD )
488491 )));
489492 } else {
490493 if (!LoTASLightClient .config .getBoolean (ConfigOptions .SAVESTATE_SHOW_CONTROLS )) {
@@ -497,34 +500,36 @@ private static void showInfo(CommandContext<CommandSourceStack> context, Integer
497500 else {
498501 Component saveComponent = Component .translatable ("msg.lotaslight.savestate.save.clickable" ).withStyle (saveColor )
499502 .withStyle (t ->
500- t .withClickEvent (new ClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate save %s" , index )))
503+ t .withClickEvent (
504+ createClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate save %s" , index )))
501505 )
502506 .withStyle (t ->
503- t .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.save.hover" , name ).withStyle (saveColor )))
507+ t .withHoverEvent (
508+ createHoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.save.hover" , name ).withStyle (saveColor )))
504509 );
505510
506511 Component deleteComponent = Component .translatable ("msg.lotaslight.savestate.delete.clickable" ).withStyle (deleteColor )
507512 .withStyle (t ->
508- t .withClickEvent (new ClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate delete %s" , index )))
513+ t .withClickEvent (createClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate delete %s" , index )))
509514 )
510515 .withStyle (t ->
511- t .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.delete.hover" , name ).withStyle (deleteColor )))
516+ t .withHoverEvent (createHoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.delete.hover" , name ).withStyle (deleteColor )))
512517 );
513518
514519 Component renameComponent = Component .translatable ("msg.lotaslight.savestate.rename.clickable" ).withStyle (renameColor )
515520 .withStyle (t ->
516- t .withClickEvent (new ClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate rename %s " , index )))
521+ t .withClickEvent (createClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate rename %s " , index )))
517522 )
518523 .withStyle (t ->
519- t .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.rename.hover" , name ).withStyle (renameColor )))
524+ t .withHoverEvent (createHoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.rename.hover" , name ).withStyle (renameColor )))
520525 );
521526
522527 Component loadComponent = Component .translatable ("msg.lotaslight.savestate.load.clickable" ).withStyle (loadColor )
523528 .withStyle (t ->
524- t .withClickEvent (new ClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate load %s" , index )))
529+ t .withClickEvent (createClickEvent (ClickEvent .Action .SUGGEST_COMMAND , String .format ("/savestate load %s" , index )))
525530 )
526531 .withStyle (t ->
527- t .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.load.hover" , name ).withStyle (loadColor )))
532+ t .withHoverEvent (createHoverEvent (HoverEvent .Action .SHOW_TEXT , Component .translatable ("msg.lotaslight.savestate.load.hover" , name ).withStyle (loadColor )))
528533 );
529534
530535 msg = Component .translatable ("%s: %s %s %s %s %s" ,
@@ -542,6 +547,46 @@ private static void showInfo(CommandContext<CommandSourceStack> context, Integer
542547 context .getSource ().sendSystemMessage (msg );
543548 }
544549 }
550+
551+ private static ClickEvent createClickEvent (ClickEvent .Action action , String command ) {
552+ //# 1.21.5
553+ //$$ return switch (action) {
554+ //$$ case COPY_TO_CLIPBOARD: {
555+ //$$ yield new ClickEvent.CopyToClipboard(command);
556+ //$$ }
557+ //$$ case RUN_COMMAND: {
558+ //$$ yield new ClickEvent.RunCommand(command);
559+ //$$ }
560+ //$$ case SUGGEST_COMMAND: {
561+ //$$ yield new ClickEvent.SuggestCommand(command);
562+ //$$ }
563+ //$$ default:
564+ //$$ throw new IllegalArgumentException("Unexpected value: " + action);
565+ //$$ };
566+ //# def
567+ return new ClickEvent (action , command );
568+ //# end
569+ }
570+
571+ private static HoverEvent createHoverEvent (
572+ //# 1.21.5
573+ //$$ HoverEvent.Action action,
574+ //# def
575+ HoverEvent .Action <Component > action ,
576+ //# end
577+ Component component ) {
578+ //# 1.21.5
579+ //$$ return switch (action) {
580+ //$$ case SHOW_TEXT: {
581+ //$$ yield new HoverEvent.ShowText(component);
582+ //$$ }
583+ //$$ default:
584+ //$$ throw new IllegalArgumentException("Unexpected value: " + action);
585+ //$$ };
586+ //# def
587+ return new HoverEvent (action , component );
588+ //# end
589+ }
545590
546591 private static Component wrap (Component component , ChatFormatting color ) {
547592 return ComponentUtils .wrapInSquareBrackets (component ).withStyle (color );
0 commit comments