Skip to content

Commit 538a097

Browse files
committed
added editable prop
1 parent db3008b commit 538a097

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<groupId>net.azalealibrary</groupId>
1515
<artifactId>configuration</artifactId>
16-
<version>1.1.1</version>
16+
<version>1.1.2</version>
1717

1818
<repositories>
1919
<repository>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ public List<String> complete(CommandSender sender, Arguments arguments) {
3939
List<ConfigurableProperty<?, ?>> properties = configuration.getProperties();
4040

4141
if (arguments.size() == 3) {
42-
return properties.stream().map(ConfigurableProperty::getName).toList();
42+
return properties.stream().filter(ConfigurableProperty::isEditable).map(ConfigurableProperty::getName).toList();
4343
} else if (arguments.size() > 3 && action == Action.SET) {
4444
return properties.stream()
45+
.filter(ConfigurableProperty::isEditable)
4546
.filter(p -> p.getName().equals(arguments.get(2)))
4647
.findFirst().map(p -> p.onComplete(sender, arguments.subArguments(3)))
4748
.orElse(List.of());
@@ -56,6 +57,7 @@ public void execute(CommandSender sender, Arguments arguments) {
5657
Action action = arguments.find(1, "action", input -> Action.valueOf(input.toUpperCase()));
5758
Arguments sub = arguments.subArguments(3);
5859
List<ConfigurableProperty<?, ?>> properties = arguments.find(2, "property", input -> configuration.getProperties().stream()
60+
.filter(ConfigurableProperty::isEditable)
5961
.filter(c -> action.predicate.test(sender, sub, input, c))
6062
.toList());
6163

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ public abstract class ConfigurableProperty<T, P> {
1919
protected final String name;
2020
protected final Consumer<P> callback;
2121
protected final List<String> description;
22+
protected final boolean editable;
2223
protected final Supplier<P> defaultValue;
2324
protected @Nullable P value;
2425

25-
protected ConfigurableProperty(PropertyType<T> propertyType, Supplier<P> defaultValue, String name, List<String> description, Consumer<P> callback, List<AssignmentPolicy<T>> policies) {
26+
protected ConfigurableProperty(PropertyType<T> propertyType, Supplier<P> defaultValue, String name, List<String> description, boolean editable, Consumer<P> callback, List<AssignmentPolicy<T>> policies) {
2627
this.propertyType = propertyType;
2728
this.name = name;
2829
this.description = description;
30+
this.editable = editable;
2931
this.defaultValue = defaultValue;
3032
this.callback = callback;
3133
this.policies = policies;
@@ -44,6 +46,10 @@ public List<String> getDescription() {
4446
return description;
4547
}
4648

49+
public boolean isEditable() {
50+
return editable;
51+
}
52+
4753
public P getDefault() {
4854
return defaultValue.get();
4955
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ 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, List<String> description, Consumer<List<T>> callback, List<AssignmentPolicy<T>> policies) {
23-
super(type, defaultValue, name, description, callback, policies);
22+
private ListProperty(PropertyType<T> type, Supplier<List<T>> defaultValue, String name, List<String> description, boolean editable, Consumer<List<T>> callback, List<AssignmentPolicy<T>> policies) {
23+
super(type, defaultValue, name, description, editable, callback, policies);
2424
}
2525

2626
@Override
@@ -102,6 +102,7 @@ public static final class Builder<T> {
102102
private final List<AssignmentPolicy<T>> policies = new ArrayList<>();
103103
private final List<String> description = new ArrayList<>();
104104
private Consumer<List<T>> callback;
105+
private boolean editable = true;
105106

106107
private Builder(PropertyType<T> type, String name, Supplier<List<T>> defaultValue) {
107108
this.type = type;
@@ -125,8 +126,13 @@ public Builder<T> onChange(Consumer<List<T>> callback) {
125126
return this;
126127
}
127128

129+
public Builder<T> locked() {
130+
editable = false;
131+
return this;
132+
}
133+
128134
public ListProperty<T> done() {
129-
return new ListProperty<>(type, defaultValue, name, description, callback, policies);
135+
return new ListProperty<>(type, defaultValue, name, description, editable, callback, policies);
130136
}
131137
}
132138
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

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

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

2020
@Override
@@ -58,6 +58,7 @@ public static final class Builder<T> {
5858
private final List<AssignmentPolicy<T>> policies = new ArrayList<>();
5959
private final List<String> description = new ArrayList<>();
6060
private Consumer<T> callback;
61+
private boolean editable = true;
6162

6263
private Builder(PropertyType<T> type, String name, Supplier<T> defaultValue) {
6364
this.type = type;
@@ -81,8 +82,13 @@ public Builder<T> onChange(Consumer<T> callback) {
8182
return this;
8283
}
8384

85+
public Builder<T> locked() {
86+
editable = false;
87+
return this;
88+
}
89+
8490
public Property<T> done() {
85-
return new Property<>(type, defaultValue, name, description, callback, policies);
91+
return new Property<>(type, defaultValue, name, description, editable, callback, policies);
8692
}
8793
}
8894
}

0 commit comments

Comments
 (0)