12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package me.shedaniel.clothconfig2.impl.builders;
- import me.shedaniel.clothconfig2.gui.entries.StringListEntry;
- import org.jetbrains.annotations.NotNull;
- import java.util.Objects;
- import java.util.Optional;
- import java.util.function.Consumer;
- import java.util.function.Function;
- import java.util.function.Supplier;
- public class StringFieldBuilder extends FieldBuilder<String, StringListEntry> {
-
- private Consumer<String> saveConsumer = null;
- private Function<String, Optional<String[]>> tooltipSupplier = str -> Optional.empty();
- private String value;
-
- public StringFieldBuilder(String resetButtonKey, String fieldNameKey, String value) {
- super(resetButtonKey, fieldNameKey);
- Objects.requireNonNull(value);
- this.value = value;
- }
-
- public StringFieldBuilder setErrorSupplier(Function<String, Optional<String>> errorSupplier) {
- this.errorSupplier = errorSupplier;
- return this;
- }
-
- public StringFieldBuilder requireRestart() {
- requireRestart(true);
- return this;
- }
-
- public StringFieldBuilder setSaveConsumer(Consumer<String> saveConsumer) {
- this.saveConsumer = saveConsumer;
- return this;
- }
-
- public StringFieldBuilder setDefaultValue(Supplier<String> defaultValue) {
- this.defaultValue = defaultValue;
- return this;
- }
-
- public StringFieldBuilder setDefaultValue(String defaultValue) {
- this.defaultValue = () -> Objects.requireNonNull(defaultValue);
- return this;
- }
-
- public StringFieldBuilder setTooltipSupplier(Supplier<Optional<String[]>> tooltipSupplier) {
- this.tooltipSupplier = str -> tooltipSupplier.get();
- return this;
- }
-
- public StringFieldBuilder setTooltipSupplier(Function<String, Optional<String[]>> tooltipSupplier) {
- this.tooltipSupplier = tooltipSupplier;
- return this;
- }
- public StringFieldBuilder setTooltip(Optional<String[]> tooltip) {
- this.tooltipSupplier = str -> tooltip;
- return this;
- }
- public StringFieldBuilder setTooltip(String... tooltip) {
- this.tooltipSupplier = str -> Optional.ofNullable(tooltip);
- return this;
- }
- @NotNull
- @Override
- public StringListEntry build() {
- StringListEntry entry = new StringListEntry(getFieldNameKey(), value, getResetButtonKey(), defaultValue, saveConsumer, null, isRequireRestart());
- entry.setTooltipSupplier(() -> tooltipSupplier.apply(entry.getValue()));
- if (errorSupplier != null)
- entry.setErrorSupplier(() -> errorSupplier.apply(entry.getValue()));
- return entry;
- }
- }
|