playercurrentgamedata.java LINE 58 is null

This commit is contained in:
Trixkz 2021-11-24 10:50:42 -05:00
parent b78d4d175a
commit 14253308c5
10 changed files with 594 additions and 15 deletions

View File

@ -8,6 +8,7 @@ import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.arena.Arena;
import rip.tilly.bedwars.menus.arena.ArenaManagerMenu;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.menusystem.menu.UpgradesMenu;
public class ArenaCommand implements CommandExecutor {

View File

@ -231,31 +231,31 @@ public class Game {
public void tick(int amount, Game game) {
if (this.secondsToMinutes(amount) == 5D) {
game.broadcast("&bDiamond &egenerators have been upgraded to &bTier II&e.");
game.broadcast("&bDiamond &egenerators have been upgraded to &bTier II");
this.diamondGeneratorTier = GeneratorTier.TWO;
}
if (this.secondsToMinutes(amount) == 8D) {
game.broadcast("&aEmerald &egenerators have been upgraded to &bTier II&e.");
game.broadcast("&aEmerald &egenerators have been upgraded to &bTier II");
this.emeraldGeneratorTier = GeneratorTier.TWO;
}
if (this.secondsToMinutes(amount) == 10D) {
game.broadcast("&bDiamond &egenerators have been upgraded to &bTier III&e.");
game.broadcast("&bDiamond &egenerators have been upgraded to &bTier III");
this.diamondGeneratorTier = GeneratorTier.THREE;
}
if (this.secondsToMinutes(amount) == 12D) {
game.broadcast("&aEmerald &egenerators have been upgraded to &bTier III&e.");
game.broadcast("&aEmerald &egenerators have been upgraded to &bTier III");
this.emeraldGeneratorTier = GeneratorTier.THREE;
}
if (this.secondsToMinutes(amount) == 15D) {
game.broadcast("&bDiamond &egenerators have been upgraded to &bTier IV&e.");
game.broadcast("&bDiamond &egenerators have been upgraded to &bTier IV");
this.diamondGeneratorTier = GeneratorTier.FOUR;
}

View File

@ -5,14 +5,17 @@ import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.TrapDoor;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.GameState;
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
import rip.tilly.bedwars.menus.queue.PlayAGameMenu;
import rip.tilly.bedwars.menus.settings.SettingsMenu;
@ -20,6 +23,7 @@ import rip.tilly.bedwars.menus.shop.blocks.BlocksMenu;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.PlayerState;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.menusystem.menu.UpgradesMenu;
public class InteractListener implements Listener {
@ -139,6 +143,8 @@ public class InteractListener implements Listener {
if (event.getRightClicked() instanceof ArmorStand) {
event.setCancelled(true);
return;
}
String name = event.getRightClicked().getCustomName();
@ -153,17 +159,13 @@ public class InteractListener implements Listener {
case "Item Shop":
event.setCancelled(true);
// open item shop gui
player.sendMessage(CC.translate("&aItem shop menu opened"));
new BlocksMenu().openMenu(player);
break;
case "Upgrades Shop":
event.setCancelled(true);
// open upgrades shop gui
player.sendMessage(CC.translate("&aUpgrades shop menu opened"));
new UpgradesMenu(this.plugin.getPlayerMenuUtil(player)).open(player);
break;
}

View File

@ -1,10 +1,32 @@
package rip.tilly.bedwars.playerdata.currentgame;
import lombok.Data;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.generators.GeneratorTier;
import rip.tilly.bedwars.generators.GeneratorType;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;
import java.util.UUID;
@Data
public class PlayerCurrentGameData {
private BedWars main = BedWars.getInstance();
private int gameKills;
private int gameBedsDestroyed;
@ -13,4 +35,159 @@ public class PlayerCurrentGameData {
private boolean shears = false;
private ArmorType armorType = ArmorType.LEATHER;
private Map<UUID, ArmorType> armor = new HashMap<UUID, ArmorType>();
private Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
public int getLevelForUpgrade(Upgrade upgrade) {
return this.upgrades.getOrDefault(upgrade, 0);
}
public int getCostToUpgrade(Upgrade upgrade) {
return upgrade.getCostForLevel(this.upgrades.getOrDefault(upgrade, 0) + 1);
}
public void upgrade(Player player, Game game, Upgrade upgrade) {
this.upgrades.put(upgrade, this.upgrades.getOrDefault(upgrade, 0) + 1);
int level = this.upgrades.get(upgrade);
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
GameTeam gameTeam = game.getTeams().get(playerData.getTeamId());
game.getTeams().stream().filter(team -> team == gameTeam).forEach(team -> team.playingPlayers().forEach(teamMember -> {
teamMember.sendMessage(CC.translate("&6" + player.getName() + " upgraded " + upgrade.getFormattedName() + " to &cTier " + upgrade.getNumberToRomanNumeral(level)));
// System.out.println("11111111111111111111111 - " + player.getName());
playerData.getCurrentGameData().giveTeamArmor(player, this);
int upgradeLevel = 0;
switch (upgrade) {
case SHARPENED_SWORDS:
// System.out.println("2222222222222222");
for (ListIterator<ItemStack> listIterator = player.getInventory().iterator(); listIterator.hasNext();) {
ItemStack itemStack = listIterator.next();
// System.out.println("33333333333333333");
if (itemStack != null && itemStack.getType().name().toLowerCase().contains("sword")) {
// System.out.println("444444444444444444444");
itemStack.addEnchantment(Enchantment.DAMAGE_ALL, 1);
}
}
break;
case MANIAC_MINER:
upgradeLevel = this.getLevelForUpgrade(upgrade);
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1000000, upgradeLevel));
break;
case FASTER_FORGE:
upgradeLevel = this.getLevelForUpgrade(upgrade);
int upgradeLevelFinal = upgradeLevel;
game.getActivatedGenerators().forEach(generator -> {
switch (upgradeLevelFinal) {
case 1:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.TWO);
}
break;
case 2:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.THREE);
}
break;
case 3:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.THREE);
} else {
generator.setActivated(true);
generator.setGeneratorTier(GeneratorTier.ONE);
}
break;
case 4:
if (generator.getGeneratorType() != GeneratorType.EMERALD) {
generator.setGeneratorTier(GeneratorTier.FOUR);
} else {
generator.setGeneratorTier(GeneratorTier.TWO);
}
break;
}
});
break;
}
}));
}
public ArmorType getArmorType(Player player) {
return this.armor.getOrDefault(player.getUniqueId(), ArmorType.LEATHER);
}
public void setArmorType(Player player, ArmorType armorType) {
this.armor.put(player.getUniqueId(), armorType);
this.giveTeamArmor(player, this);
}
public void giveTeamArmor(Player player, PlayerCurrentGameData playerCurrentGameData) {
Material leggingsMaterial;
Material bootsMaterial;
Map<Enchantment, Integer> protection = new HashMap<Enchantment, Integer>();
int level = playerCurrentGameData.getLevelForUpgrade(Upgrade.PROTECTION);
if (level != 0) {
protection.put(Enchantment.PROTECTION_ENVIRONMENTAL, level);
}
Game game = this.main.getGameManager().getGame(player.getUniqueId());
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
GameTeam gameTeam = game.getTeams().get(playerData.getTeamId());
player.getInventory().setHelmet((new ItemBuilder(Material.LEATHER_HELMET)).durability(gameTeam.getPlayerTeam().getColorData()).addEnchantments(protection).build());
player.getInventory().setChestplate((new ItemBuilder(Material.LEATHER_CHESTPLATE)).durability(gameTeam.getPlayerTeam().getColorData()).addEnchantments(protection).build());
ArmorType armorType = this.getArmorType(player);
if (armorType == ArmorType.LEATHER) {
player.getInventory().setLeggings((new ItemBuilder(Material.LEATHER_LEGGINGS)).durability(gameTeam.getPlayerTeam().getColorData()).addEnchantments(protection).build());
player.getInventory().setBoots((new ItemBuilder(Material.LEATHER_BOOTS)).durability(gameTeam.getPlayerTeam().getColorData()).addEnchantments(protection).build());
return;
}
switch (armorType) {
case CHAIN:
leggingsMaterial = Material.CHAINMAIL_LEGGINGS;
bootsMaterial = Material.CHAINMAIL_BOOTS;
break;
case IRON:
leggingsMaterial = Material.IRON_LEGGINGS;
bootsMaterial = Material.IRON_BOOTS;
break;
case DIAMOND:
leggingsMaterial = Material.DIAMOND_LEGGINGS;
bootsMaterial = Material.DIAMOND_BOOTS;
break;
default:
return;
}
player.getInventory().setLeggings((new ItemBuilder(leggingsMaterial)).durability(gameTeam.getPlayerTeam().getColorData()).addEnchantments(protection).build());
player.getInventory().setBoots((new ItemBuilder(bootsMaterial)).durability(gameTeam.getPlayerTeam().getColorData()).addEnchantments(protection).build());
}
}

