Skip to content

Commit 94e1e9e

Browse files
committed
added description as list
1 parent 53924c0 commit 94e1e9e

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/main/java/net/azalealibrary/configuration/ConfigureCommand.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import net.azalealibrary.command.Arguments;
44
import net.azalealibrary.command.AzaleaException;
55
import net.azalealibrary.command.CommandNode;
6+
import net.azalealibrary.command.TextUtil;
67
import net.azalealibrary.configuration.property.ConfigurableProperty;
8+
import net.azalealibrary.configuration.property.ListProperty;
79
import org.bukkit.ChatColor;
810
import org.bukkit.command.CommandSender;
911

@@ -59,19 +61,26 @@ public void execute(CommandSender sender, Arguments arguments) {
5961

6062
for (ConfigurableProperty<?, ?> property : properties) {
6163
property.onExecute(sender, sub);
62-
sender.sendMessage(" " + TextUtil.getName(property));
64+
sender.sendMessage(" " + ChatColor.LIGHT_PURPLE + property.getName() + ChatColor.RESET);
6365
}
6466
}
6567
case RESET -> {
6668
sender.sendMessage(getMessage(properties, "reset"));
6769

6870
for (ConfigurableProperty<?, ?> property : properties) {
6971
property.reset();
70-
sender.sendMessage(" " + TextUtil.getName(property));
72+
sender.sendMessage(" " + ChatColor.LIGHT_PURPLE + property.getName() + ChatColor.RESET);
7173
}
7274
}
7375
case INFO -> {
74-
sender.sendMessage(TextUtil.getCommandInfo(properties.get(0), 60).toArray(String[]::new));
76+
ConfigurableProperty<?, ?> property = properties.get(0);
77+
List<String> info = new ArrayList<>();
78+
String type = property.getType().getExpected() + (property instanceof ListProperty<?> ? " (list)" : "");
79+
info.add("Property: " + ChatColor.LIGHT_PURPLE + property.getName() + ChatColor.RESET + " " + type);
80+
info.add("Default: " + ChatColor.AQUA + property.getDefault());
81+
info.add("Value: " + ChatColor.YELLOW + property);
82+
property.getDescription().forEach(l -> info.addAll(TextUtil.split(l, 55).stream().map(i -> " " + i).toList()));
83+
sender.sendMessage(info.toArray(String[]::new));
7584
}
7685
}
7786
}

src/main/java/net/azalealibrary/configuration/property/ListProperty.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public final class ListProperty<T> extends ConfigurableProperty<T, List<T>> {
1919
private static final String REMOVE = "remove";
2020
private static final String REPLACE = "replace";
2121

22-
private ListProperty(PropertyType<T> type, Supplier<List<T>> defaultValue, String name, String description, Consumer<List<T>> callback, List<AssignmentPolicy<T>> policies) {
22+
private ListProperty(PropertyType<T> type, Supplier<List<T>> defaultValue, String name, List<String> description, Consumer<List<T>> callback, List<AssignmentPolicy<T>> policies) {
2323
super(type, defaultValue, name, description, callback, policies);
2424
}
2525

@@ -102,14 +102,13 @@ public static final class Builder<T> {
102102
private final String name;
103103
private final Supplier<List<T>> defaultValue;
104104
private final List<AssignmentPolicy<T>> policies = new ArrayList<>();
105-
private String description;
105+
private final List<String> description = new ArrayList<>();
106106
private Consumer<List<T>> callback;
107107

108108
private Builder(PropertyType<T> type, String name, Supplier<List<T>> defaultValue) {
109109
this.type = type;
110110
this.name = name;
111111
this.defaultValue = defaultValue;
112-
this.description = name;
113112
this.callback = v -> {};
114113
}
115114

@@ -118,8 +117,8 @@ public Builder<T> addPolicy(AssignmentPolicy<T> policy) {
118117
return this;
119118
}
120119

121-
public Builder<T> addDescription(String description) {
122-
this.description = description;
120+
public Builder<T> description(String line) {
121+
this.description.add(line);
123122
return this;
124123
}
125124

src/main/java/net/azalealibrary/configuration/property/Property.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public final class Property<T> extends ConfigurableProperty<T, T> {
1515

16-
private Property(PropertyType<T> type, Supplier<T> defaultValue, String name, String description, Consumer<T> callback, List<AssignmentPolicy<T>> policies) {
16+
private Property(PropertyType<T> type, Supplier<T> defaultValue, String name, List<String> description, Consumer<T> callback, List<AssignmentPolicy<T>> policies) {
1717
super(type, defaultValue, name, description, callback, policies);
1818
}
1919

@@ -56,14 +56,13 @@ public static final class Builder<T> {
5656
private final String name;
5757
private final Supplier<T> defaultValue;
5858
private final List<AssignmentPolicy<T>> policies = new ArrayList<>();
59-
private String description;
59+
private final List<String> description = new ArrayList<>();
6060
private Consumer<T> callback;
6161

6262
private Builder(PropertyType<T> type, String name, Supplier<T> defaultValue) {
6363
this.type = type;
6464
this.name = name;
6565
this.defaultValue = defaultValue;
66-
this.description = name;
6766
this.callback = v -> {};
6867
}
6968

@@ -72,8 +71,8 @@ public Builder<T> addPolicy(AssignmentPolicy<T> policy) {
7271
return this;
7372
}
7473

75-
public Builder<T> addDescription(String description) {
76-
this.description = description;
74+
public Builder<T> description(String line) {
75+
this.description.add(line);
7776
return this;
7877
}
7978

0 commit comments

Comments
 (0)