11package dev .plex .command ;
22
3+ import com .mojang .brigadier .builder .LiteralArgumentBuilder ;
4+ import io .papermc .paper .command .brigadier .CommandSourceStack ;
35import java .util .List ;
46import java .util .Locale ;
57import java .util .concurrent .atomic .AtomicInteger ;
68import net .kyori .adventure .text .Component ;
79import org .bukkit .Location ;
810import org .bukkit .Particle ;
911import org .bukkit .Sound ;
10- import org .bukkit .command .CommandSender ;
1112import org .bukkit .entity .Player ;
12- import org .jetbrains .annotations .NotNull ;
1313import org .jetbrains .annotations .Nullable ;
1414
1515public class ExampleCommand extends SimplePlexCommand
@@ -24,31 +24,27 @@ public ExampleCommand()
2424 }
2525
2626 @ Override
27- protected Component execute ( @ NotNull CommandSender sender , @ Nullable Player player , @ NotNull String [] args )
27+ protected void configureCommand ( LiteralArgumentBuilder < CommandSourceStack > command )
2828 {
29- if (args .length == 0 )
30- {
31- return help ();
32- }
29+ command .executes (context -> executeCommand (context , (sender , player ) -> help ()));
30+ command .then (word ("action" )
31+ .suggests ((context , builder ) -> suggestMatching (builder , List .of ("info" , "sparkle" )))
32+ .executes (context -> executeCommand (context ,
33+ (sender , player ) -> executeTyped (player , string (context , "action" ))))
34+ .then (greedyString ("ignored" ).executes (context -> executeCommand (context ,
35+ (sender , player ) -> executeTyped (player , string (context , "action" ))))));
36+ }
3337
34- return switch (args [0 ].toLowerCase (Locale .ROOT ))
38+ private Component executeTyped (@ Nullable Player player , String action )
39+ {
40+ return switch (action .toLowerCase (Locale .ROOT ))
3541 {
3642 case "info" -> info ();
3743 case "sparkle" -> sparkle (player );
3844 default -> usage ();
3945 };
4046 }
4147
42- @ Override
43- protected @ NotNull List <String > suggestions (@ NotNull CommandSender sender , @ NotNull String alias , @ NotNull String [] args )
44- {
45- if (args .length == 1 )
46- {
47- return List .of ("info" , "sparkle" );
48- }
49- return List .of ();
50- }
51-
5248 private Component help ()
5349 {
5450 return mmString ("""
@@ -74,7 +70,7 @@ private Component sparkle(@Nullable Player player)
7470 }
7571
7672 AtomicInteger bursts = new AtomicInteger ();
77- scheduler (). runEntityTimer ( player , task ->
73+ ownTask ( player . getScheduler (). runAtFixedRate ( taskOwner () , task ->
7874 {
7975 int burst = bursts .incrementAndGet ();
8076 Location origin = player .getLocation ().add (0 , 1 , 0 );
@@ -84,7 +80,7 @@ private Component sparkle(@Nullable Player player)
8480 {
8581 task .cancel ();
8682 }
87- }, null , 1L , 5L );
83+ }, null , 1L , 5L )) ;
8884
8985 return mmString ("<rainbow>A tiny celebration!</rainbow>" );
9086 }
0 commit comments