Add constructors that allows to set minimal and maximal return value.

This commit is contained in:
BONNe1704 2019-01-18 17:03:08 +02:00
parent 25371fc6aa
commit fb06dae7ab
1 changed files with 71 additions and 0 deletions

View File

@ -19,11 +19,26 @@ import world.bentobox.bentobox.api.user.User;
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();
@ -119,6 +134,18 @@ public class NumberGUI
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;
};
@ -211,6 +238,19 @@ public class NumberGUI
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;
});
@ -223,6 +263,13 @@ public class NumberGUI
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;
});
@ -235,6 +282,13 @@ public class NumberGUI
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;
});
@ -247,6 +301,13 @@ public class NumberGUI
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;
});
@ -301,6 +362,16 @@ public class NumberGUI
*/
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.
*/