Add SupportHomePage + reflective buildPageButton method

This commit is contained in:
Spencer 2018-01-04 19:01:09 -05:00 committed by Alexander Meech
parent 18ad75582a
commit 248472a5d3
2 changed files with 65 additions and 1 deletions

View File

@ -30,7 +30,7 @@ public class SupportChestPage extends SupportPage
private Map<TreasureType, Integer> _treasureRecieved; private Map<TreasureType, Integer> _treasureRecieved;
public SupportChestPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportHomePage homePage) public SupportChestPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage homePage)
{ {
super(plugin, shop, player, target, homePage, "Chests"); super(plugin, shop, player, target, homePage, "Chests");

View File

@ -0,0 +1,64 @@
package mineplex.staffServer.ui;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.Managers;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.C;
import mineplex.core.shop.item.ShopItem;
import mineplex.staffServer.customerSupport.CustomerSupport;
public class SupportHomePage extends SupportPage
{
public SupportHomePage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target)
{
super(plugin, shop, player, target, null);
buildPage();
}
private void buildPageButton(int slot,ShopItem shopItem, Class<? extends SupportPage> clazz)
{
Constructor pageConstructor;
try
{
pageConstructor = clazz.getConstructor(CustomerSupport.class, SupportShop.class, Player.class, CoreClient.class, SupportPage.class);
} catch (NoSuchMethodException e)
{
System.out.println("Could not get page constructor:");
e.printStackTrace();
return;
}
addButton(slot, shopItem, (p, c) -> {
try
{
getShop().openPageForPlayer(getPlayer(), (SupportPage) pageConstructor.newInstance(getPlugin(), getShop(), getPlayer(), _target, this));
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
{
System.out.println("Could not instantiate page:");
e.printStackTrace();
}
});
}
@Override
protected void buildPage()
{
super.buildPage();
buildPageButton(getSlotIndex(1, 1), new ShopItem(Material.CHEST, "Chests", new String[] {
C.mBody + "Click to view or add",
C.mBody + "chests for " + C.cYellow + _target.getName()
}, 1, false, true), SupportChestPage.class);
buildPageButton(getSlotIndex(1, 3), new ShopItem(Material.EMERALD, "Currency", new String[] {
C.mBody + "Click to add gems or",
C.mBody + "shards for " + C.cYellow + _target.getName()
}, 1, false, true), SupportCurrencyPage.class);
}
}