View File

@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import org.github.paperspigot.Title;
@ -12,6 +14,8 @@ import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.game.GameTeam;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.PlayerState;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.utils.CC;
@AllArgsConstructor
@ -46,11 +50,20 @@ public class RespawnRunnable extends BukkitRunnable {
this.player.sendMessage(CC.translate("&aYou have respawned!"));
this.player.playSound(this.player.getLocation(), Sound.ORB_PICKUP, 10F, 1F);
this.player.getInventory().setArmorContents(this.plugin.getGameManager().getGameArmor(this.playerData, this.playerData.getPlayerTeam().getTeamUpgrades()));
// this.player.getInventory().setArmorContents(this.plugin.getGameManager().getGameArmor(this.playerData, this.playerData.getPlayerTeam().getTeamUpgrades()));
for (ItemStack stack : this.plugin.getGameManager().getGameItems(this.playerData.getCurrentGameData(), this.playerData.getPlayerTeam().getTeamUpgrades())) {
this.player.getInventory().addItem(stack);
}
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(this.player.getUniqueId());
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
playerCurrentGameData.giveTeamArmor(this.player, playerCurrentGameData);
if (playerCurrentGameData.getLevelForUpgrade(Upgrade.MANIAC_MINER) != 0) {
this.player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1000000, playerCurrentGameData.getLevelForUpgrade(Upgrade.MANIAC_MINER)));
}
this.game.getTeams().forEach(team -> team.playingPlayers().filter(player1 -> !this.player.equals(player1))
.forEach(matchplayer -> matchplayer.sendMessage(CC.translate(this.gameTeam.getPlayerTeam().getChatColor() + this.player.getName() + " &ehas respawned!"))));

