From 03b61cc2ad8eb3f09263dd423385182649698014 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 26 Nov 2021 20:03:54 +0100 Subject: [PATCH] im tired --- .../java/rip/tilly/bedwars/game/Game.java | 4 +- .../tilly/bedwars/generators/Generator.java | 2 +- .../listeners/game/GameStartListener.java | 2 +- .../tilly/bedwars/managers/GameManager.java | 12 +- .../bedwars/menus/shop/ShopTypeButton.java | 2 + .../bedwars/menus/shop/armor/ArmorButton.java | 135 ++++++++++++++++++ .../bedwars/menus/shop/armor/ArmorMenu.java | 52 +++++++ .../menus/shop/tools/ShearsButton.java | 103 +++++++++++++ .../bedwars/menus/shop/tools/ToolsMenu.java | 6 + .../playerdata/currentgame/TeamUpgrades.java | 4 +- .../bedwars/runnables/RespawnRunnable.java | 17 +-- .../rip/tilly/bedwars/upgrades/AxeTier.java | 21 +++ 12 files changed, 335 insertions(+), 25 deletions(-) create mode 100644 src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorButton.java create mode 100644 src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorMenu.java create mode 100644 src/main/java/rip/tilly/bedwars/menus/shop/tools/ShearsButton.java create mode 100644 src/main/java/rip/tilly/bedwars/menus/shop/tools/ToolsMenu.java create mode 100644 src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java diff --git a/src/main/java/rip/tilly/bedwars/game/Game.java b/src/main/java/rip/tilly/bedwars/game/Game.java index b21ffdb..143a1d5 100644 --- a/src/main/java/rip/tilly/bedwars/game/Game.java +++ b/src/main/java/rip/tilly/bedwars/game/Game.java @@ -300,11 +300,11 @@ public class Game { int minutesLeft = difference % 3600 / 60; int secondsLeft = difference % 60; - return entry.getValue() + "&7: &d" + String.format("%02d:%02d", minutesLeft, secondsLeft); + return entry.getValue() + ": &d" + String.format("%02d:%02d", minutesLeft, secondsLeft); } } - return null; + return "&cNone"; } public double secondsToMinutes(int seconds) { diff --git a/src/main/java/rip/tilly/bedwars/generators/Generator.java b/src/main/java/rip/tilly/bedwars/generators/Generator.java index 23a078a..91752ce 100644 --- a/src/main/java/rip/tilly/bedwars/generators/Generator.java +++ b/src/main/java/rip/tilly/bedwars/generators/Generator.java @@ -157,7 +157,7 @@ public class Generator { this.generatorTierArmorStand.setCustomName(CC.translate(this.getArmorStandName())); if (this.main != null) { - this.rotateIndicatorTask = this.main.getServer().getScheduler().runTaskTimer(this.main, () -> { + this.rotateIndicatorTask = this.main.getServer().getScheduler().runTaskTimerAsynchronously(this.main, () -> { EulerAngle eulerAngle = this.indictatorArmorStand.getHeadPose(); if (eulerAngle.getY() > 360D) { diff --git a/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java b/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java index c6209d9..589e037 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/game/GameStartListener.java @@ -86,7 +86,7 @@ public class GameStartListener implements Listener { player.teleport(team.getId() == 1 ? locationA.toBukkitLocation() : locationB.toBukkitLocation()); - player.getInventory().setArmorContents(this.plugin.getGameManager().getGameArmor(playerData)); + player.getInventory().setArmorContents(this.plugin.getGameManager().getGameStartArmor(playerData)); for (ItemStack stack : this.plugin.getGameManager().getGameItems(playerData.getCurrentGameData(), playerData.getPlayerTeam().getTeamUpgrades())) { player.getInventory().addItem(stack); } diff --git a/src/main/java/rip/tilly/bedwars/managers/GameManager.java b/src/main/java/rip/tilly/bedwars/managers/GameManager.java index 439524f..ab44b79 100644 --- a/src/main/java/rip/tilly/bedwars/managers/GameManager.java +++ b/src/main/java/rip/tilly/bedwars/managers/GameManager.java @@ -19,6 +19,7 @@ import rip.tilly.bedwars.playerdata.PlayerData; import rip.tilly.bedwars.playerdata.PlayerState; import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData; import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades; +import rip.tilly.bedwars.upgrades.Upgrade; import rip.tilly.bedwars.utils.ItemBuilder; import rip.tilly.bedwars.utils.PlayerUtil; import rip.tilly.bedwars.utils.TtlHashMap; @@ -215,8 +216,11 @@ public class GameManager { public List getGameItems(PlayerCurrentGameData currentGameData, TeamUpgrades teamUpgrades) { List allItems = new ArrayList<>(); - ItemStack sword = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable().build(); - allItems.add(sword); + ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable(); + if (teamUpgrades.getLevelForUpgrade(Upgrade.SHARPENED_SWORDS) == 1) { + sword.enchantment(Enchantment.DAMAGE_ALL, 1); + } + allItems.add(sword.build()); if (currentGameData.isShears()) { ItemStack shears = new ItemBuilder(Material.SHEARS).addUnbreakable().build(); @@ -239,7 +243,6 @@ public class GameManager { axe = new ItemBuilder(Material.DIAMOND_AXE).enchantment(Enchantment.DIG_SPEED, 3).addUnbreakable().build(); break; default: - axe = null; break; } } @@ -263,7 +266,6 @@ public class GameManager { pickaxe = new ItemBuilder(Material.DIAMOND_PICKAXE).enchantment(Enchantment.DIG_SPEED, 3).addUnbreakable().build(); break; default: - pickaxe = null; break; } } @@ -274,7 +276,7 @@ public class GameManager { return allItems; } - public ItemStack[] getGameArmor(PlayerData playerData) { + public ItemStack[] getGameStartArmor(PlayerData playerData) { Color color = playerData.getPlayerTeam().getColor(); ItemStack leatherBoots = new ItemBuilder(Material.LEATHER_BOOTS).color(color).addUnbreakable().build(); diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java b/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java index f7a3bb7..9e5cb32 100644 --- a/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java +++ b/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.menus.shop.armor.ArmorMenu; import rip.tilly.bedwars.menus.shop.blocks.BlocksMenu; import rip.tilly.bedwars.utils.ItemBuilder; import rip.tilly.bedwars.utils.menu.Button; @@ -40,6 +41,7 @@ public class ShopTypeButton extends Button { new BlocksMenu().openMenu(player); break; case ARMOR: + new ArmorMenu().openMenu(player); break; case TOOLS: break; diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorButton.java b/src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorButton.java new file mode 100644 index 0000000..6c8cc3f --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorButton.java @@ -0,0 +1,135 @@ +package rip.tilly.bedwars.menus.shop.armor; + +import lombok.AllArgsConstructor; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.playerdata.PlayerData; +import rip.tilly.bedwars.playerdata.currentgame.ArmorType; +import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.PlayerUtil; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +public class ArmorButton extends Button { + + private final String name; + private final Material material; + private final Material costType; + private final String costTypeName; + private final ChatColor costTypeColor; + private final int cost; + private final ArmorType armorType; + + @Override + public ItemStack getButtonItem(Player player) { + List loreList = new ArrayList<>(); + + PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades(); + + loreList.add(" "); + loreList.add("&7&oYou will keep this armor"); + loreList.add("&7&oupon death."); + loreList.add(" "); + if (teamUpgrades.getArmorType(player) == armorType) { + loreList.add("&cYou already own this!"); + } else if (teamUpgrades.getArmorType(player) == ArmorType.DIAMOND) { + loreList.add("&cYou have the highest tier of armor!"); + } else if (teamUpgrades.getArmorType(player) == ArmorType.IRON && armorType == ArmorType.CHAIN) { + loreList.add("&cYou already have a higher tier of armor!"); + } else { + loreList.add("&9Cost: " + costTypeColor + cost + " " + costTypeName); + } + + int costItems = 0; + for (ItemStack contents : player.getInventory().getContents()) { + if (contents != null) { + if (contents.getType() == costType) { + costItems += contents.getAmount(); + } + } + } + + loreList.add(" "); + loreList.add(costItems >= cost ? "&aClick to purchase!" : "&cYou don't have enough " + costTypeName + "!"); + + return new ItemBuilder(material) + .name((costItems >= cost ? "&a" : "&c") + name) + .lore(loreList) + .hideFlags() + .build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + if (clickType.isShiftClick()) { + return; + } + + PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades(); + if (teamUpgrades.getArmorType(player) == armorType) { + player.sendMessage(CC.translate("&cYou already own this armor!")); + playFail(player); + return; + } + + if (teamUpgrades.getArmorType(player) == ArmorType.DIAMOND) { + player.sendMessage(CC.translate("&cYou have the highest tier of armor!")); + playFail(player); + return; + } + + if (teamUpgrades.getArmorType(player) == ArmorType.IRON && armorType == ArmorType.CHAIN) { + player.sendMessage(CC.translate("&cYou already have a higher tier of armor!")); + playFail(player); + return; + } + + int costItems = 0; + for (ItemStack contents : player.getInventory().getContents()) { + if (contents != null) { + if (contents.getType() == costType) { + costItems += contents.getAmount(); + } + } + } + + if (costItems < cost) { + player.sendMessage(CC.translate("&cYou don't have enough " + costTypeName + "!")); + playFail(player); + return; + } + + int finalCost = cost; + for (ItemStack i : player.getInventory().getContents()) { + if (i == null) { + continue; + } + if (i.getType() == costType) { + if (i.getAmount() < finalCost) { + finalCost -= i.getAmount(); + PlayerUtil.minusAmount(player, i, i.getAmount()); + player.updateInventory(); + } else { + PlayerUtil.minusAmount(player, i, finalCost); + player.updateInventory(); + break; + } + } + } + + teamUpgrades.setArmorType(player, armorType); + + playNeutral(player); + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorMenu.java b/src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorMenu.java new file mode 100644 index 0000000..3533a97 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/armor/ArmorMenu.java @@ -0,0 +1,52 @@ +package rip.tilly.bedwars.menus.shop.armor; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.menus.shop.ShopType; +import rip.tilly.bedwars.menus.shop.ShopTypeButton; +import rip.tilly.bedwars.playerdata.currentgame.ArmorType; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.Menu; + +import java.util.HashMap; +import java.util.Map; + +public class ArmorMenu extends Menu { + + @Override + public boolean isUpdateAfterClick() { + return true; + } + + @Override + public String getTitle(Player player) { + return CC.translate("&eClick armor to purchase..."); + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap<>(); + + for (ShopType types : ShopType.values()) { + buttons.put(types.getSlot(), new ShopTypeButton(types)); + } + + buttons.put(ShopType.ARMOR.getSlot() + 9, Button.placeholder(Material.STAINED_GLASS_PANE, (byte) 5, " ")); + + buttons.put(19, new ArmorButton("Permanent Chain Armor", Material.CHAINMAIL_BOOTS, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 40, ArmorType.CHAIN)); + buttons.put(20, new ArmorButton("Permanent Iron Armor", Material.IRON_BOOTS, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 12, ArmorType.IRON)); + buttons.put(21, new ArmorButton("Permanent Diamond Armor", Material.DIAMOND_BOOTS, Material.EMERALD, "Emeralds", ChatColor.DARK_GREEN, 6, ArmorType.DIAMOND)); + + fillEmptySlots(buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(7).name(" ").build()); + + return buttons; + } + + @Override + public int getSize() { + return 6 * 9; + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/tools/ShearsButton.java b/src/main/java/rip/tilly/bedwars/menus/shop/tools/ShearsButton.java new file mode 100644 index 0000000..f3b4c9b --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/tools/ShearsButton.java @@ -0,0 +1,103 @@ +package rip.tilly.bedwars.menus.shop.tools; + +import lombok.AllArgsConstructor; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.PlayerUtil; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +public class ShearsButton extends Button { + + private final String name; + private final Material material; + private final Material costType; + private final String costTypeName; + private final ChatColor costTypeColor; + private final int cost; + private final PlayerCurrentGameData currentGameData; + + @Override + public ItemStack getButtonItem(Player player) { + List loreList = new ArrayList<>(); + + loreList.add(" "); + if (currentGameData.isShears()) { + loreList.add("&cYou already have shears!"); + } else { + loreList.add("&9Cost: " + costTypeColor + cost + " " + costTypeName); + } + + int costItems = 0; + for (ItemStack contents : player.getInventory().getContents()) { + if (contents != null) { + if (contents.getType() == costType) { + costItems += contents.getAmount(); + } + } + } + + loreList.add(" "); + loreList.add(costItems >= cost ? "&aClick to purchase!" : "&cYou don't have enough " + costTypeName + "!"); + + return new ItemBuilder(material) + .name((costItems >= cost ? "&a" : "&c") + name) + .lore(loreList) + .hideFlags() + .build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + if (clickType.isShiftClick()) { + return; + } + + int costItems = 0; + for (ItemStack contents : player.getInventory().getContents()) { + if (contents != null) { + if (contents.getType() == costType) { + costItems += contents.getAmount(); + } + } + } + + if (costItems < cost) { + player.sendMessage(CC.translate("&cYou don't have enough " + costTypeName + "!")); + playFail(player); + return; + } + + int finalCost = cost; + for (ItemStack i : player.getInventory().getContents()) { + if (i == null) { + continue; + } + if (i.getType() == costType) { + if (i.getAmount() < finalCost) { + finalCost -= i.getAmount(); + PlayerUtil.minusAmount(player, i, i.getAmount()); + player.updateInventory(); + } else { + PlayerUtil.minusAmount(player, i, finalCost); + player.updateInventory(); + break; + } + } + } + + player.getInventory().addItem(new ItemBuilder(material) + .addUnbreakable() + .hideFlags() + .build()); + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/tools/ToolsMenu.java b/src/main/java/rip/tilly/bedwars/menus/shop/tools/ToolsMenu.java new file mode 100644 index 0000000..fd799bc --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/tools/ToolsMenu.java @@ -0,0 +1,6 @@ +package rip.tilly.bedwars.menus.shop.tools; + +import rip.tilly.bedwars.utils.menu.Menu; + +public class ToolsMenu extends Menu { +} diff --git a/src/main/java/rip/tilly/bedwars/playerdata/currentgame/TeamUpgrades.java b/src/main/java/rip/tilly/bedwars/playerdata/currentgame/TeamUpgrades.java index 1bc433b..e778e08 100644 --- a/src/main/java/rip/tilly/bedwars/playerdata/currentgame/TeamUpgrades.java +++ b/src/main/java/rip/tilly/bedwars/playerdata/currentgame/TeamUpgrades.java @@ -171,7 +171,7 @@ public class TeamUpgrades { return; } - player.getInventory().setLeggings((new ItemBuilder(leggingsMaterial)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build()); - player.getInventory().setBoots((new ItemBuilder(bootsMaterial)).color(gameTeam.getPlayerTeam().getColor()).addEnchantments(protection).addUnbreakable().build()); + player.getInventory().setLeggings((new ItemBuilder(leggingsMaterial)).addEnchantments(protection).addUnbreakable().build()); + player.getInventory().setBoots((new ItemBuilder(bootsMaterial)).addEnchantments(protection).addUnbreakable().build()); } } diff --git a/src/main/java/rip/tilly/bedwars/runnables/RespawnRunnable.java b/src/main/java/rip/tilly/bedwars/runnables/RespawnRunnable.java index 6f53b46..f4abe1c 100644 --- a/src/main/java/rip/tilly/bedwars/runnables/RespawnRunnable.java +++ b/src/main/java/rip/tilly/bedwars/runnables/RespawnRunnable.java @@ -1,10 +1,9 @@ package rip.tilly.bedwars.runnables; import lombok.AllArgsConstructor; -import org.bukkit.Material; import org.bukkit.Sound; -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 org.bukkit.scheduler.BukkitRunnable; @@ -18,7 +17,6 @@ import rip.tilly.bedwars.playerdata.PlayerState; import rip.tilly.bedwars.playerdata.currentgame.TeamUpgrades; import rip.tilly.bedwars.upgrades.Upgrade; import rip.tilly.bedwars.utils.CC; -import rip.tilly.bedwars.utils.ItemBuilder; @AllArgsConstructor public class RespawnRunnable extends BukkitRunnable { @@ -52,28 +50,19 @@ 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())); -// 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()); TeamUpgrades teamUpgrades = playerData.getPlayerTeam().getTeamUpgrades(); teamUpgrades.giveTeamArmor(this.player); - ItemBuilder itemBuilder = new ItemBuilder(Material.WOOD_SWORD).addUnbreakable(); - - if (teamUpgrades.getLevelForUpgrade(Upgrade.SHARPENED_SWORDS) == 1) { - itemBuilder.enchantment(Enchantment.DAMAGE_ALL, 1); + for (ItemStack stack : this.plugin.getGameManager().getGameItems(this.playerData.getCurrentGameData(), teamUpgrades)) { + this.player.getInventory().addItem(stack); } if (teamUpgrades.getLevelForUpgrade(Upgrade.MANIAC_MINER) != 0) { this.player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1000000, teamUpgrades.getLevelForUpgrade(Upgrade.MANIAC_MINER))); } - player.getInventory().addItem(itemBuilder.build()); - 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!")))); diff --git a/src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java b/src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java new file mode 100644 index 0000000..208e0a4 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java @@ -0,0 +1,21 @@ +package rip.tilly.bedwars.upgrades; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.utils.ItemBuilder; + +@Getter +@RequiredArgsConstructor +public enum AxeTier { + + NONE(0, Material.AIR, null, 0), + WOOD(10, Material.IRON_INGOT, new ItemBuilder(Material.WOOD_AXE).enchantment(Enchantment.DIG_SPEED, 1).name(), 1) + + private final int cost; + private final Material costType; + private final ItemStack item; + private final int level; +}