LongFieldBuilder.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package me.shedaniel.clothconfig2.impl.builders;
  2. import me.shedaniel.clothconfig2.gui.entries.LongListEntry;
  3. import java.util.Optional;
  4. import java.util.function.Consumer;
  5. import java.util.function.Supplier;
  6. public class LongFieldBuilder extends FieldBuilder<Long, LongListEntry> {
  7. private Consumer<Long> saveConsumer = null;
  8. private Supplier<Optional<String[]>> tooltipSupplier = null;
  9. private long value;
  10. private Long min = null, max = null;
  11. public LongFieldBuilder(String resetButtonKey, String fieldNameKey, long value) {
  12. super(resetButtonKey, fieldNameKey);
  13. this.value = value;
  14. }
  15. public LongFieldBuilder requireRestart() {
  16. requireRestart(true);
  17. return this;
  18. }
  19. public LongFieldBuilder setSaveConsumer(Consumer<Long> saveConsumer) {
  20. this.saveConsumer = saveConsumer;
  21. return this;
  22. }
  23. public LongFieldBuilder setDefaultValue(Supplier<Long> defaultValue) {
  24. this.defaultValue = defaultValue;
  25. return this;
  26. }
  27. public LongFieldBuilder setDefaultValue(long defaultValue) {
  28. this.defaultValue = () -> defaultValue;
  29. return this;
  30. }
  31. public LongFieldBuilder setTooltipSupplier(Supplier<Optional<String[]>> tooltipSupplier) {
  32. this.tooltipSupplier = tooltipSupplier;
  33. return this;
  34. }
  35. public LongFieldBuilder setTooltip(Optional<String[]> tooltip) {
  36. this.tooltipSupplier = () -> tooltip;
  37. return this;
  38. }
  39. public LongFieldBuilder setTooltip(String... tooltip) {
  40. this.tooltipSupplier = () -> Optional.ofNullable(tooltip);
  41. return this;
  42. }
  43. public LongFieldBuilder setMin(long min) {
  44. this.min = min;
  45. return this;
  46. }
  47. public LongFieldBuilder setMax(long max) {
  48. this.max = max;
  49. return this;
  50. }
  51. public LongFieldBuilder removeMin() {
  52. this.min = null;
  53. return this;
  54. }
  55. public LongFieldBuilder removeMax() {
  56. this.max = null;
  57. return this;
  58. }
  59. @Override
  60. public LongListEntry build() {
  61. LongListEntry entry = new LongListEntry(getFieldNameKey(), value, getResetButtonKey(), defaultValue, saveConsumer, tooltipSupplier, isRequireRestart());
  62. if (min != null)
  63. entry.setMinimum(min);
  64. if (max != null)
  65. entry.setMaximum(max);
  66. return entry;
  67. }
  68. }