Skip to content

Commit

Permalink
Create common buttons in CommonGUI panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Jan 14, 2019
1 parent 6a5ec14 commit 594fa0f
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions src/main/java/world/bentobox/challenges/panel/CommonGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;

import java.util.Collections;
import java.util.List;

import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
Expand Down Expand Up @@ -66,6 +70,17 @@ public abstract class CommonGUI
protected PanelItem returnButton;


/**
* This enum contains buttons that is offten used in multiple GUIs.
*/
protected enum CommonButtons
{
NEXT,
PREVIOUS,
RETURN
}


// ---------------------------------------------------------------------
// Section: Constants
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -155,8 +170,6 @@ public CommonGUI(ChallengesAddon addon,
this.parentGUI.build();
return true;
}).build();

this.build();
}


Expand All @@ -169,5 +182,55 @@ public CommonGUI(ChallengesAddon addon,
* This method builds all necessary elements in GUI panel.
*/
public abstract void build();


/**
* This method returns PanelItem that represents given Button.
* @param button Button that must be returned.
* @return PanelItem with requested functionality.
*/
protected PanelItem getButton(CommonButtons button)
{
ItemStack icon;
String name;
List<String> description;
PanelItem.ClickHandler clickHandler;

switch (button)
{
case NEXT:
{
name = this.user.getTranslation("challenges.gui.buttons.next");
description = Collections.emptyList();
icon = new ItemStack(Material.SIGN);
clickHandler = (panel, user, clickType, slot) -> {
this.pageIndex++;
this.build();
return true;
};

break;
}
case PREVIOUS:
{
name = this.user.getTranslation("challenges.gui.buttons.previous");
description = Collections.emptyList();
icon = new ItemStack(Material.SIGN);
clickHandler = (panel, user, clickType, slot) -> {
this.pageIndex--;
this.build();
return true;
};

break;
}
case RETURN:
return this.returnButton;
default:
return null;
}

return new PanelItem(icon, name, description, false, clickHandler, false);
}
}

0 comments on commit 594fa0f

Please sign in to comment.