Skip to content

Commit

Permalink
Merge pull request #11 from ELDEpendenci/develop
Browse files Browse the repository at this point in the history
NumberTypeFactory 不再需要必須填寫 min max step 數值
  • Loading branch information
eric2788 authored Sep 1, 2021
2 parents 3035c09 + 08aacba commit fba9697
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -94,24 +95,24 @@ private static <N extends Number> void addNumberType(Class<N> type, MathCalculat
public NumInputField(
AttributeController attributeController,
ItemStackService.ItemFactory itemFactory,
T min,
T max,
T step,
@Nullable T min,
@Nullable T max,
@Nullable T step,
boolean disabled,
String inputMessage,
String errorMessage,
long maxWait,
Class<T> numberType
) {
super(attributeController, itemFactory);
this.min = min;
this.max = max;
this.step = step;
this.math = (MathCalculate<T>) Optional.ofNullable(valueMap.get(numberType)).orElseThrow(() -> new IllegalStateException("unknown number type: " + numberType.getSimpleName()));
this.min = Optional.ofNullable(min).orElse(math.toNumber.apply(0));
this.max = Optional.ofNullable(max).orElse(math.toNumber.apply(64));
this.step = Optional.ofNullable(step).orElse(math.toNumber.apply(1));
this.disabled = disabled;
this.inputMessage = inputMessage;
this.errorMessage = errorMessage;
this.maxWait = maxWait;
this.math = (MathCalculate<T>) Optional.ofNullable(valueMap.get(numberType)).orElseThrow(() -> new IllegalStateException("unknown number type: " + numberType.getSimpleName()));
Number num = (Number) Optional.ofNullable(attributeController.getAttribute(getItem(), AttributeController.VALUE_TAG)).orElse(0);
this.value = math.toNumber.apply(num);
itemFactory.lore("-> " + value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ public NumInputFactory.NumberTypeFactory<T> bindInput(String field, T initValue)
}

public Component build(ItemStackService.ItemFactory itemFactory){
Validate.notNull(min, "you must define min value");
Validate.notNull(max, "you must define max value");
Validate.notNull(step, "you must define step value");
return new NumInputField<T>(
attributeController,
itemFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ public interface NumInputFactory extends ComponentFactory<NumInputFactory> {
interface NumberTypeFactory<T extends Number> {

/**
* <b>必須設置,否則報錯</b>
* 默認數值為 0
* @param min 最少數字
* @return this
*/
NumberTypeFactory<T> min(T min);

/**
* <b>必須設置,否則報錯</b>
* 默認數值為 64
* @param max 最大數字
* @return this
*/
NumberTypeFactory<T> max(T max);

/**
* <b>必須設置,否則報錯</b>
* 默認數值為 1
* @param step 增加/減少數量
* @return this
*/
Expand Down

0 comments on commit fba9697

Please sign in to comment.