Search in sources :

Example 6 with IslandBank

use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.

the class CrystalsBankItem method withdraw.

/**
 * Withdraws the given amount of this item from the Player's bank.
 *
 * @param player The player who wants to withdraw
 * @param amount The amount which should be withdrawn
 */
@Override
public double withdraw(Player player, Number amount) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (island.isPresent()) {
        IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), this);
        int crystals = Math.min(amount.intValue(), (int) islandBank.getNumber());
        if (crystals > 0) {
            islandBank.setNumber(islandBank.getNumber() - crystals);
            player.getInventory().addItem(IridiumSkyblock.getInstance().getIslandManager().getIslandCrystal(crystals)).values().forEach(itemStack -> player.getWorld().dropItem(player.getLocation(), itemStack));
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankWithdrew.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%amount%", String.valueOf(crystals)).replace("%type%", getDisplayName()));
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().insufficientFundsToWithdrew.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%type%", getDisplayName()));
        }
        return crystals;
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return 0;
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island)

Example 7 with IslandBank

use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.

the class ExperienceBankItem method withdraw.

/**
 * Withdraws the given amount of this item from the Player's bank.
 *
 * @param player The player who wants to withdraw
 * @param amount The amount which should be withdrawn
 */
@Override
public double withdraw(Player player, Number amount) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (island.isPresent()) {
        IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), this);
        int experience = Math.min(amount.intValue(), (int) islandBank.getNumber());
        if (experience > 0) {
            islandBank.setNumber(islandBank.getNumber() - experience);
            PlayerUtils.setTotalExperience(player, PlayerUtils.getTotalExperience(player) + experience);
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankWithdrew.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%amount%", String.valueOf(experience)).replace("%type%", getDisplayName()));
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().insufficientFundsToWithdrew.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%type%", getDisplayName()));
        }
        return experience;
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return 0;
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island)

Example 8 with IslandBank

use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.

the class MoneyBankItem method deposit.

/**
 * Deposits the given amount of this item to the Player's bank.
 *
 * @param player The player who wants to deposit
 * @param amount The amount which should be deposited
 */
@Override
public double deposit(Player player, Number amount) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (island.isPresent()) {
        IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), this);
        double money = Math.min(amount.doubleValue(), IridiumSkyblock.getInstance().getEconomy().getBalance(player));
        if (money > 0) {
            islandBank.setNumber(islandBank.getNumber() + money);
            IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, money);
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankDeposited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%amount%", String.valueOf(money)).replace("%type%", getDisplayName()));
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().insufficientFundsToDeposit.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%type%", getDisplayName()));
        }
        return money;
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return 0;
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island)

Example 9 with IslandBank

use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.

the class MoneyBankItem method withdraw.

/**
 * Withdraws the given amount of this item from the Player's bank.
 *
 * @param player The player who wants to withdraw
 * @param amount The amount which should be withdrawn
 */
@Override
public double withdraw(Player player, Number amount) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (island.isPresent()) {
        IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), this);
        double money = Math.min(amount.doubleValue(), islandBank.getNumber());
        if (money > 0) {
            islandBank.setNumber(islandBank.getNumber() - money);
            IridiumSkyblock.getInstance().getEconomy().depositPlayer(player, money);
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankWithdrew.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%amount%", String.valueOf(money)).replace("%type%", getDisplayName()));
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().insufficientFundsToWithdrew.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%type%", getDisplayName()));
        }
        return money;
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return 0;
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island)

Example 10 with IslandBank

use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.

the class ShopManager method giveReward.

/**
 * Called when a player successfully sells an item in the shop.
 * Gives all rewards for that item to him.
 *
 * @param player The player who sold the item
 * @param item   The item that has been sold
 * @param amount The amount of that item
 */
public void giveReward(Player player, ShopItem item, int amount) {
    double vaultReward = calculateCost(amount, item.defaultAmount, item.sellReward.vault);
    int crystalReward = (int) calculateCost(amount, item.defaultAmount, item.sellReward.crystals);
    Island island = IridiumSkyblockAPI.getInstance().getUser(player).getIsland().get();
    IslandBank moneyIslandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().moneyBankItem);
    IslandBank crystalIslandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
    moneyIslandBank.setNumber(moneyIslandBank.getNumber() + vaultReward);
    crystalIslandBank.setNumber(crystalIslandBank.getNumber() + crystalReward);
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().successfullySold.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%amount%", String.valueOf(amount)).replace("%item%", StringUtils.color(item.name)).replace("%vault_reward%", String.valueOf(vaultReward)).replace("%crystal_reward%", String.valueOf(crystalReward))));
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

IslandBank (com.iridium.iridiumskyblock.database.IslandBank)16 Island (com.iridium.iridiumskyblock.database.Island)11 User (com.iridium.iridiumskyblock.database.User)10 BankItem (com.iridium.iridiumskyblock.bank.BankItem)5 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)4 Collections (java.util.Collections)4 Optional (java.util.Optional)4 StringUtils (com.iridium.iridiumcore.utils.StringUtils)3 Command (com.iridium.iridiumskyblock.commands.Command)3 PlayerUtils (com.iridium.iridiumskyblock.utils.PlayerUtils)3 Duration (java.time.Duration)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Bukkit (org.bukkit.Bukkit)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 CommandSender (org.bukkit.command.CommandSender)3 Placeholder (com.iridium.iridiumcore.utils.Placeholder)2 Economy (net.milkbowl.vault.economy.Economy)2 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)1 InventoryUtils (com.iridium.iridiumcore.utils.InventoryUtils)1