View File

@ -0,0 +1,156 @@
package rip.tilly.bedwars.upgrades;
public enum Upgrade {
SHARPENED_SWORDS,
PROTECTION,
MANIAC_MINER,
FASTER_FORGE,
HEAL_POOL,
DRAGON_BUFF,
TRAP;
public int getHighestLevel() {
switch (this) {
case SHARPENED_SWORDS:
case HEAL_POOL:
case DRAGON_BUFF:
case TRAP:
return 1;
case PROTECTION:
case FASTER_FORGE:
return 4;
case MANIAC_MINER:
return 2;
}
return -1;
}
public int getCostForLevel(int level) {
if (this.getHighestLevel() < level) {
return -1;
}
switch (this) {
case SHARPENED_SWORDS:
return 4;
case PROTECTION:
if (level == 1) {
return 2;
}
if (level == 2) {
return 4;
}
if (level == 3) {
return 8;
}
return 16;
case MANIAC_MINER:
if (level == 1) {
return 2;
}
return 4;
case FASTER_FORGE:
if (level == 1) {
return 2;
}
if (level == 2) {
return 4;
}
if (level == 3) {
return 6;
}
return 8;
case HEAL_POOL:
case DRAGON_BUFF:
case TRAP:
return 1;
}
return -1;
}
public String getPerkForLevel(int level) {
switch (this) {
case SHARPENED_SWORDS:
case DRAGON_BUFF:
case TRAP:
return null;
case PROTECTION:
return "Protection " + this.getNumberToRomanNumeral(level);
case MANIAC_MINER:
return "Haste " + this.getNumberToRomanNumeral(level);
case FASTER_FORGE:
if (level == 1) {
return "+50% Resources";
}
if (level == 2) {
return "+100% Resources";
}
if (level == 3) {
return "Spawn Emeralds";
}
return "+200% Resources";
case HEAL_POOL:
return "Regeneration " + this.getNumberToRomanNumeral(level);
}
return null;
}
public String getNumberToRomanNumeral(int number) {
StringBuilder stringBuilder = new StringBuilder();
int times = 0;
String[] romans = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
int[] ints = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
for (int i = ints.length - 1; i >= 0; i--) {
times = number / ints[i];
number %= ints[i];
while (times > 0) {
stringBuilder.append(romans[i]);
times--;
}
}
return stringBuilder.toString();
}
public String getFormattedName() {
switch (this) {
case SHARPENED_SWORDS:
return "Sharpened Swords";
case PROTECTION:
return "Protection";
case MANIAC_MINER:
return "Maniac Miner";
case FASTER_FORGE:
return "Faster Forge";
case HEAL_POOL:
return "Heal Pool";
case DRAGON_BUFF:
return "Dragon Buff";
case TRAP:
return "Trap";
}
return "";
}
}

