Skip to content

Commit

Permalink
Fixed stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG committed Oct 21, 2023
1 parent 5d6c1a7 commit 75fa917
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ public CompletableFuture<Island> createTeam(@NotNull Player owner, String name)
User user = IridiumSkyblock.getInstance().getUserManager().getUser(owner);
Schematics.SchematicConfig schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.get(schematic);

if(schematicConfig.regenCost.money != 0 || !schematicConfig.regenCost.bankItems.isEmpty()) {
if(!IridiumSkyblock.getInstance().getSchematicManager().buy(owner, schematicConfig)) {
return null;
}
}

IslandCreateEvent islandCreateEvent = getIslandCreateEvent(user, name, schematicConfig).join();
if (islandCreateEvent.isCancelled()) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,11 @@ public boolean buy(Player player, Schematics.SchematicConfig schematic) {
.map(name -> new Placeholder(name + "_cost", formatPrice(getBankBalance(player, name))))
.collect(Collectors.toList());

double moneyCost = round(schematic.regenCost.money, 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)),
.replace("%vault_cost%", formatPrice(schematic.regenCost.money)),
bankPlaceholders)
));
return true;
Expand All @@ -172,22 +170,22 @@ private void setBankBalance(Player player, String bankItem, double amount) {
}

private boolean canPurchase(Player player, Schematics.SchematicConfig schematic) {
double moneyCost = round(schematic.regenCost.money, 2);
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);
double cost = schematic.regenCost.bankItems.get(bankItem);
if (getBankBalance(player, bankItem) < cost) return false;
}

return moneyCost == 0 || economy != null && economy.getBalance(player) >= moneyCost;
}

private void purchase(Player player, Schematics.SchematicConfig schematic) {
double moneyCost = round(schematic.regenCost.money, 2);
double moneyCost = schematic.regenCost.money;
IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, moneyCost);

for (String bankItem : schematic.regenCost.bankItems.keySet()) {
double cost = round(schematic.regenCost.bankItems.get(bankItem), 2);
double cost = schematic.regenCost.bankItems.get(bankItem);
setBankBalance(player, bankItem, getBankBalance(player, bankItem) - cost);
}
IridiumSkyblock.getInstance().getSchematics().successSound.play(player);
Expand All @@ -200,6 +198,7 @@ private double round(double value, int places) {
}

public String formatPrice(double value) {
value = round(value, 2);
if (IridiumSkyblock.getInstance().getSchematics().abbreviatePrices) {
return IridiumSkyblock.getInstance().getConfiguration().numberFormatter.format(value);
}
Expand Down

0 comments on commit 75fa917

Please sign in to comment.