Skip to content

Commit

Permalink
Add method that allows to create custom handler for all buttons in co…
Browse files Browse the repository at this point in the history
…mmon panel.
  • Loading branch information
BONNe committed Jan 6, 2019
1 parent 12880fe commit 7552ade
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/main/java/world/bentobox/addons/biomes/panel/CommonPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected PanelItem createCommonButton(CommonButtons button, PanelItem.ClickHand
return null;
}

return new PanelItem(icon, name, description, glow, clickHandler, false);
return new PanelItem(icon, name, description, glow, handler == null ? clickHandler : handler, false);
}


Expand All @@ -314,6 +314,18 @@ protected PanelItem createCommonButton(CommonButtons button, PanelItem.ClickHand
* @return new PanelItem button.
*/
protected PanelItem createCommonButton(NumberButtons button)
{
return this.createCommonButton(button, null);
}


/**
* This method returns button from NumberButtons enum.
* @param button Necessary button.
* @param handler Custom Click handling.
* @return new PanelItem button.
*/
protected PanelItem createCommonButton(NumberButtons button, PanelItem.ClickHandler handler)
{
int number;

Expand Down Expand Up @@ -417,11 +429,7 @@ protected PanelItem createCommonButton(NumberButtons button)
{
icon = new ItemStack(Material.PAPER);
name = this.user.getTranslation("biomes.gui.buttons.value","[number]", Integer.toString(number));
clickHandler = (panel, user1, clickType, slot) -> {
this.valueObject = (int) this.valueObject + number;
this.build();
return true;
};
clickHandler = (panel, user1, clickType, slot) -> true;
}
else if (increase)
{
Expand Down Expand Up @@ -454,7 +462,7 @@ else if (reduce)
};
}

return new PanelItem(icon, name, Collections.emptyList(), false, clickHandler, false);
return new PanelItem(icon, name, Collections.emptyList(), false, handler == null ? clickHandler : handler, false);
}


Expand Down

0 comments on commit 7552ade

Please sign in to comment.