diff --git a/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java b/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java index 88bb071..9e5f840 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java @@ -13,6 +13,7 @@ import rip.tilly.bedwars.BedWars; import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem; import rip.tilly.bedwars.menus.queue.PlayAGameMenu; import rip.tilly.bedwars.menus.settings.SettingsMenu; +import rip.tilly.bedwars.menus.shop.blocks.BlocksMenu; import rip.tilly.bedwars.playerdata.PlayerData; import rip.tilly.bedwars.playerdata.PlayerState; @@ -88,6 +89,7 @@ public class InteractListener implements Listener { break; case COSMETICS_MENU: + new BlocksMenu().openMenu(player); // open cosmetics menu break; case PREFERENCES_MENU: diff --git a/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java b/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java index 892309b..07960c1 100644 --- a/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java +++ b/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java @@ -58,7 +58,7 @@ public class ArenaManager { String teamAshop = section.getString(name + ".teamAshop"); String teamBshop = section.getString(name + ".teamBshop"); String teamAupgrades = section.getString(name + ".teamAupgrades"); - String teamBupgrades = section.getString(name + ".teamAupgrades"); + String teamBupgrades = section.getString(name + ".teamBupgrades"); CustomLocation spawnA = CustomLocation.stringToLocation(a); CustomLocation spawnB = CustomLocation.stringToLocation(b); @@ -109,7 +109,7 @@ public class ArenaManager { String copyTeamAshop = section.getString(copy + ".teamAshop"); String copyTeamBshop = section.getString(copy + ".teamBshop"); String copyTeamAupgrades = section.getString(copy + ".teamAupgrades"); - String copyTeamBupgrades = section.getString(copy + ".teamAupgrades"); + String copyTeamBupgrades = section.getString(copy + ".teamBupgrades"); CustomLocation copySpawnA = CustomLocation.stringToLocation(copyA); CustomLocation copySpawnB = CustomLocation.stringToLocation(copyB); @@ -220,6 +220,11 @@ public class ArenaManager { int deadZone = arena.getDeadZone(); int buildMax = arena.getBuildMax(); + String teamAshop = CustomLocation.locationToString(arena.getTeamAshop()); + String teamBshop = CustomLocation.locationToString(arena.getTeamBshop()); + String teamAupgrades = CustomLocation.locationToString(arena.getTeamAupgrades()); + String teamBupgrades = CustomLocation.locationToString(arena.getTeamBupgrades()); + String root = "arenas." + name; fileConfig.set(root + ".icon", icon); @@ -241,6 +246,11 @@ public class ArenaManager { fileConfig.set(root + ".diamond-generators", this.fromLocations(arena.getDiamondGenerators())); fileConfig.set(root + ".emerald-generators", this.fromLocations(arena.getEmeraldGenerators())); + fileConfig.set(root + ".teamAshop", teamAshop); + fileConfig.set(root + ".teamBshop", teamBshop); + fileConfig.set(root + ".teamAupgrades", teamAupgrades); + fileConfig.set(root + ".teamBupgrades", teamBupgrades); + fileConfig.set(root + ".enabled", arena.isEnabled()); fileConfig.set(root + ".copiedArenas", null); @@ -256,6 +266,11 @@ public class ArenaManager { String copyTeamBmin = CustomLocation.locationToString(copiedArena.getTeamBmin()); String copyTeamBmax = CustomLocation.locationToString(copiedArena.getTeamBmax()); + String copyTeamAshop = CustomLocation.locationToString(copiedArena.getTeamAshop()); + String copyTeamBshop = CustomLocation.locationToString(copiedArena.getTeamBshop()); + String copyTeamAupgrades = CustomLocation.locationToString(copiedArena.getTeamAupgrades()); + String copyTeamBupgrades = CustomLocation.locationToString(copiedArena.getTeamBupgrades()); + String copyRoot = root + ".copiedArenas." + i; fileConfig.set(copyRoot + ".a", copyA); @@ -271,6 +286,11 @@ public class ArenaManager { fileConfig.set(copyRoot + ".diamond-generators", this.fromLocations(copiedArena.getDiamondGenerators())); fileConfig.set(copyRoot + ".emerald-generators", this.fromLocations(copiedArena.getEmeraldGenerators())); + fileConfig.set(copyRoot + ".teamAshop", copyTeamAshop); + fileConfig.set(copyRoot + ".teamBshop", copyTeamBshop); + fileConfig.set(copyRoot + ".teamAupgrades", copyTeamAupgrades); + fileConfig.set(copyRoot + ".teamBupgrades", copyTeamBupgrades); + i++; } } diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java b/src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java index 82a2e93..961e1b1 100644 --- a/src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java +++ b/src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java @@ -1,6 +1,7 @@ package rip.tilly.bedwars.menus.shop; import lombok.AllArgsConstructor; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -18,54 +19,69 @@ import java.util.List; public class ShopButton extends Button { private final String name; - private final List lore; private final Material material; private final int data; private final int amount; private final Material costType; private final String costTypeName; + private final ChatColor costTypeColor; private final int cost; private final boolean color; - private final int costItems; @Override public ItemStack getButtonItem(Player player) { List loreList = new ArrayList<>(); loreList.add(" "); - loreList.addAll(lore); + loreList.add("&9Cost: " + costTypeColor + cost + " " + costTypeName); + loreList.add("&9Amount: &e" + amount + "x"); -// int costItems = 0; -// for (ItemStack contents : player.getInventory().getContents()) { -// if (contents != null) { -// if (contents.getType() == costType) { -// costItems += contents.getAmount(); -// } -// } -// } + 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 + "!"); PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); if (color) { - return new ItemBuilder(material).name(name).lore(loreList).amount(amount).durability(playerData.getPlayerTeam().getColorData()).hideFlags().build(); + return new ItemBuilder(material) + .name((costItems >= cost ? "&a" : "&c") + name) + .lore(loreList) + .amount(amount) + .durability(playerData.getPlayerTeam().getColorData()) + .hideFlags() + .build(); } else { - return new ItemBuilder(material).name(name).lore(loreList).amount(amount).durability(data).hideFlags().build(); + return new ItemBuilder(material) + .name((costItems >= cost ? "&a" : "&c") + name) + .lore(loreList) + .amount(amount) + .durability(data) + .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(); -// } -// } -// } + int costItems = 0; + for (ItemStack contents : player.getInventory().getContents()) { + if (contents != null) { + if (contents.getType() == costType) { + costItems += contents.getAmount(); + } + } + } PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); if (costItems >= cost) { @@ -81,9 +97,17 @@ public class ShopButton extends Button { } } if (color) { - player.getInventory().addItem(new ItemBuilder(material).amount(amount).durability(playerData.getPlayerTeam().getColorData()).hideFlags().build()); + player.getInventory().addItem(new ItemBuilder(material) + .amount(amount) + .durability(playerData.getPlayerTeam().getColorData()) + .hideFlags() + .build()); } else { - player.getInventory().addItem(new ItemBuilder(material).amount(amount).durability(data).hideFlags().build()); + player.getInventory().addItem(new ItemBuilder(material) + .amount(amount) + .durability(data) + .hideFlags() + .build()); } playNeutral(player); } else { diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java b/src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java index 27644df..2a63211 100644 --- a/src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java +++ b/src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java @@ -1,21 +1,82 @@ package rip.tilly.bedwars.menus.shop; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.bukkit.Material; +import java.util.Arrays; +import java.util.List; + +@Getter @RequiredArgsConstructor public enum ShopType { - QUICK("Quick Buy", Material.NETHER_STAR, 0), - BLOCKS("Blocks", Material.STAINED_CLAY, 0), - ARMOR("Armor", Material.LEATHER_CHESTPLATE, 0), - TOOLS("Tools", Material.STONE_PICKAXE, 0), - WEAPONS("Weapons", Material.GOLD_SWORD, 0), - RANGED("Ranged", Material.BOW, 0), - POTIONS("Potions", Material.POTION, 0), - UTILITY("Utility", Material.EGG, 0); + QUICK("Quick Buy", Arrays.asList( + " ", + "&9Handy to buy things quickly!", + " " + ), Material.NETHER_STAR, 0, 0), + + BLOCKS("Blocks", Arrays.asList( + " ", + "&9Buy yourself some blocks to", + "&9defend your bed and get to", + "&9your enemies!", + " " + ), Material.STAINED_CLAY, 0, 2), + + ARMOR("Armor", Arrays.asList( + " ", + "&9Protect yourself with armor", + "&9that stays after death!", + " " + ), Material.LEATHER_CHESTPLATE, 0, 3), + + TOOLS("Tools", Arrays.asList( + " ", + "&9Break the blocks of your enemies", + "&9quicker and faster with tools!", + " " + ), Material.STONE_PICKAXE, 0, 4), + + WEAPONS("Weapons", Arrays.asList( + " ", + "&9Make killing enemies easier", + "&9and quicker with stronger", + "&9weapons!", + " " + ), Material.GOLD_SWORD, 0, 5), + + RANGED("Ranged", Arrays.asList( + " ", + "&9Don't like close quarter", + "&9combat? Then the ranged", + "&9weapons are for you!", + " " + ), Material.BOW, 0, 6), + + POTIONS("Potions", Arrays.asList( + " ", + "&9Sneak up on your enemies", + "&9with special brewed potions!", + " " + ), Material.POTION, 0, 7), + + UTILITY("Utility", Arrays.asList( + " ", + "&9Need extra utilities to destroy", + "&9your enemies? Then the utilities", + "&9are for you!", + " " + ), Material.EGG, 0, 8); private final String name; + private final List lore; private final Material material; private final int data; + private final int slot; + + public static ShopType getByName(String name) { + return Arrays.stream(values()).filter(type -> type.name.equalsIgnoreCase(name)).findFirst().orElse(null); + } } 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 0945b83..8a1e874 100644 --- a/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java +++ b/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java @@ -1,10 +1,56 @@ -//package rip.tilly.bedwars.menus.shop; -// -//import lombok.AllArgsConstructor; -//import rip.tilly.bedwars.utils.menu.Button; -// -//@AllArgsConstructor -//public class ShopTypeButton extends Button { -// -// private final ShopType shopType; -//} +package rip.tilly.bedwars.menus.shop; + +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.blocks.BlocksMenu; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +public class ShopTypeButton extends Button { + + private final ShopType shopType; + + @Override + public ItemStack getButtonItem(Player player) { + List loreList = new ArrayList<>(shopType.getLore()); + loreList.add("&eClick to open the " + shopType.getName() + " section!"); + + return new ItemBuilder(shopType.getMaterial()) + .durability(shopType.getData()) + .name(shopType.getName()) + .lore(loreList) + .hideFlags() + .build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + playNeutral(player); + + switch (shopType) { + case QUICK: + break; + case BLOCKS: + new BlocksMenu().openMenu(player); + break; + case ARMOR: + break; + case TOOLS: + break; + case WEAPONS: + break; + case RANGED: + break; + case POTIONS: + break; + case UTILITY: + break; + } + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/blocks/BlocksMenu.java b/src/main/java/rip/tilly/bedwars/menus/shop/blocks/BlocksMenu.java index 94a782b..64602ad 100644 --- a/src/main/java/rip/tilly/bedwars/menus/shop/blocks/BlocksMenu.java +++ b/src/main/java/rip/tilly/bedwars/menus/shop/blocks/BlocksMenu.java @@ -1,7 +1,13 @@ package rip.tilly.bedwars.menus.shop.blocks; +import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.entity.Player; +import rip.tilly.bedwars.menus.shop.ShopButton; +import rip.tilly.bedwars.menus.shop.ShopType; +import rip.tilly.bedwars.menus.shop.ShopTypeButton; 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; @@ -17,13 +23,34 @@ public class BlocksMenu extends Menu { @Override public String getTitle(Player player) { - return CC.translate("&eBlocks"); + return CC.translate("&eClick a block 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.BLOCKS.getSlot() + 9, Button.placeholder(Material.STAINED_GLASS_PANE, (byte) 5, " ")); + + buttons.put(19, new ShopButton("Wool", Material.WOOL, 0, 16, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 4, true)); + buttons.put(20, new ShopButton("Stained Clay", Material.STAINED_CLAY, 0, 16, Material.IRON_INGOT, "Iron", ChatColor.WHITE,12, true)); + buttons.put(21, new ShopButton("Blast-Proof Glass", Material.GLASS, 0, 4, Material.IRON_INGOT, "Iron", ChatColor.WHITE,12, true)); + buttons.put(22, new ShopButton("End Stone", Material.ENDER_STONE, 0, 12, Material.IRON_INGOT, "Iron", ChatColor.WHITE,24, false)); + buttons.put(23, new ShopButton("Ladder", Material.LADDER, 0, 8, Material.IRON_INGOT, "Iron", ChatColor.WHITE,4, false)); + buttons.put(24, new ShopButton("Wood", Material.WOOD, 0, 12, Material.GOLD_INGOT, "Gold", ChatColor.GOLD,4, false)); + buttons.put(25, new ShopButton("Obsidian", Material.OBSIDIAN, 0, 4, Material.EMERALD, "Emerald", ChatColor.GREEN,4, false)); + + fillEmptySlots(buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(7).name(" ").build()); + return buttons; } + + @Override + public int getSize() { + return 6 * 9; + } }