From e0e0d4c997f51c9dfab3bb16707e04e8035baa6a Mon Sep 17 00:00:00 2001 From: Shyanne Date: Sat, 23 Sep 2023 13:50:58 -0400 Subject: [PATCH] Implemented Biome Shop (#719) * Implemented Biome Shop - registered /is biomes command - added menu option - added config file - added plugin messages for biomes & co. - basically a carbon copy of IridiumTeams shop, localized for IridiumSkyblock * Changes * Remove DI * Early Return Pattern * Cleanup * More Cleanup * Added TabComplete * Inventory Changes * Fixed Issues with island permissions * Changed configs --------- Co-authored-by: Peaches_MLG --- .../iridiumskyblock/IridiumSkyblock.java | 5 + .../commands/BiomeCommand.java | 59 +++++++ .../iridiumskyblock/configs/Biomes.java | 155 ++++++++++++++++++ .../iridiumskyblock/configs/Commands.java | 2 + .../iridiumskyblock/configs/Inventories.java | 2 + .../iridiumskyblock/configs/Messages.java | 3 + .../iridiumskyblock/gui/BiomeCategoryGUI.java | 107 ++++++++++++ .../iridiumskyblock/gui/BiomeOverviewGUI.java | 51 ++++++ .../managers/BiomeManager.java | 107 ++++++++++++ .../managers/CommandManager.java | 1 + .../managers/DatabaseManager.java | 2 +- .../managers/IslandManager.java | 33 ++++ 12 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java create mode 100644 src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java create mode 100644 src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java create mode 100644 src/main/java/com/iridium/iridiumskyblock/gui/BiomeOverviewGUI.java create mode 100644 src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java diff --git a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java index f4e5d683f..4de2f3959 100644 --- a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java +++ b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java @@ -48,6 +48,7 @@ public class IridiumSkyblock extends IridiumTeams { private Missions missions; private Schematics schematics; private Shop shop; + private Biomes biomes; private Settings settings; private IslandPlaceholderBuilder teamsPlaceholderBuilder; @@ -61,6 +62,7 @@ public class IridiumSkyblock extends IridiumTeams { private MissionManager missionManager; private SchematicManager schematicManager; private ShopManager shopManager; + private BiomeManager biomeManager; private Economy economy; @@ -97,6 +99,7 @@ public void onEnable() { this.databaseManager = new DatabaseManager(); this.missionManager = new MissionManager<>(this); this.shopManager = new ShopManager<>(this); + this.biomeManager = new BiomeManager(); try { databaseManager.init(); } catch (SQLException exception) { @@ -156,6 +159,7 @@ public void loadConfigs() { this.missions = getPersist().load(Missions.class); this.schematics = getPersist().load(Schematics.class); this.shop = getPersist().load(Shop.class); + this.biomes = getPersist().load(Biomes.class); this.settings = getPersist().load(Settings.class); super.loadConfigs(); @@ -189,6 +193,7 @@ public void saveConfigs() { getPersist().save(missions); getPersist().save(schematics); getPersist().save(shop); + getPersist().save(biomes); getPersist().save(settings); saveSchematics(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java new file mode 100644 index 000000000..54fb81bd3 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java @@ -0,0 +1,59 @@ +package com.iridium.iridiumskyblock.commands; + +import com.iridium.iridiumcore.utils.StringUtils; +import com.iridium.iridiumskyblock.IridiumSkyblock; +import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.User; +import com.iridium.iridiumskyblock.gui.BiomeCategoryGUI; +import com.iridium.iridiumskyblock.gui.BiomeOverviewGUI; +import com.iridium.iridiumteams.IridiumTeams; +import com.iridium.iridiumteams.commands.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +public class BiomeCommand extends Command { + + public BiomeCommand() { + super(Collections.singletonList("biomes"), "Refresh your Island Biome", "%prefix% &7/is biomes ", "", 10); + } + + @Override + public boolean execute(User user, Island island, String[] args, IridiumTeams iridiumTeams) { + Player player = user.getPlayer(); + if (args.length == 0) { + player.openInventory(new BiomeOverviewGUI(player.getOpenInventory().getTopInventory()).getInventory()); + return false; + } else { + Optional categoryName = getCategoryName(String.join(" ", args)); + + if (!categoryName.isPresent()) { + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noBiomeCategory + .replace("%prefix%", iridiumTeams.getConfiguration().prefix) + )); + return false; + } + + player.openInventory(new BiomeCategoryGUI(categoryName.get(), player.getOpenInventory().getTopInventory()).getInventory()); + return false; + } + } + + private Optional getCategoryName(String name) { + for (String category : IridiumSkyblock.getInstance().getBiomes().categories.keySet()) { + if (category.equalsIgnoreCase(name)) { + return Optional.of(category); + } + } + return Optional.empty(); + } + + @Override + public List onTabComplete(CommandSender commandSender, String[] args, IridiumTeams iridiumTeams) { + return new ArrayList<>(IridiumSkyblock.getInstance().getBiomes().categories.keySet()); + } +} diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java b/src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java new file mode 100644 index 000000000..604e2adfa --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java @@ -0,0 +1,155 @@ +package com.iridium.iridiumskyblock.configs; + +import com.google.common.collect.ImmutableMap; +import com.iridium.iridiumcore.Item; +import com.iridium.iridiumcore.dependencies.fasterxml.annotation.JsonIgnore; +import com.iridium.iridiumcore.dependencies.xseries.XBiome; +import com.iridium.iridiumcore.dependencies.xseries.XMaterial; +import com.iridium.iridiumcore.dependencies.xseries.XSound; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +import java.util.*; + +public class Biomes { + + public Map categories = ImmutableMap.builder() + .put("Overworld", new BiomeCategory(new Item(XMaterial.GRASS_BLOCK, 11, 1, "&9&lOverworld", Collections.emptyList()), 27)) + .put("Nether", new BiomeCategory(new Item(XMaterial.CRIMSON_NYLIUM, 13, 1, "&9&lNether", Collections.emptyList()), 27)) + .put("End", new BiomeCategory(new Item(XMaterial.END_STONE, 15, 1, "&9&lEnd", Collections.emptyList()), 27)) + .build(); + public Map> items = ImmutableMap.>builder() + .put("Overworld", Arrays.asList( + new BiomeItem( + "&9&lPlains", + XMaterial.GRASS_BLOCK, + XBiome.PLAINS, + 1, + 11, + new Cost(100, new HashMap<>()) + ), + new BiomeItem( + "&9&lSnowy Plains", + XMaterial.SNOW_BLOCK, + XBiome.SNOWY_PLAINS, + 1, + 13, + new Cost(50, new HashMap<>()) + ), + new BiomeItem( + "&9&lSavanna", + XMaterial.TALL_GRASS, + XBiome.SAVANNA, + 1, + 15, + new Cost(100, new HashMap<>()) + ) + )) + .put("Nether", Arrays.asList( + new BiomeItem( + "&9&lNether Wastes", + XMaterial.NETHERRACK, + XBiome.NETHER_WASTES, + 1, + 11, + new Cost(50, new HashMap<>()) + ), + new BiomeItem( + "&9&lCrimson Forest", + XMaterial.CRIMSON_NYLIUM, + XBiome.CRIMSON_FOREST, + 1, + 13, + new Cost(1000, new HashMap<>()) + ), + new BiomeItem( + "&9&lWarped Forest", + XMaterial.WARPED_NYLIUM, + XBiome.WARPED_FOREST, + 1, + 15, + new Cost(100, new HashMap<>()) + ) + ) + ) + .put("End", Arrays.asList( + new BiomeItem( + "&9&lTHE END", + XMaterial.END_STONE, + XBiome.THE_END, + 1, + 11, + new Cost(100, new HashMap<>()) + ), + new BiomeItem( + "&9&lEnd Highlands", + XMaterial.PURPUR_BLOCK, + XBiome.END_HIGHLANDS, + 1, + 13, + new Cost(150, new HashMap<>()) + ), + new BiomeItem( + "&9&lEnd Barrens", + XMaterial.ENDER_EYE, + XBiome.END_BARRENS, + 1, + 15, + new Cost(150, new HashMap<>()) + ) + ) + ) + .build(); + public String buyPriceLore = "&aBuy Price: $%vault_cost%"; + public String notPurchasableLore = "&cThis item cannot be purchased!"; + public boolean abbreviatePrices = true; + public XSound failSound = XSound.BLOCK_ANVIL_LAND; + public XSound successSound = XSound.ENTITY_PLAYER_LEVELUP; + public List biomeItemLore = Arrays.asList( + "&9&l[!] " + "&9Left-Click to Purchase" + ); + + @NoArgsConstructor + @AllArgsConstructor + public static class BiomeCategory { + public Item item; + public int inventorySize; + } + + @NoArgsConstructor + @AllArgsConstructor + public static class BiomeItem { + public String name; + public XMaterial type; + public XBiome biome; + public List lore; + public int defaultAmount; + public int slot; + public int page; + public Cost buyCost; + + public BiomeItem(String name, XMaterial type, XBiome biome, int defaultAmount, int slot, Cost buyCost) { + this.name = name; + this.type = type; + this.biome = biome; + this.lore = Collections.emptyList(); + this.defaultAmount = defaultAmount; + this.slot = slot; + this.page = 1; + this.buyCost = buyCost; + } + } + + @AllArgsConstructor + @NoArgsConstructor + public static class Cost { + public double money; + public Map bankItems; + + @JsonIgnore + public boolean canPurchase() { + return money > 0 || bankItems.values().stream().anyMatch(value -> value > 0); + } + } + +} diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java b/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java index 5264fea7f..e4b955193 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java @@ -1,5 +1,6 @@ package com.iridium.iridiumskyblock.configs; +import com.iridium.iridiumskyblock.commands.BiomeCommand; import com.iridium.iridiumskyblock.commands.BorderCommand; import com.iridium.iridiumskyblock.commands.RegenCommand; import com.iridium.iridiumskyblock.commands.VisitCommand; @@ -14,4 +15,5 @@ public Commands() { public VisitCommand visitCommand = new VisitCommand(); public BorderCommand borderCommand = new BorderCommand(); public RegenCommand regenCommand = new RegenCommand(); + public BiomeCommand biomeCommand = new BiomeCommand(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java b/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java index 3d7e4847c..677444074 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java @@ -59,6 +59,8 @@ public class Inventories extends com.iridium.iridiumteams.configs.Inventories { ))); public NoItemGUI islandSchematicGUI = new NoItemGUI(27, "&7Select a Schematic", background2); + public NoItemGUI biomeOverviewGUI = new NoItemGUI(27, "Biomes", background2); + public NoItemGUI biomeCategoryGUI = new NoItemGUI(54, "Biomes - %biome_category_name%", background1); public Inventories() { super("Island", "&9"); diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java b/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java index 0ae41b283..b50c8a708 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java @@ -21,4 +21,7 @@ public Messages() { public String noSafeLocation = "%prefix% &7Could not find a safe location to teleport to."; public String cannotHurtPlayers = "%prefix% &7You cannot hurt players on your Island."; public String creatingIsland = "%prefix% &7Creating Island, please wait..."; + public String noBiomeCategory = "%prefix% &7No biome category with that name."; + public String noBiome = "%prefix% &7No biome with that name."; + public String changedBiome = "%prefix% &7%player% successfully changed your Island biome to %biome%."; } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java new file mode 100644 index 000000000..eabd13579 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java @@ -0,0 +1,107 @@ +package com.iridium.iridiumskyblock.gui; + +import com.iridium.iridiumcore.gui.BackGUI; +import com.iridium.iridiumcore.utils.Placeholder; +import com.iridium.iridiumcore.utils.StringUtils; +import com.iridium.iridiumskyblock.IridiumSkyblock; +import com.iridium.iridiumskyblock.configs.Biomes; +import com.iridium.iridiumteams.configs.inventories.NoItemGUI; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +public class BiomeCategoryGUI extends BackGUI { + + @Getter + private final String categoryName; + private final Biomes.BiomeCategory biomeCategory; + + public BiomeCategoryGUI(String categoryName, Inventory previousInventory) { + super(IridiumSkyblock.getInstance().getInventories().biomeCategoryGUI.background, previousInventory, IridiumSkyblock.getInstance().getInventories().backButton); + this.categoryName = categoryName; + this.biomeCategory = IridiumSkyblock.getInstance().getBiomes().categories.get(categoryName); + } + + @NotNull + @Override + public Inventory getInventory() { + NoItemGUI biomeCategoryGUI = IridiumSkyblock.getInstance().getInventories().biomeCategoryGUI; + Inventory inventory = Bukkit.createInventory(this, biomeCategory.inventorySize, StringUtils.color(biomeCategoryGUI.title.replace("%biome_category_name%", categoryName))); + addContent(inventory); + return inventory; + } + + @Override + public void addContent(Inventory inventory) { + super.addContent(inventory); + + if (!IridiumSkyblock.getInstance().getBiomes().items.containsKey(categoryName)) { + IridiumSkyblock.getInstance().getLogger().warning("Biome Category " + categoryName + " Is not configured with any items!"); + return; + } + for (Biomes.BiomeItem biomeItem : IridiumSkyblock.getInstance().getBiomes().items.get(categoryName)) { + ItemStack itemStack = biomeItem.type.parseItem(); + ItemMeta itemMeta = itemStack.getItemMeta(); + + itemStack.setAmount(biomeItem.defaultAmount); + itemMeta.setDisplayName(StringUtils.color(biomeItem.name)); + itemMeta.setLore(getBiomeLore(biomeItem)); + + itemStack.setItemMeta(itemMeta); + inventory.setItem(biomeItem.slot, itemStack); + } + } + + private List getBiomeLorePlaceholders(Biomes.BiomeItem item) { + List placeholders = new ArrayList<>(Arrays.asList( + new Placeholder("amount", IridiumSkyblock.getInstance().getBiomeManager().formatPrice(item.defaultAmount)), + new Placeholder("vault_cost", IridiumSkyblock.getInstance().getBiomeManager().formatPrice(item.buyCost.money)) + )); + for (Map.Entry bankItem : item.buyCost.bankItems.entrySet()) { + placeholders.add(new Placeholder(bankItem.getKey() + "_cost", IridiumSkyblock.getInstance().getBiomeManager().formatPrice(bankItem.getValue()))); + } + return placeholders; + } + + private List getBiomeLore(Biomes.BiomeItem item) { + List lore = item.lore == null ? new ArrayList<>() : new ArrayList<>(StringUtils.color(item.lore)); + List placeholders = getBiomeLorePlaceholders(item); + + if (item.buyCost.canPurchase()) { + lore.add(IridiumSkyblock.getInstance().getBiomes().buyPriceLore); + } else { + lore.add(IridiumSkyblock.getInstance().getBiomes().notPurchasableLore); + } + + lore.addAll(IridiumSkyblock.getInstance().getBiomes().biomeItemLore); + + return StringUtils.color(StringUtils.processMultiplePlaceholders(lore, placeholders)); + } + + @Override + public void onInventoryClick(InventoryClickEvent event) { + super.onInventoryClick(event); + Optional biomeItem = IridiumSkyblock.getInstance().getBiomes().items.get(categoryName).stream() + .filter(item -> item.slot == event.getSlot()) + .findAny(); + + if (!biomeItem.isPresent()) { + return; + } + + Player player = (Player) event.getWhoClicked(); + if (event.isLeftClick() && biomeItem.get().buyCost.canPurchase()) { + IridiumSkyblock.getInstance().getBiomeManager().buy(player, biomeItem.get()); + player.closeInventory(); + } else { + IridiumSkyblock.getInstance().getBiomes().failSound.play(player); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BiomeOverviewGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeOverviewGUI.java new file mode 100644 index 000000000..6d08a3278 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeOverviewGUI.java @@ -0,0 +1,51 @@ +package com.iridium.iridiumskyblock.gui; + +import com.iridium.iridiumcore.gui.BackGUI; +import com.iridium.iridiumcore.utils.ItemStackUtils; +import com.iridium.iridiumcore.utils.StringUtils; +import com.iridium.iridiumskyblock.IridiumSkyblock; +import com.iridium.iridiumskyblock.configs.Biomes; +import com.iridium.iridiumteams.configs.inventories.NoItemGUI; +import org.bukkit.Bukkit; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class BiomeOverviewGUI extends BackGUI { + + public BiomeOverviewGUI(Inventory previousInventory) { + super(IridiumSkyblock.getInstance().getInventories().biomeOverviewGUI.background, previousInventory, IridiumSkyblock.getInstance().getInventories().backButton); + } + + @NotNull + @Override + public Inventory getInventory() { + NoItemGUI biomeOverviewGUI = IridiumSkyblock.getInstance().getInventories().biomeOverviewGUI; + Inventory inventory = Bukkit.createInventory(this, biomeOverviewGUI.size, StringUtils.color(biomeOverviewGUI.title)); + addContent(inventory); + return inventory; + } + + @Override + public void addContent(Inventory inventory) { + super.addContent(inventory); + + for (Biomes.BiomeCategory category : IridiumSkyblock.getInstance().getBiomes().categories.values()) { + inventory.setItem(category.item.slot, ItemStackUtils.makeItem(category.item)); + } + } + + @Override + public void onInventoryClick(InventoryClickEvent event) { + for (Map.Entry category : IridiumSkyblock.getInstance().getBiomes().categories.entrySet()) { + if (event.getSlot() != category.getValue().item.slot) continue; + event.getWhoClicked().openInventory(new BiomeCategoryGUI(category.getKey(), event.getWhoClicked().getOpenInventory().getTopInventory()).getInventory()); + return; + } + super.onInventoryClick(event); + } +} + + diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java new file mode 100644 index 000000000..05c6e6771 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java @@ -0,0 +1,107 @@ +package com.iridium.iridiumskyblock.managers; + +import com.iridium.iridiumcore.dependencies.xseries.XBiome; +import com.iridium.iridiumcore.utils.StringUtils; +import com.iridium.iridiumskyblock.IridiumSkyblock; +import com.iridium.iridiumskyblock.configs.Biomes; +import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.User; +import com.iridium.iridiumteams.database.IridiumUser; +import com.iridium.iridiumteams.database.TeamBank; +import net.milkbowl.vault.economy.Economy; +import org.apache.commons.lang.WordUtils; +import org.bukkit.entity.Player; + +import java.util.Optional; + +public class BiomeManager { + + public void buy(Player player, Biomes.BiomeItem biomeItem) { + XBiome biome = biomeItem.biome; + User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); + Optional island = user.getIsland(); + Optional biomeOptional = XBiome.matchXBiome(biomeItem.biome.toString()); + + if (!canPurchase(player, biomeItem)) { + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + )); + IridiumSkyblock.getInstance().getBiomes().failSound.play(player); + return; + } + + if (!biomeOptional.isPresent()) { + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noBiome + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + )); + return; + } + + if (!island.isPresent()) { + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().dontHaveTeam + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + )); + return; + } + + purchase(player, biomeItem); + + IridiumSkyblock.getInstance().getCommands().biomeCommand.getCooldownProvider().applyCooldown(player); + + IridiumSkyblock.getInstance().getIslandManager().setIslandBiome(island.get(), biomeOptional.get()); + IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island.get()).stream().map(IridiumUser::getPlayer).forEach((teamMember) -> { + if (teamMember != null) { + teamMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().changedBiome + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + .replace("%player%", player.getName()) + .replace("%biome%", WordUtils.capitalizeFully(biome.toString().toLowerCase().replace("_", " "))) + )); + } + }); + IridiumSkyblock.getInstance().getBiomes().successSound.play(player); + + } + + private double getBankBalance(Player player, String bankItem) { + User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); + return IridiumSkyblock.getInstance().getTeamManager().getTeamViaID(user.getTeamID()) + .map(team -> IridiumSkyblock.getInstance().getTeamManager().getTeamBank(team, bankItem)) + .map(TeamBank::getNumber) + .orElse(0.0); + } + + private void setBankBalance(Player player, String bankItem, double amount) { + User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); + Optional team = IridiumSkyblock.getInstance().getTeamManager().getTeamViaID(user.getTeamID()); + if (!team.isPresent()) return; + IridiumSkyblock.getInstance().getTeamManager().getTeamBank(team.get(), bankItem).setNumber(amount); + } + + private boolean canPurchase(Player player, Biomes.BiomeItem biomeItem) { + double moneyCost = biomeItem.buyCost.money; + Economy economy = IridiumSkyblock.getInstance().getEconomy(); + for (String bankItem : biomeItem.buyCost.bankItems.keySet()) { + double cost = biomeItem.buyCost.bankItems.get(bankItem); + if (getBankBalance(player, bankItem) < cost) return false; + } + + return moneyCost == 0 || economy != null && economy.getBalance(player) >= moneyCost; + } + + private void purchase(Player player, Biomes.BiomeItem biomeItem) { + double moneyCost = biomeItem.buyCost.money; + IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, moneyCost); + + for (String bankItem : biomeItem.buyCost.bankItems.keySet()) { + double cost = biomeItem.buyCost.bankItems.get(bankItem); + setBankBalance(player, bankItem, getBankBalance(player, bankItem) - cost); + } + } + + public String formatPrice(double value) { + if (IridiumSkyblock.getInstance().getBiomes().abbreviatePrices) { + return IridiumSkyblock.getInstance().getConfiguration().numberFormatter.format(value); + } + return String.valueOf(value); + } +} diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/CommandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/CommandManager.java index dc3ad6028..b92aee648 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/CommandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/CommandManager.java @@ -20,6 +20,7 @@ public void registerCommands() { registerCommand(IridiumSkyblock.getInstance().getCommands().visitCommand); registerCommand(IridiumSkyblock.getInstance().getCommands().borderCommand); registerCommand(IridiumSkyblock.getInstance().getCommands().regenCommand); + registerCommand(IridiumSkyblock.getInstance().getCommands().biomeCommand); } @Override diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/DatabaseManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/DatabaseManager.java index dedcf41c4..235bc8f2f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/DatabaseManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/DatabaseManager.java @@ -68,7 +68,7 @@ public void init() throws SQLException { this.islandTableManager = new IslandTableManager(connectionSource); this.invitesTableManager = new ForeignIslandTableManager<>(connectionSource, TeamInvite.class, Comparator.comparing(TeamInvite::getTeamID).thenComparing(TeamInvite::getUser)); this.trustTableManager = new ForeignIslandTableManager<>(connectionSource, TeamTrust.class, Comparator.comparing(TeamTrust::getTeamID).thenComparing(TeamTrust::getUser)); - this.permissionsTableManager = new ForeignIslandTableManager<>(connectionSource, TeamPermission.class, Comparator.comparing(TeamPermission::getTeamID).thenComparing(TeamPermission::getPermission)); + this.permissionsTableManager = new ForeignIslandTableManager<>(connectionSource, TeamPermission.class, Comparator.comparing(TeamPermission::getTeamID).thenComparing(TeamPermission::getPermission).thenComparing(TeamPermission::getRank)); this.bankTableManager = new ForeignIslandTableManager<>(connectionSource, TeamBank.class, Comparator.comparing(TeamBank::getTeamID).thenComparing(TeamBank::getBankItem)); this.enhancementTableManager = new ForeignIslandTableManager<>(connectionSource, TeamEnhancement.class, Comparator.comparing(TeamEnhancement::getTeamID).thenComparing(TeamEnhancement::getEnhancementName)); this.teamBlockTableManager = new ForeignIslandTableManager<>(connectionSource, TeamBlock.class, Comparator.comparing(TeamBlock::getTeamID).thenComparing(TeamBlock::getXMaterial)); diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index 095e2ae97..381d16b3f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -4,6 +4,7 @@ import com.iridium.iridiumcore.dependencies.nbtapi.NBTItem; import com.iridium.iridiumcore.dependencies.paperlib.PaperLib; import com.iridium.iridiumcore.dependencies.xseries.XMaterial; +import com.iridium.iridiumcore.dependencies.xseries.XBiome; import com.iridium.iridiumcore.utils.ItemStackUtils; import com.iridium.iridiumcore.utils.Placeholder; import com.iridium.iridiumcore.utils.StringUtils; @@ -56,6 +57,35 @@ public void createWorld(World.Environment environment, String name) { Bukkit.createWorld(worldCreator); } + public void setIslandBiome(@NotNull Island island, @NotNull XBiome biome) { + World.Environment environment = biome.getEnvironment(); + World world; + switch (environment) { + case NETHER: + world = getWorld(World.Environment.NETHER); + break; + case THE_END: + world = getWorld(World.Environment.THE_END); + break; + default: + world = getWorld(World.Environment.NORMAL); + break; + } + + getIslandChunks(island).thenAccept(chunks -> { + Location pos1 = island.getPosition1(world); + Location pos2 = island.getPosition2(world); + biome.setBiome(pos1, pos2).thenRun(() -> { + for (Chunk chunk : chunks) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + } + }); + }).exceptionally(throwable -> { + throwable.printStackTrace(); + return null; + }); + } + @Override public Optional getTeamViaID(int id) { return IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getIsland(id); @@ -158,6 +188,9 @@ public CompletableFuture generateIsland(Island island, Schematics.Schemati setHome(island, schematicConfig); deleteIslandBlocks(island).join(); IridiumSkyblock.getInstance().getSchematicManager().pasteSchematic(island, schematicConfig).join(); + setIslandBiome(island, XBiome.matchXBiome(schematicConfig.overworld.biome)); + setIslandBiome(island, XBiome.matchXBiome(schematicConfig.nether.biome)); + setIslandBiome(island, XBiome.matchXBiome(schematicConfig.end.biome)); }); }