Skip to content

Commit

Permalink
Integrate AnvilGUI into NumberGUI so users could manually write numbe…
Browse files Browse the repository at this point in the history
…rs in GUI.

Add error messages, if number is not valid.
  • Loading branch information
BONNe committed Jan 19, 2019
1 parent c42652d commit faa237d
Showing 1 changed file with 55 additions and 19 deletions.
74 changes: 55 additions & 19 deletions src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import java.util.function.BiConsumer;

import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
Expand Down Expand Up @@ -132,21 +134,35 @@ private PanelItem getButton(Button button)
description = Collections.emptyList();
icon = new ItemStack(Material.ANVIL);
clickHandler = (panel, user, clickType, slot) -> {
// TODO: Build Anvil GUI for editing value.
new AnvilGUI(BentoBox.getInstance(),
this.user.getPlayer(),
Integer.toString(this.value),
(player, reply) -> {
try
{
this.value = Integer.parseInt(reply);

if (this.value > this.maxValue || this.value < this.minValue)
{
this.user.sendMessage("challenges.error.not-valid-integer",
"[value]", reply,
"[min]", Integer.toString(this.minValue),
"[max]", Integer.toString(this.maxValue));
}
else
{
this.build();
}
}
catch (Exception e)
{
reply = Integer.toString(this.value);
this.user.sendMessage("challenges.error.not-a-integer", "[value]", reply);
}

return reply;
});

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;
};
glow = false;
Expand Down Expand Up @@ -241,13 +257,21 @@ private PanelItem createNumberButton(int number)

if (this.value > this.maxValue)
{
// TODO: Throw warning message.
this.user.sendMessage("challenges.error.not-valid-integer",
"[value]", Integer.toString(this.value),
"[min]", Integer.toString(this.minValue),
"[max]", Integer.toString(this.maxValue));

this.value = this.maxValue;
}

if (this.value < this.minValue)
{
// TODO: Throw warning message.
this.user.sendMessage("challenges.error.not-valid-integer",
"[value]", Integer.toString(this.value),
"[min]", Integer.toString(this.minValue),
"[max]", Integer.toString(this.maxValue));

this.value = this.minValue;
}

Expand All @@ -266,7 +290,11 @@ private PanelItem createNumberButton(int number)

if (this.value > this.maxValue)
{
// TODO: Throw warning message.
this.user.sendMessage("challenges.error.not-valid-integer",
"[value]", Integer.toString(this.value),
"[min]", Integer.toString(this.minValue),
"[max]", Integer.toString(this.maxValue));

this.value = this.maxValue;
}

Expand All @@ -285,7 +313,11 @@ private PanelItem createNumberButton(int number)

if (this.value < this.minValue)
{
// TODO: Throw warning message.
this.user.sendMessage("challenges.error.not-valid-integer",
"[value]", Integer.toString(this.value),
"[min]", Integer.toString(this.minValue),
"[max]", Integer.toString(this.maxValue));

this.value = this.minValue;
}

Expand All @@ -304,7 +336,11 @@ private PanelItem createNumberButton(int number)

if (this.value > this.maxValue)
{
// TODO: Throw warning message.
this.user.sendMessage("challenges.error.not-valid-integer",
"[value]", Integer.toString(this.value),
"[min]", Integer.toString(this.minValue),
"[max]", Integer.toString(this.maxValue));

this.value = this.maxValue;
}

Expand Down

0 comments on commit faa237d

Please sign in to comment.