From d5d4bf7c45eabc4edcc9e30973b6db4138629307 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Mon, 2 Oct 2023 01:03:56 -0400 Subject: [PATCH 01/12] Added payPerRegen setting - added `payPerRegen` setting to allow servers to charge players to regenerate their island - includes a message sent to players of the island with `%schematic% placeholder to add schematic name to message - missing schematic lore --- .../commands/RegenCommand.java | 7 ++ .../configs/Configuration.java | 1 + .../iridiumskyblock/configs/Messages.java | 1 + .../iridiumskyblock/configs/Schematics.java | 95 ++++++++++++++----- .../managers/SchematicManager.java | 84 ++++++++++++++++ 5 files changed, 162 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index efdd82db8..5dd44a298 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -47,6 +47,13 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams schematics = ImmutableMap.builder() - .put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&9&lDesert Island", Collections.singletonList("&7A starter desert island.")), - -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT, - "desert.schem", 90.0, true - ), new SchematicWorld(Biome.NETHER_WASTES, - "desert_nether.schem", 90.0, true - ), new SchematicWorld(Biome.THE_END, - "desert_end.schem", 90.0, true - ))) - .put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&9&lJungle Island", Collections.singletonList("&7A starter jungle island.")), - 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE, - "jungle.schem", 90.0, true - ), new SchematicWorld(Biome.NETHER_WASTES, - "jungle_nether.schem", 90.0, true - ), new SchematicWorld(Biome.THE_END, - "jungle_end.schem", 90.0, true - ))) - .put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&9&lMushroom Island", Collections.singletonList("&7A starter mushroom island.")), - 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS, - "mushroom.schem", 90.0, true - ), new SchematicWorld(Biome.NETHER_WASTES, - "mushroom_nether.schem", 90.0, true - ), new SchematicWorld(Biome.THE_END, - "mushroom_end.schem", 90.0, true - ))) - .build(); + public Map schematics; + public String buyPriceLore; + public String notPurchasableLore; + public boolean abbreviatePrices; + public XSound failSound; + public XSound successSound; + public List schematicPurchaseLore; + + public Schematics() { + this("&c"); + } + + public Schematics(String color) { + schematics = ImmutableMap.builder() + .put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&9&lDesert Island", Collections.singletonList("&7A starter desert island.")), + new Schematics.Cost(100, new HashMap<>()), -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT, + "desert.schem", 90.0, true + ), new SchematicWorld(Biome.NETHER_WASTES, + "desert_nether.schem", 90.0, true + ), new SchematicWorld(Biome.THE_END, + "desert_end.schem", 90.0, true + ))) + .put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&9&lJungle Island", Collections.singletonList("&7A starter jungle island.")), + new Schematics.Cost(100, new HashMap<>()), 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE, + "jungle.schem", 90.0, true + ), new SchematicWorld(Biome.NETHER_WASTES, + "jungle_nether.schem", 90.0, true + ), new SchematicWorld(Biome.THE_END, + "jungle_end.schem", 90.0, true + ))) + .put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&9&lMushroom Island", Collections.singletonList("&7A starter mushroom island.")), + new Schematics.Cost(100, new HashMap<>()), 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS, + "mushroom.schem", 90.0, true + ), new SchematicWorld(Biome.NETHER_WASTES, + "mushroom_nether.schem", 90.0, true + ), new SchematicWorld(Biome.THE_END, + "mushroom_end.schem", 90.0, true + ))) + .build(); + + buyPriceLore = "&aBuy Price: $%vault_cost%"; + notPurchasableLore = "&cThis item cannot be purchased!"; + + abbreviatePrices = true; + + failSound = XSound.BLOCK_ANVIL_LAND; + successSound = XSound.ENTITY_PLAYER_LEVELUP; + + schematicPurchaseLore = Arrays.asList( + " ", + color + "&l[!] " + color + "Left-Click to Purchase %amount%, Shift for 64", + color + "&l[!] " + color + "Right Click to Sell %amount%, Shift for 64" + ); + } @NoArgsConstructor @AllArgsConstructor public static class SchematicConfig { public Item item; + public Cost regenCost; public double xHome; public double yHome; public double zHome; @@ -69,4 +100,16 @@ public SchematicWorld(Biome biome, String schematicID, Double islandHeight, Bool } } + @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/managers/SchematicManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java index 71476c898..1c81eed36 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java @@ -1,20 +1,30 @@ package com.iridium.iridiumskyblock.managers; +import com.iridium.iridiumcore.utils.Placeholder; +import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.configs.Schematics; import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.schematics.FastAsyncWorldEdit; import com.iridium.iridiumskyblock.schematics.SchematicAsync; import com.iridium.iridiumskyblock.schematics.SchematicPaster; import com.iridium.iridiumskyblock.schematics.WorldEdit; +import com.iridium.iridiumteams.bank.BankItem; +import com.iridium.iridiumteams.database.TeamBank; +import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.entity.Player; import java.io.File; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; public class SchematicManager { @@ -115,4 +125,78 @@ private CompletableFuture pasteSchematic(Island island, Schematics.Schemat return completableFuture; } + public boolean buy(Player player, Schematics.SchematicConfig schematic) { + if (!canPurchase(player, schematic)) { + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + IridiumSkyblock.getInstance().getSchematics().failSound.play(player); + return false; + } + + purchase(player, schematic); + + IridiumSkyblock.getInstance().getSchematics().successSound.play(player); + + List bankPlaceholders = IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .map(name -> new Placeholder(name + "_cost", formatPrice(getBankBalance(player, name)))) + .collect(Collectors.toList()); + + player.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().paidForRegen + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + .replace("%player%", player.getName()) + .replace("%schematic%", StringUtils.color(schematic.item.displayName)) + .replace("%vault_cost%", formatPrice(schematic.regenCost.money)), + bankPlaceholders) + )); + + return true; + } + + 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 island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaID(user.getTeamID()); + if (!island.isPresent()) return; + IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island.get(), bankItem).setNumber(amount); + } + + private boolean canPurchase(Player player, Schematics.SchematicConfig schematic) { + double moneyCost = schematic.regenCost.money; + Economy economy = IridiumSkyblock.getInstance().getEconomy(); + for (String bankItem : schematic.regenCost.bankItems.keySet()) { + double cost = round(schematic.regenCost.bankItems.get(bankItem), 2); + if (getBankBalance(player, bankItem) < cost) return false; + } + + return moneyCost == 0 || economy != null && economy.getBalance(player) >= schematic.regenCost.money; + } + + private void purchase(Player player, Schematics.SchematicConfig schematic) { + IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, schematic.regenCost.money); + + for (String bankItem : schematic.regenCost.bankItems.keySet()) { + setBankBalance(player, bankItem, getBankBalance(player, bankItem) - round(schematic.regenCost.bankItems.get(bankItem), 2)); + } + } + + private double round(double value, int places) { + BigDecimal bigDecimal = BigDecimal.valueOf(value); + bigDecimal = bigDecimal.setScale(places, RoundingMode.HALF_UP); + return bigDecimal.doubleValue(); + } + + public String formatPrice(double value) { + if (IridiumSkyblock.getInstance().getSchematics().abbreviatePrices) { + return IridiumSkyblock.getInstance().getConfiguration().numberFormatter.format(value); + } + return String.valueOf(value); + } } From a4f8bee35cf59424a8ccf924472dd8b0055b490f Mon Sep 17 00:00:00 2001 From: Shyanne Date: Mon, 2 Oct 2023 01:15:51 -0400 Subject: [PATCH 02/12] Update Schematics.java --- .../java/com/iridium/iridiumskyblock/configs/Schematics.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java b/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java index 36bea8f25..90c53f672 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java @@ -10,8 +10,7 @@ import lombok.NoArgsConstructor; import org.bukkit.block.Biome; -import java.util.Collections; -import java.util.Map; +import java.util.*; @JsonIgnoreProperties(ignoreUnknown = true) public class Schematics { From c8322558b1e8dd9f255cf4260386973f9b420ec0 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Mon, 2 Oct 2023 21:46:01 -0400 Subject: [PATCH 03/12] Update src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java Co-authored-by: Peaches_MLG --- .../com/iridium/iridiumskyblock/commands/RegenCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index 5dd44a298..783a8b66d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -48,8 +48,7 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams Date: Tue, 3 Oct 2023 00:15:40 -0400 Subject: [PATCH 04/12] updated PR to remove config check rather than check the config for the specified boolean, we now check to see if the schematic has a value other than 0 assigned to it (this also allows servers to charge for specific schematics and not others) --- .../com/iridium/iridiumskyblock/commands/RegenCommand.java | 2 +- .../com/iridium/iridiumskyblock/configs/Configuration.java | 1 - .../com/iridium/iridiumskyblock/configs/Schematics.java | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index 783a8b66d..e2e6cbd64 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -47,7 +47,7 @@ public boolean execute(User user, Island island, String[] args, IridiumTeamsbuilder() .put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&9&lDesert Island", Collections.singletonList("&7A starter desert island.")), - new Schematics.Cost(100, new HashMap<>()), -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT, + new Schematics.Cost(0, new HashMap<>()), -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT, "desert.schem", 90.0, true ), new SchematicWorld(Biome.NETHER_WASTES, "desert_nether.schem", 90.0, true @@ -38,7 +38,7 @@ public Schematics(String color) { "desert_end.schem", 90.0, true ))) .put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&9&lJungle Island", Collections.singletonList("&7A starter jungle island.")), - new Schematics.Cost(100, new HashMap<>()), 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE, + new Schematics.Cost(0, new HashMap<>()), 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE, "jungle.schem", 90.0, true ), new SchematicWorld(Biome.NETHER_WASTES, "jungle_nether.schem", 90.0, true @@ -46,7 +46,7 @@ public Schematics(String color) { "jungle_end.schem", 90.0, true ))) .put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&9&lMushroom Island", Collections.singletonList("&7A starter mushroom island.")), - new Schematics.Cost(100, new HashMap<>()), 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS, + new Schematics.Cost(0, new HashMap<>()), 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS, "mushroom.schem", 90.0, true ), new SchematicWorld(Biome.NETHER_WASTES, "mushroom_nether.schem", 90.0, true From 86eb002311d6c2d08aede900e42d1772988b039b Mon Sep 17 00:00:00 2001 From: Shyanne Date: Sun, 8 Oct 2023 15:49:57 -0400 Subject: [PATCH 05/12] updated SchematicManager.java and RegenCommand.java --- .../commands/RegenCommand.java | 4 +- .../managers/SchematicManager.java | 92 +++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index e2e6cbd64..93f328012 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -47,8 +47,8 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams pasteSchematic(Island island, Schematics.Schemat return completableFuture; } - public boolean buy(Player player, Schematics.SchematicConfig schematic) { - if (!canPurchase(player, schematic)) { - player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford - .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); - IridiumSkyblock.getInstance().getSchematics().failSound.play(player); + public boolean processTransaction(Player player, Schematics.SchematicConfig schematic) { + + User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); + Optional island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaID(user.getTeamID()); + + if(!island.isPresent()){ + //NO ISLAND return false; } - purchase(player, schematic); + TeamBank bank; - IridiumSkyblock.getInstance().getSchematics().successSound.play(player); + double bankBalance; + List bankPlaceholders; + double moneyCost = schematic.regenCost.money; + Economy economy = IridiumSkyblock.getInstance().getEconomy(); - List bankPlaceholders = IridiumSkyblock.getInstance().getBankItemList().stream() - .map(BankItem::getName) - .map(name -> new Placeholder(name + "_cost", formatPrice(getBankBalance(player, name)))) - .collect(Collectors.toList()); + if(moneyCost == 0 || economy != null && economy.getBalance(player) >= moneyCost) { + //INVALID TRANSACTION + return false; + } - player.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().paidForRegen - .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) - .replace("%player%", player.getName()) - .replace("%schematic%", StringUtils.color(schematic.item.displayName)) - .replace("%vault_cost%", formatPrice(schematic.regenCost.money)), - bankPlaceholders) - )); + for (String schematicBankItem : schematic.regenCost.bankItems.keySet()) { - return true; - } + bank = IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island.get(), schematicBankItem); + bankBalance = bank.getNumber(); - 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); - } + double cost = round(schematic.regenCost.bankItems.get(schematicBankItem), 2); - private void setBankBalance(Player player, String bankItem, double amount) { - User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); - Optional island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaID(user.getTeamID()); - if (!island.isPresent()) return; - IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island.get(), bankItem).setNumber(amount); - } + if (bank.getNumber() < cost) { + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + IridiumSkyblock.getInstance().getSchematics().failSound.play(player); - private boolean canPurchase(Player player, Schematics.SchematicConfig schematic) { - double moneyCost = schematic.regenCost.money; - Economy economy = IridiumSkyblock.getInstance().getEconomy(); - for (String bankItem : schematic.regenCost.bankItems.keySet()) { - double cost = round(schematic.regenCost.bankItems.get(bankItem), 2); - if (getBankBalance(player, bankItem) < cost) return false; + return false; + } + + double finalBankBalance = bankBalance; + bankPlaceholders = IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .map(name -> new Placeholder(name + "_cost", formatPrice(finalBankBalance))) + .collect(Collectors.toList()); + + player.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().paidForRegen + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + .replace("%player%", player.getName()) + .replace("%schematic%", StringUtils.color(schematic.item.displayName)) + .replace("%bank_cost%", formatPrice(cost)) + .replace ("%vault_cost%", formatPrice(moneyCost)), + bankPlaceholders) + )); + + bank.setNumber(bankBalance - cost); } - return moneyCost == 0 || economy != null && economy.getBalance(player) >= schematic.regenCost.money; - } + economy.withdrawPlayer(player, moneyCost); - private void purchase(Player player, Schematics.SchematicConfig schematic) { - IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, schematic.regenCost.money); + IridiumSkyblock.getInstance().getSchematics().successSound.play(player); - for (String bankItem : schematic.regenCost.bankItems.keySet()) { - setBankBalance(player, bankItem, getBankBalance(player, bankItem) - round(schematic.regenCost.bankItems.get(bankItem), 2)); - } + return true; } private double round(double value, int places) { From d7c04016a1aa79683cf33a94bf38b8d5bdaeaa50 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Mon, 9 Oct 2023 18:11:57 -0400 Subject: [PATCH 06/12] Update src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java Co-authored-by: Peaches_MLG --- .../iridium/iridiumskyblock/managers/SchematicManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java index c7c5ef175..325bbd826 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java @@ -142,8 +142,8 @@ public boolean processTransaction(Player player, Schematics.SchematicConfig sche double moneyCost = schematic.regenCost.money; Economy economy = IridiumSkyblock.getInstance().getEconomy(); - if(moneyCost == 0 || economy != null && economy.getBalance(player) >= moneyCost) { - //INVALID TRANSACTION + if(moneyCost != 0 && economy != null && economy.getBalance(player) < moneyCost) { + //Cannot Afford return false; } From 1acef2fb388eab176fcb90469d332656e860ecec Mon Sep 17 00:00:00 2001 From: Shyanne Date: Mon, 9 Oct 2023 18:12:31 -0400 Subject: [PATCH 07/12] Update src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java Co-authored-by: Peaches_MLG --- .../iridium/iridiumskyblock/managers/SchematicManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java index 325bbd826..b872203a9 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java @@ -149,8 +149,8 @@ public boolean processTransaction(Player player, Schematics.SchematicConfig sche for (String schematicBankItem : schematic.regenCost.bankItems.keySet()) { - bank = IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island.get(), schematicBankItem); - bankBalance = bank.getNumber(); + TeamBank bank = IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island.get(), schematicBankItem); + double bankBalance = bank.getNumber(); double cost = round(schematic.regenCost.bankItems.get(schematicBankItem), 2); From 01a8b322f5f50d6fd2bf9803bc6fce5ae9350dcc Mon Sep 17 00:00:00 2001 From: Shyanne Date: Mon, 9 Oct 2023 18:12:38 -0400 Subject: [PATCH 08/12] Update src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java Co-authored-by: Peaches_MLG --- .../com/iridium/iridiumskyblock/managers/SchematicManager.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java index b872203a9..18be08d42 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java @@ -135,9 +135,6 @@ public boolean processTransaction(Player player, Schematics.SchematicConfig sche return false; } - TeamBank bank; - - double bankBalance; List bankPlaceholders; double moneyCost = schematic.regenCost.money; Economy economy = IridiumSkyblock.getInstance().getEconomy(); From 69aa68e6911f1a3ab1ccd28fdead539056ebb3b0 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Mon, 9 Oct 2023 18:13:19 -0400 Subject: [PATCH 09/12] Update src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java Co-authored-by: Peaches_MLG --- .../java/com/iridium/iridiumskyblock/commands/RegenCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index 93f328012..c448ddb9b 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -47,7 +47,7 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams Date: Wed, 11 Oct 2023 19:12:57 -0400 Subject: [PATCH 10/12] Updated SchematicManager.java copied the shopmanager and created this, parity is important and tbh i prefer this anyway --- .../commands/RegenCommand.java | 2 +- .../managers/SchematicManager.java | 96 ++++++++++--------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index c448ddb9b..777072bc7 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -48,7 +48,7 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams pasteSchematic(Island island, Schematics.Schemat return completableFuture; } - public boolean processTransaction(Player player, Schematics.SchematicConfig schematic) { - - User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); - Optional island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaID(user.getTeamID()); - - if(!island.isPresent()){ - //NO ISLAND + public boolean buy(Player player, Schematics.SchematicConfig schematic) { + if (!canPurchase(player, schematic)) { + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + IridiumSkyblock.getInstance().getSchematics().failSound.play(player); return false; } - List bankPlaceholders; - double moneyCost = schematic.regenCost.money; - Economy economy = IridiumSkyblock.getInstance().getEconomy(); + purchase(player, schematic); - if(moneyCost != 0 && economy != null && economy.getBalance(player) < moneyCost) { - //Cannot Afford - return false; - } + IridiumSkyblock.getInstance().getShop().successSound.play(player); - for (String schematicBankItem : schematic.regenCost.bankItems.keySet()) { + List bankPlaceholders = IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .map(name -> new Placeholder(name + "_cost", formatPrice(getBankBalance(player, name)))) + .collect(Collectors.toList()); - TeamBank bank = IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island.get(), schematicBankItem); - double bankBalance = bank.getNumber(); + double moneyCost = round(schematic.regenCost.money, 2); - double cost = round(schematic.regenCost.bankItems.get(schematicBankItem), 2); + player.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().paidForRegen + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + .replace("%player%", player.getName()) + .replace("%schematic%", StringUtils.color(schematic.item.displayName)) + .replace ("%vault_cost%", formatPrice(moneyCost)), + bankPlaceholders) + )); + return true; + } - if (bank.getNumber() < cost) { - player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford - .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); - IridiumSkyblock.getInstance().getSchematics().failSound.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); + } - return false; - } + 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); + } - double finalBankBalance = bankBalance; - bankPlaceholders = IridiumSkyblock.getInstance().getBankItemList().stream() - .map(BankItem::getName) - .map(name -> new Placeholder(name + "_cost", formatPrice(finalBankBalance))) - .collect(Collectors.toList()); - - player.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().paidForRegen - .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) - .replace("%player%", player.getName()) - .replace("%schematic%", StringUtils.color(schematic.item.displayName)) - .replace("%bank_cost%", formatPrice(cost)) - .replace ("%vault_cost%", formatPrice(moneyCost)), - bankPlaceholders) - )); - - bank.setNumber(bankBalance - cost); + private boolean canPurchase(Player player, Schematics.SchematicConfig schematic) { + double moneyCost = round(schematic.regenCost.money, 2); + Economy economy = IridiumSkyblock.getInstance().getEconomy(); + for (String bankItem : schematic.regenCost.bankItems.keySet()) { + double cost = round(schematic.regenCost.bankItems.get(bankItem), 2); + if (getBankBalance(player, bankItem) < cost) return false; } - economy.withdrawPlayer(player, moneyCost); + return moneyCost == 0 || economy != null && economy.getBalance(player) >= moneyCost; + } - IridiumSkyblock.getInstance().getSchematics().successSound.play(player); + private void purchase(Player player, Schematics.SchematicConfig schematic) { + double moneyCost = round(schematic.regenCost.money, 2); + IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, moneyCost); - return true; + for (String bankItem : schematic.regenCost.bankItems.keySet()) { + double cost = round(schematic.regenCost.bankItems.get(bankItem), 2); + setBankBalance(player, bankItem, getBankBalance(player, bankItem) - cost); + } } private double round(double value, int places) { From 65c6c1417db85ae431fe77ed7027b98b680056d0 Mon Sep 17 00:00:00 2001 From: Peaches_MLG Date: Sat, 21 Oct 2023 13:05:08 +0100 Subject: [PATCH 11/12] boop --- .../iridiumskyblock/configs/Schematics.java | 83 +++++++------------ .../managers/SchematicManager.java | 3 +- 2 files changed, 30 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java b/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java index 4ea8c40d6..ffa0f0d64 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java @@ -15,60 +15,35 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class Schematics { - public Map schematics; - public String buyPriceLore; - public String notPurchasableLore; - public boolean abbreviatePrices; - public XSound failSound; - public XSound successSound; - public List schematicPurchaseLore; - - public Schematics() { - this("&c"); - } - - public Schematics(String color) { - schematics = ImmutableMap.builder() - .put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&9&lDesert Island", Collections.singletonList("&7A starter desert island.")), - new Schematics.Cost(0, new HashMap<>()), -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT, - "desert.schem", 90.0, true - ), new SchematicWorld(Biome.NETHER_WASTES, - "desert_nether.schem", 90.0, true - ), new SchematicWorld(Biome.THE_END, - "desert_end.schem", 90.0, true - ))) - .put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&9&lJungle Island", Collections.singletonList("&7A starter jungle island.")), - new Schematics.Cost(0, new HashMap<>()), 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE, - "jungle.schem", 90.0, true - ), new SchematicWorld(Biome.NETHER_WASTES, - "jungle_nether.schem", 90.0, true - ), new SchematicWorld(Biome.THE_END, - "jungle_end.schem", 90.0, true - ))) - .put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&9&lMushroom Island", Collections.singletonList("&7A starter mushroom island.")), - new Schematics.Cost(0, new HashMap<>()), 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS, - "mushroom.schem", 90.0, true - ), new SchematicWorld(Biome.NETHER_WASTES, - "mushroom_nether.schem", 90.0, true - ), new SchematicWorld(Biome.THE_END, - "mushroom_end.schem", 90.0, true - ))) - .build(); - - buyPriceLore = "&aBuy Price: $%vault_cost%"; - notPurchasableLore = "&cThis item cannot be purchased!"; - - abbreviatePrices = true; - - failSound = XSound.BLOCK_ANVIL_LAND; - successSound = XSound.ENTITY_PLAYER_LEVELUP; - - schematicPurchaseLore = Arrays.asList( - " ", - color + "&l[!] " + color + "Left-Click to Purchase %amount%, Shift for 64", - color + "&l[!] " + color + "Right Click to Sell %amount%, Shift for 64" - ); - } + public Map schematics = ImmutableMap.builder() + .put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&9&lDesert Island", Arrays.asList("&7A starter desert island.", "", "&9&l[!] &7Costs $1000")), + new Schematics.Cost(1000, new HashMap<>()), -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT, + "desert.schem", 90.0, true + ), new SchematicWorld(Biome.NETHER_WASTES, + "desert_nether.schem", 90.0, true + ), new SchematicWorld(Biome.THE_END, + "desert_end.schem", 90.0, true + ))) + .put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&9&lJungle Island", Arrays.asList("&7A starter jungle island.", "", "&9&l[!] &7Costs $1000")), + new Schematics.Cost(1000, new HashMap<>()), 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE, + "jungle.schem", 90.0, true + ), new SchematicWorld(Biome.NETHER_WASTES, + "jungle_nether.schem", 90.0, true + ), new SchematicWorld(Biome.THE_END, + "jungle_end.schem", 90.0, true + ))) + .put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&9&lMushroom Island", Arrays.asList("&7A starter mushroom island.", "", "&9&l[!] &7Costs $1000")), + new Schematics.Cost(1000, new HashMap<>()), 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS, + "mushroom.schem", 90.0, true + ), new SchematicWorld(Biome.NETHER_WASTES, + "mushroom_nether.schem", 90.0, true + ), new SchematicWorld(Biome.THE_END, + "mushroom_end.schem", 90.0, true + ))) + .build(); + public boolean abbreviatePrices = true; + public XSound failSound = XSound.BLOCK_ANVIL_LAND; + public XSound successSound = XSound.ENTITY_PLAYER_LEVELUP; @NoArgsConstructor @AllArgsConstructor diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java index 1ae261667..ffe594ce0 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/SchematicManager.java @@ -139,8 +139,6 @@ public boolean buy(Player player, Schematics.SchematicConfig schematic) { purchase(player, schematic); - IridiumSkyblock.getInstance().getShop().successSound.play(player); - List bankPlaceholders = IridiumSkyblock.getInstance().getBankItemList().stream() .map(BankItem::getName) .map(name -> new Placeholder(name + "_cost", formatPrice(getBankBalance(player, name)))) @@ -192,6 +190,7 @@ private void purchase(Player player, Schematics.SchematicConfig schematic) { double cost = round(schematic.regenCost.bankItems.get(bankItem), 2); setBankBalance(player, bankItem, getBankBalance(player, bankItem) - cost); } + IridiumSkyblock.getInstance().getSchematics().successSound.play(player); } private double round(double value, int places) { From 01213c744b06e19b636b7f29442d76c8f47e35a0 Mon Sep 17 00:00:00 2001 From: Peaches_MLG Date: Sat, 21 Oct 2023 13:05:09 +0100 Subject: [PATCH 12/12] Update src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java --- .../java/com/iridium/iridiumskyblock/commands/RegenCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index 777072bc7..f54c148b4 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -47,7 +47,7 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams