11package dev .plex .command ;
22
3- import dev .plex .command .annotation .CommandParameters ;
4- import dev .plex .command .annotation .CommandPermissions ;
5- import java .util .Arrays ;
6- import java .util .Collections ;
73import java .util .List ;
4+ import java .util .Locale ;
5+ import java .util .concurrent .atomic .AtomicInteger ;
86import net .kyori .adventure .text .Component ;
7+ import org .bukkit .Location ;
8+ import org .bukkit .Particle ;
9+ import org .bukkit .Sound ;
910import org .bukkit .command .CommandSender ;
1011import org .bukkit .entity .Player ;
1112import org .jetbrains .annotations .NotNull ;
1213import org .jetbrains .annotations .Nullable ;
1314
14- @ CommandParameters (name = "examplemodule" , description = "An example command provided by Plex's example module" )
15- @ CommandPermissions (permission = "plex.module.command" )
16- public class ExampleCommand extends PlexCommand
15+ public class ExampleCommand extends SimplePlexCommand
1716{
17+ public ExampleCommand ()
18+ {
19+ super (command ("examplemodule" )
20+ .description ("An example command provided by Plex's example module" )
21+ .usage ("/<command> [info | sparkle]" )
22+ .aliases ("example" )
23+ .build ());
24+ }
25+
1826 @ Override
19- protected Component execute (@ NotNull CommandSender commandSender , @ Nullable Player player , @ NotNull String [] strings )
27+ protected Component execute (@ NotNull CommandSender sender , @ Nullable Player player , @ NotNull String [] args )
2028 {
21- return Component .text ("Example module command" );
29+ if (args .length == 0 )
30+ {
31+ return help ();
32+ }
33+
34+ return switch (args [0 ].toLowerCase (Locale .ROOT ))
35+ {
36+ case "info" -> info ();
37+ case "sparkle" -> sparkle (player );
38+ default -> usage ();
39+ };
2240 }
2341
2442 @ Override
25- public @ NotNull List <String > smartTabComplete (@ NotNull CommandSender sender , @ NotNull String alias , @ NotNull String [] args ) throws IllegalArgumentException
43+ protected @ NotNull List <String > suggestions (@ NotNull CommandSender sender , @ NotNull String alias , @ NotNull String [] args )
2644 {
27- if (silentCheckPermission ( sender , this . getPermission ()) )
45+ if (args . length == 1 )
2846 {
29- if (args .length == 1 )
30- {
31- return Arrays .asList ("option1" , "option2" , "option3" );
32- }
47+ return List .of ("info" , "sparkle" );
48+ }
49+ return List .of ();
50+ }
51+
52+ private Component help ()
53+ {
54+ return mmString ("""
55+ <gold><bold>Plex Example Module</bold></gold>
56+ <gray>Try <yellow>/example info</yellow> or <light_purple>/example sparkle</light_purple>.</gray>
57+ """ );
58+ }
59+
60+ private Component info ()
61+ {
62+ int compatibility = api ().compatibility ().version ();
63+ int loadedModules = api ().modules ().loadedModules ().size ();
64+ return mmString ("<gold>Plex API compatibility:</gold> <yellow>" + compatibility
65+ + "</yellow> <dark_gray>•</dark_gray> <gold>Loaded modules:</gold> <yellow>"
66+ + loadedModules + "</yellow>" );
67+ }
68+
69+ private Component sparkle (@ Nullable Player player )
70+ {
71+ if (player == null )
72+ {
73+ return mmString ("<red>Only players can sparkle.</red>" );
74+ }
3375
34- if (args .length == 2 )
76+ AtomicInteger bursts = new AtomicInteger ();
77+ api ().scheduler ().runEntityTimer (player , task ->
78+ {
79+ int burst = bursts .incrementAndGet ();
80+ Location origin = player .getLocation ().add (0 , 1 , 0 );
81+ player .getWorld ().spawnParticle (Particle .END_ROD , origin , 12 , 0.6 , 0.7 , 0.6 , 0.02 );
82+ player .playSound (origin , Sound .BLOCK_NOTE_BLOCK_CHIME , 0.7f , 1.2f + burst * 0.15f );
83+ if (burst >= 4 )
3584 {
36- return Arrays . asList ( "option3" , "option4" );
85+ task . cancel ( );
3786 }
38- return Collections . emptyList ( );
39- }
40- return Collections . emptyList ( );
87+ }, null , 1L , 5L );
88+
89+ return mmString ( "<rainbow>A tiny celebration!</rainbow>" );
4190 }
42- }
91+ }
0 commit comments