View File

@ -0,0 +1,119 @@
package rip.tilly.bedwars.upgrades;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.stream.Collectors;
public class UpgradeItem {
private String name;
private String[] lore;
private Material material;
private Upgrade upgrade;
public UpgradeItem(String name, String[] lore, Material material, Upgrade upgrade) {
this.name = name;
this.lore = lore;
this.material = material;
this.upgrade = upgrade;
}
public ItemStack getItemStack(Player player, PlayerCurrentGameData playerCurrentGameData) {
int level = playerCurrentGameData.getLevelForUpgrade(this.upgrade);
ItemBuilder itemBuilder = new ItemBuilder(this.material, Math.min(level + 1, this.upgrade.getHighestLevel()));
itemBuilder.name(CC.translate("&e" + this.name + " " + this.upgrade.getNumberToRomanNumeral(Math.min(level + 1, this.upgrade.getHighestLevel()))));
List<String> lore = Arrays.stream(this.lore).map(line -> "&7" + line).collect(Collectors.toList());
lore.add(CC.translate(""));
if (this.upgrade.getHighestLevel() == 1) {
lore.add(CC.translate("&7Cost: &b" + this.upgrade.getCostForLevel(1) + " Diamond" + (this.upgrade.getCostForLevel(1) == 1 ? "" : "s")));
} else {
for (int i = 0; i < this.upgrade.getHighestLevel(); i++) {
int amount = i + 1;
String string = this.upgrade.getCostForLevel(amount) + " Diamond" + (this.upgrade.getCostForLevel(amount) == 1 ? "" : "s");
lore.add(CC.translate((level < amount ? "&7" : "&a") + "Tier " + amount + ": " + this.upgrade.getPerkForLevel(amount) + ", &b" + string));
}
}
lore.add(CC.translate(""));
if (playerCurrentGameData.getCostToUpgrade(this.upgrade) != -1) {
if (this.canBuy(player, level + 1)) {
lore.add(CC.translate("&aClick to purchase"));
} else {
lore.add(CC.translate("&cNot enough diamonds"));
}
} else {
lore.add(CC.translate("&aUnlocked"));
}
itemBuilder = itemBuilder.lore(lore);
return itemBuilder.build();
}
public void buy(Player player, int level, Game game, PlayerCurrentGameData playerCurrentGameData) {
if (!this.canBuy(player, level)) {
return;
}
int price = this.upgrade.getCostForLevel(level);
int removed = 0;
for (ListIterator<ItemStack> listIterator = player.getInventory().iterator(); listIterator.hasNext();) {
ItemStack itemStack = listIterator.next();
if (itemStack != null && itemStack.getType() == Material.DIAMOND) {
if (itemStack.getAmount() >= price) {
removed += itemStack.getAmount() - price;
itemStack.setAmount(itemStack.getAmount() - price);
} else {
removed += itemStack.getAmount();
itemStack.setAmount(0);
}
if (price <= removed) {
break;
}
}
}
playerCurrentGameData.upgrade(player, game, this.upgrade);
}
public boolean canBuy(Player player, int level) {
int amount = 0;
for (ListIterator<ItemStack> listIterator = player.getInventory().iterator(); listIterator.hasNext();) {
ItemStack itemStack = listIterator.next();
if (itemStack != null && itemStack.getType() == Material.DIAMOND) {
amount += itemStack.getAmount();
}
}
return amount >= this.upgrade.getCostForLevel(level);
}
public Upgrade getUpgrade() {
return this.upgrade;
}
}

View File

@ -18,6 +18,7 @@ import org.bukkit.material.MaterialData;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class ItemBuilder implements Listener {
@ -32,6 +33,10 @@ public class ItemBuilder implements Listener {
this.is = is;
}
public ItemBuilder(Material m, int amount) {
this.is = new ItemStack(m, amount);
}
public ItemBuilder amount(final int amount) {
is.setAmount(amount);
@ -192,6 +197,11 @@ public class ItemBuilder implements Listener {
}
}
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments) {
this.is.addEnchantments(enchantments);
return this;
}
public ItemStack build() {
return is;
}

View File

