add addToItemLores method into SupportPackagePage instead
This commit is contained in:
parent
413948bf38
commit
876ba8fb1f
@ -46,10 +46,6 @@ public class SupportClansPackagePage extends SupportPackagePage
|
|||||||
addRuneAmplifier(20);
|
addRuneAmplifier(20);
|
||||||
addRuneAmplifier(60);
|
addRuneAmplifier(60);
|
||||||
|
|
||||||
List<String> allPackages = new ArrayList<>();
|
|
||||||
_packageList.forEach(pair -> allPackages.addAll(pair.getRight()));
|
|
||||||
_receivedClansPackages = getPackageOwnership(allPackages);
|
|
||||||
|
|
||||||
addToItemLores();
|
addToItemLores();
|
||||||
|
|
||||||
buildPage();
|
buildPage();
|
||||||
@ -92,43 +88,4 @@ public class SupportClansPackagePage extends SupportPackagePage
|
|||||||
_packageList.add(getPackagePair(new ItemBuilder(Material.EMERALD).setAmount(Math.min(minutes, 64)), minutes + " Minute Rune Amplifier", packageName));
|
_packageList.add(getPackagePair(new ItemBuilder(Material.EMERALD).setAmount(Math.min(minutes, 64)), minutes + " Minute Rune Amplifier", packageName));
|
||||||
_itemPackages.add(packageName);
|
_itemPackages.add(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToItemLores()
|
|
||||||
{
|
|
||||||
_packageList.forEach(pair ->
|
|
||||||
{
|
|
||||||
// Only process item packages, i.e. ones that
|
|
||||||
// can be received multiple times
|
|
||||||
List<String> packages = pair.getRight().stream().filter(p -> _itemPackages.contains(p)).collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (packages.size() == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack item = pair.getLeft();
|
|
||||||
|
|
||||||
List<String> newLore = new ArrayList<>();
|
|
||||||
|
|
||||||
newLore.addAll(Arrays.asList(
|
|
||||||
C.mBody + "This player has",
|
|
||||||
C.mBody + "received:"
|
|
||||||
));
|
|
||||||
|
|
||||||
for (String packageName : packages)
|
|
||||||
{
|
|
||||||
newLore.add(" " + C.cYellow + _receivedClansPackages.computeIfAbsent(packageName, k -> 0) + " " + C.cWhite + packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
newLore.add("");
|
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
|
|
||||||
newLore.addAll(meta.getLore());
|
|
||||||
|
|
||||||
meta.setLore(newLore);
|
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import mineplex.core.account.CoreClient;
|
import mineplex.core.account.CoreClient;
|
||||||
import mineplex.core.common.Pair;
|
import mineplex.core.common.Pair;
|
||||||
@ -29,6 +32,8 @@ public class SupportPackagePage extends SupportPage
|
|||||||
// as items when the above package is clicked.
|
// as items when the above package is clicked.
|
||||||
protected List<String> _itemPackages;
|
protected List<String> _itemPackages;
|
||||||
|
|
||||||
|
protected Map<String, Integer> _receivedPackages;
|
||||||
|
|
||||||
public SupportPackagePage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage, String name)
|
public SupportPackagePage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage, String name)
|
||||||
{
|
{
|
||||||
super(plugin, shop, player, target, previousPage, name);
|
super(plugin, shop, player, target, previousPage, name);
|
||||||
@ -68,6 +73,25 @@ public class SupportPackagePage extends SupportPage
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addPackage(Pair<ItemStack, List<String>> item, int slot)
|
private void addPackage(Pair<ItemStack, List<String>> item, int slot)
|
||||||
|
{
|
||||||
|
// Only 1 item, and it's an item type
|
||||||
|
if (item.getRight().size() == 1 && _itemPackages.contains(item.getRight().get(0)))
|
||||||
|
{
|
||||||
|
addButton(slot, item.getLeft(), (p, c) ->
|
||||||
|
{
|
||||||
|
getShop().openPageForPlayer(getPlayer(),
|
||||||
|
new SupportGivePackagePage(
|
||||||
|
getPlugin(),
|
||||||
|
getShop(),
|
||||||
|
getPlayer(),
|
||||||
|
_target,
|
||||||
|
this,
|
||||||
|
new ItemBuilder(item.getLeft().getType()).setTitle(item.getLeft().getItemMeta().getDisplayName()),
|
||||||
|
item.getRight().get(0)
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
addButton(slot, item.getLeft(), (p, c) ->
|
addButton(slot, item.getLeft(), (p, c) ->
|
||||||
{
|
{
|
||||||
@ -77,12 +101,61 @@ public class SupportPackagePage extends SupportPage
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<Pair<ItemStack, List<String>>> getPackageList()
|
private List<Pair<ItemStack, List<String>>> getPackageList()
|
||||||
{
|
{
|
||||||
return _packageList;
|
return _packageList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this method once all items
|
||||||
|
* have been added to the _packageList
|
||||||
|
* map so that they can be processed.
|
||||||
|
*/
|
||||||
|
protected void addToItemLores()
|
||||||
|
{
|
||||||
|
List<String> allPackages = new ArrayList<>();
|
||||||
|
_packageList.forEach(pair -> allPackages.addAll(pair.getRight()));
|
||||||
|
_receivedPackages = getPackageOwnership(allPackages);
|
||||||
|
|
||||||
|
_packageList.forEach(pair ->
|
||||||
|
{
|
||||||
|
// Only process item packages, i.e. ones that
|
||||||
|
// can be received multiple times
|
||||||
|
List<String> packages = pair.getRight().stream().filter(p -> _itemPackages.contains(p)).collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (packages.size() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack item = pair.getLeft();
|
||||||
|
|
||||||
|
List<String> newLore = new ArrayList<>();
|
||||||
|
|
||||||
|
newLore.addAll(Arrays.asList(
|
||||||
|
C.mBody + "This player has",
|
||||||
|
C.mBody + "received:"
|
||||||
|
));
|
||||||
|
|
||||||
|
for (String packageName : packages)
|
||||||
|
{
|
||||||
|
newLore.add(" " + C.cYellow + _receivedPackages.computeIfAbsent(packageName, k -> 0) + " " + C.cWhite + packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
newLore.add("");
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
|
newLore.addAll(meta.getLore());
|
||||||
|
|
||||||
|
meta.setLore(newLore);
|
||||||
|
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildPage()
|
protected void buildPage()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user