55import net .azalealibrary .command .CommandNode ;
66import net .azalealibrary .command .TextUtil ;
77import net .azalealibrary .configuration .property .ConfigurableProperty ;
8+ import net .azalealibrary .configuration .property .ListProperty ;
89import org .bukkit .ChatColor ;
910import org .bukkit .command .CommandSender ;
1011
1415
1516public class ConfigureCommand extends CommandNode {
1617
18+ private static final String INDENT = " " ;
19+
1720 public ConfigureCommand () {
1821 super ("configure" );
1922 }
@@ -31,7 +34,7 @@ public List<String> complete(CommandSender sender, Arguments arguments) {
3134
3235 if (arguments .size () == 3 ) {
3336 return properties .stream ().map (ConfigurableProperty ::getName ).toList ();
34- } else if (arguments .size () == 4 && action == Action .SET ) {
37+ } else if (arguments .size () > 3 && action == Action .SET ) {
3538 return properties .stream ()
3639 .filter (p -> p .getName ().equals (arguments .get (2 )))
3740 .findFirst ().map (p -> p .onComplete (sender , arguments .subArguments (3 )))
@@ -56,40 +59,35 @@ public void execute(CommandSender sender, Arguments arguments) {
5659
5760 switch (action ) {
5861 case SET -> {
62+ properties .forEach (p -> p .onExecute (sender , sub ));
5963 sender .sendMessage (getMessage (properties , "updated" ));
60-
61- for (ConfigurableProperty <?, ?> property : properties ) {
62- property .onExecute (sender , sub );
63- sender .sendMessage (" " + ChatColor .LIGHT_PURPLE + property .getName () + ChatColor .RESET );
64- }
6564 }
6665 case RESET -> {
66+ properties .forEach (ConfigurableProperty ::reset );
6767 sender .sendMessage (getMessage (properties , "reset" ));
68-
69- for (ConfigurableProperty <?, ?> property : properties ) {
70- property .reset ();
71- sender .sendMessage (" " + ChatColor .LIGHT_PURPLE + property .getName () + ChatColor .RESET );
72- }
7368 }
7469 case INFO -> {
7570 ConfigurableProperty <?, ?> property = properties .get (0 );
7671
7772 List <String > info = new ArrayList <>();
7873 info .add (ChatColor .LIGHT_PURPLE + property .getName () + ChatColor .RESET + "=" + ChatColor .YELLOW + property );
79- property .getDescription ().forEach (l -> info .addAll (TextUtil .split (l , 55 ).stream ().map (i -> ChatColor .GRAY + " " + i ).toList ()));
74+ property .getDescription ().forEach (l -> info .addAll (TextUtil .split (l , 55 ).stream ().map (i -> ChatColor .GRAY + INDENT + i ).toList ()));
8075 sender .sendMessage (info .toArray (String []::new ));
8176 }
8277 }
8378 }
8479
85- private static String getMessage (List <ConfigurableProperty <?, ?>> properties , String action ) {
86- return String .valueOf (ChatColor .YELLOW ) + properties .size () + ChatColor .RESET +
80+ private static String [] getMessage (List <ConfigurableProperty <?, ?>> properties , String action ) {
81+ List <String > lines = new ArrayList <>();
82+ lines .add (String .valueOf (ChatColor .YELLOW ) + properties .size () + ChatColor .RESET +
8783 (properties .size () > 1 ? " properties" : " property" ) +
88- (properties .size () > 1 ? " have" : " has" ) + " been " + action + ":" ;
84+ (properties .size () > 1 ? " have" : " has" ) + " been " + action + ":" );
85+ lines .addAll (properties .stream ().map (p -> INDENT + ChatColor .LIGHT_PURPLE + p .getName ()).toList ());
86+ return lines .toArray (String []::new );
8987 }
9088
9189 private enum Action {
92- SET ((s , a , i , c ) -> c .getName ().matches (i ) && c .getPropertyType ().test (s , a )),
90+ SET ((s , a , i , c ) -> c instanceof ListProperty <?> ? c . getName (). equals ( i ) : c .getName ().matches (i ) && c .getPropertyType ().test (s , a )),
9391 RESET ((s , a , i , c ) -> c .getName ().matches (i )),
9492 INFO ((s , a , i , c ) -> c .getName ().equals (i ));
9593
0 commit comments