Skip to content

Commit

Permalink
Add constructors that allows to set minimal and maximal return value.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Jan 18, 2019
1 parent 25371fc commit fb06dae
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@
public class NumberGUI
{
public NumberGUI(User user, int value, BiConsumer<Boolean, Integer> consumer)
{
this(user, value, Integer.MIN_VALUE, Integer.MAX_VALUE, consumer);
}


public NumberGUI(User user, int value, int minValue, BiConsumer<Boolean, Integer> consumer)
{
this(user, value, minValue, Integer.MAX_VALUE, consumer);
}


public NumberGUI(User user, int value, int minValue, int maxValue, BiConsumer<Boolean, Integer> consumer)
{
this.user = user;
this.value = value;
this.consumer = consumer;

this.minValue = minValue;
this.maxValue = maxValue;

this.currentOperation = Button.SET;

this.build();
Expand Down Expand Up @@ -119,6 +134,18 @@ private PanelItem getButton(Button button)
clickHandler = (panel, user, clickType, slot) -> {
// TODO: Build Anvil GUI for editing value.

if (this.value > this.maxValue)
{
// TODO: Throw warning message.
this.value = this.maxValue;
}

if (this.value < this.minValue)
{
// TODO: Throw warning message.
this.value = this.minValue;
}

this.build();
return true;
};
Expand Down Expand Up @@ -211,6 +238,19 @@ private PanelItem createNumberButton(int number)
itemBuilder.icon(Material.WHITE_STAINED_GLASS_PANE);
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
this.value = number;

if (this.value > this.maxValue)
{
// TODO: Throw warning message.
this.value = this.maxValue;
}

if (this.value < this.minValue)
{
// TODO: Throw warning message.
this.value = this.minValue;
}

this.build();
return true;
});
Expand All @@ -223,6 +263,13 @@ private PanelItem createNumberButton(int number)
itemBuilder.icon(Material.GREEN_STAINED_GLASS_PANE);
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
this.value += number;

if (this.value > this.maxValue)
{
// TODO: Throw warning message.
this.value = this.maxValue;
}

this.build();
return true;
});
Expand All @@ -235,6 +282,13 @@ private PanelItem createNumberButton(int number)
itemBuilder.icon(Material.RED_STAINED_GLASS_PANE);
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
this.value -= number;

if (this.value < this.minValue)
{
// TODO: Throw warning message.
this.value = this.minValue;
}

this.build();
return true;
});
Expand All @@ -247,6 +301,13 @@ private PanelItem createNumberButton(int number)
itemBuilder.icon(Material.BLUE_STAINED_GLASS_PANE);
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
this.value *= number;

if (this.value > this.maxValue)
{
// TODO: Throw warning message.
this.value = this.maxValue;
}

this.build();
return true;
});
Expand Down Expand Up @@ -301,6 +362,16 @@ private enum Button
*/
private int value;

/**
* Minimal value that is allowed to set.
*/
private int minValue;

/**
* Maximal value that is allowed to set.
*/
private int maxValue;

/**
* This variable holds which operation now is processed.
*/
Expand Down

0 comments on commit fb06dae

Please sign in to comment.