add SupportPackagePage to make One-Time Package pages easily
This commit is contained in:
parent
d53222e243
commit
3ca0adfeda
@ -0,0 +1,93 @@
|
|||||||
|
package mineplex.staffServer.ui.packages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
|
import mineplex.core.common.Pair;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
|
import mineplex.core.shop.page.MultiPageManager;
|
||||||
|
import mineplex.staffServer.customerSupport.CustomerSupport;
|
||||||
|
import mineplex.staffServer.ui.SupportPage;
|
||||||
|
import mineplex.staffServer.ui.SupportShop;
|
||||||
|
|
||||||
|
public class SupportPackagePage extends SupportPage
|
||||||
|
{
|
||||||
|
private MultiPageManager<Pair<ItemStack, List<String>>> _multiPageManager;
|
||||||
|
|
||||||
|
// Add items to this list for them to display on the page.
|
||||||
|
protected List<Pair<ItemStack, List<String>>> _packageList;
|
||||||
|
|
||||||
|
// Add package names to this list if they should be given
|
||||||
|
// as items when the above package is clicked.
|
||||||
|
protected List<String> _itemPackages;
|
||||||
|
|
||||||
|
public SupportPackagePage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage, String name)
|
||||||
|
{
|
||||||
|
super(plugin, shop, player, target, previousPage, name);
|
||||||
|
|
||||||
|
_multiPageManager = new MultiPageManager<>(this, this::getPackageList, this::addPackage);
|
||||||
|
_packageList = new LinkedList<>();
|
||||||
|
_itemPackages = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Pair<ItemStack, List<String>> getPackagePair(ItemBuilder builder, String name, String... packages)
|
||||||
|
{
|
||||||
|
builder.setTitle(C.cGreenB + name)
|
||||||
|
.addLore(C.mBody + "Click to give the")
|
||||||
|
.addLore(C.mBody + "following items:");
|
||||||
|
|
||||||
|
for (String packageName : packages)
|
||||||
|
{
|
||||||
|
builder.addLore(" " + C.cYellow + packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Pair.create(builder.build(), Arrays.asList(packages));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Pair<ItemStack, List<String>> getPackagePair(Material mat, String name, String... packages)
|
||||||
|
{
|
||||||
|
return getPackagePair(new ItemBuilder(mat), name, packages);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Pair<ItemStack, List<String>> getPackagePair(Material mat, String name)
|
||||||
|
{
|
||||||
|
return getPackagePair(mat, name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Pair<ItemStack, List<String>> getPackagePair(ItemBuilder builder, String name)
|
||||||
|
{
|
||||||
|
return getPackagePair(builder, name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPackage(Pair<ItemStack, List<String>> item, int slot)
|
||||||
|
{
|
||||||
|
addButton(slot, item.getLeft(), (p, c) ->
|
||||||
|
{
|
||||||
|
for (String packageName : item.getRight())
|
||||||
|
{
|
||||||
|
giveUnknownSalesPackage(packageName, _itemPackages.contains(packageName));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Pair<ItemStack, List<String>>> getPackageList()
|
||||||
|
{
|
||||||
|
return _packageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildPage()
|
||||||
|
{
|
||||||
|
super.buildPage();
|
||||||
|
|
||||||
|
_multiPageManager.buildPage();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user