package me.shedaniel.clothconfig2.impl.builders; import me.shedaniel.clothconfig2.gui.entries.LongListEntry; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; public class LongFieldBuilder extends FieldBuilder { private Consumer saveConsumer = null; private Function> tooltipSupplier = l -> Optional.empty(); private long value; private Long min = null, max = null; public LongFieldBuilder(String resetButtonKey, String fieldNameKey, long value) { super(resetButtonKey, fieldNameKey); this.value = value; } public LongFieldBuilder requireRestart() { requireRestart(true); return this; } public LongFieldBuilder setSaveConsumer(Consumer saveConsumer) { this.saveConsumer = saveConsumer; return this; } public LongFieldBuilder setDefaultValue(Supplier defaultValue) { this.defaultValue = defaultValue; return this; } public LongFieldBuilder setDefaultValue(long defaultValue) { this.defaultValue = () -> defaultValue; return this; } public LongFieldBuilder setTooltipSupplier(Supplier> tooltipSupplier) { this.tooltipSupplier = l -> tooltipSupplier.get(); return this; } public LongFieldBuilder setTooltipSupplier(Function> tooltipSupplier) { this.tooltipSupplier = tooltipSupplier; return this; } public LongFieldBuilder setTooltip(Optional tooltip) { this.tooltipSupplier = l -> tooltip; return this; } public LongFieldBuilder setTooltip(String... tooltip) { this.tooltipSupplier = l -> Optional.ofNullable(tooltip); return this; } public LongFieldBuilder setMin(long min) { this.min = min; return this; } public LongFieldBuilder setMax(long max) { this.max = max; return this; } public LongFieldBuilder removeMin() { this.min = null; return this; } public LongFieldBuilder removeMax() { this.max = null; return this; } @Override public LongListEntry build() { LongListEntry entry = new LongListEntry(getFieldNameKey(), value, getResetButtonKey(), defaultValue, saveConsumer, null, isRequireRestart()); if (min != null) entry.setMinimum(min); if (max != null) entry.setMaximum(max); entry.setTooltipSupplier(() -> tooltipSupplier.apply(entry.getValue())); return entry; } }