@ -2,6 +2,7 @@ package rip.tilly.bedwars.utils.menusystem;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
@ -27,12 +28,12 @@ public abstract class Menu implements InventoryHolder {
public abstract void handleMenu(InventoryClickEvent event);
public abstract void setMenuItems();
public abstract void setMenuItems(Player player);
public void open() {
public void open(Player player) {
inventory = Bukkit.createInventory(this, getSlots(), getMenuName());
this.setMenuItems();
this.setMenuItems(player);
playerMenuUtil.getOwner().openInventory(inventory);
}

View File

@ -0,0 +1,100 @@
package rip.tilly.bedwars.utils.menusystem.menu;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.Game;
import rip.tilly.bedwars.playerdata.PlayerData;
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
import rip.tilly.bedwars.upgrades.Upgrade;
import rip.tilly.bedwars.upgrades.UpgradeItem;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.menusystem.Menu;
import rip.tilly.bedwars.utils.menusystem.PlayerMenuUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class UpgradesMenu extends Menu {
private BedWars main = BedWars.getInstance();
List<UpgradeItem> upgradeItems = new ArrayList<UpgradeItem>();
public UpgradesMenu(PlayerMenuUtil playerMenuUtil) {
super(playerMenuUtil);
this.upgradeItems.add(new UpgradeItem("Sharpened Swords", new String[]{"Your team permanently gains", "sharpness one on all swords"}, Material.IRON_SWORD, Upgrade.SHARPENED_SWORDS));
this.upgradeItems.add(new UpgradeItem("Reinforced Armor", new String[]{"Your team permanently gets", "protection one all all armor"}, Material.IRON_CHESTPLATE, Upgrade.PROTECTION));
this.upgradeItems.add(new UpgradeItem("Maniac Miner", new String[]{"Your team will permanently get haste"}, Material.GOLD_PICKAXE, Upgrade.MANIAC_MINER));
this.upgradeItems.add(new UpgradeItem("Faster Forge", new String[]{"Increase your team's generator speed"}, Material.FURNACE, Upgrade.FASTER_FORGE));
this.upgradeItems.add(new UpgradeItem("Heal Pool", new String[]{"Your team permanently gains", "Sharpness 1 on all swords"}, Material.BEACON, Upgrade.HEAL_POOL));
this.upgradeItems.add(new UpgradeItem("Dragon Buff", new String[]{"Your team permanently gains", "Sharpness 1 on all swords"}, Material.DRAGON_EGG, Upgrade.DRAGON_BUFF));
this.upgradeItems.add(new UpgradeItem("Trap", new String[]{"Get an alert when players", "come to your base"}, Material.TRIPWIRE_HOOK, Upgrade.TRAP));
}
@Override
public String getMenuName() {
return CC.translate("&eUpgrades Menu");
}
@Override
public int getSlots() {
return 27;
}
@Override
public void handleMenu(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
Game game = this.main.getGameManager().getGameFromUUID(player.getUniqueId());
if (event.getView().getTitle().equalsIgnoreCase(CC.translate("&eUpgrades Menu"))) {
for (UpgradeItem upgradeItem : this.upgradeItems) {
if (upgradeItem.getItemStack(player, playerCurrentGameData).getItemMeta().getDisplayName().equalsIgnoreCase(event.getCurrentItem().getItemMeta().getDisplayName())) {
if (playerCurrentGameData.getCostToUpgrade(upgradeItem.getUpgrade()) == -1) {
player.sendMessage(CC.translate("&cYour team already has the highest upgrade for &c&l" + upgradeItem.getUpgrade().getFormattedName()));
return;
}
if (upgradeItem.canBuy(player, playerCurrentGameData.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1)) {
upgradeItem.buy(player, playerCurrentGameData.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1, game, playerCurrentGameData);
player.updateInventory();
break;
}
player.sendMessage(CC.translate("&cYou do not have enough diamonds for &c&l" + upgradeItem.getUpgrade().getFormattedName() + " " + upgradeItem.getUpgrade().getNumberToRomanNumeral(playerCurrentGameData.getLevelForUpgrade(upgradeItem.getUpgrade()) + 1)));
break;
}
}
}
}
@Override
public void setMenuItems(Player player) {
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
for (int i = 0; i < this.inventory.getSize(); i++) {
this.inventory.setItem(i, this.FILLER_GLASS);
}
AtomicInteger atomicInteger = new AtomicInteger(10);
this.upgradeItems.forEach(itemStack -> {
this.inventory.setItem(atomicInteger.get(), itemStack.getItemStack(player, playerCurrentGameData));
atomicInteger.addAndGet(1);
});
}
}