Search in sources :

Example 11 with IslandBank

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

the class PlayerUtils method pay.

/**
 * Removes the specified amount of crystals and money from the island bank and from
 * the player's purse if there is not enough in the bank.
 *
 * @param player   The Player
 * @param island   The Player's Island
 * @param crystals The amount of crystals
 * @param money    The amount of money
 * @return If the purchase was successful. {@link PlayerUtils#canPurchase(Player, Island, int, double)} should be preferred.
 */
public static boolean pay(@NotNull Player player, @NotNull Island island, int crystals, double money) {
    // Don't withdraw stuff if they can't purchase it.
    if (!canPurchase(player, island, crystals, money)) {
        return false;
    }
    IslandBank islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
    IslandBank islandMoney = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().moneyBankItem);
    Economy economy = IridiumSkyblock.getInstance().getEconomy();
    islandCrystals.setNumber(islandCrystals.getNumber() - crystals);
    if (islandMoney.getNumber() >= money) {
        islandMoney.setNumber(islandMoney.getNumber() - money);
    } else {
        economy.withdrawPlayer(player, money);
    }
    return true;
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Economy(net.milkbowl.vault.economy.Economy)

Example 12 with IslandBank

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

the class PlayerUtils method canPurchase.

/**
 * Check if the player has enough money and crystals to buy something.
 *
 * @param player   The Player
 * @param island   The Player's Island
 * @param crystals The crystals being spent
 * @param money    The money being spent.
 * @return If they can purchase the item
 */
public static boolean canPurchase(@NotNull Player player, @NotNull Island island, int crystals, double money) {
    IslandBank islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
    IslandBank islandMoney = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().moneyBankItem);
    Economy economy = IridiumSkyblock.getInstance().getEconomy();
    return islandCrystals.getNumber() >= crystals && (islandMoney.getNumber() >= money || (economy != null && economy.getBalance(player) >= money));
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Economy(net.milkbowl.vault.economy.Economy)

Example 13 with IslandBank

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

the class ExperienceBankItem 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);
        int experience = Math.min(amount.intValue(), PlayerUtils.getTotalExperience(player));
        if (experience > 0) {
            islandBank.setNumber(islandBank.getNumber() + experience);
            PlayerUtils.setTotalExperience(player, PlayerUtils.getTotalExperience(player) - experience);
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankDeposited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%amount%", String.valueOf(experience)).replace("%type%", getDisplayName()));
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().insufficientFundsToDeposit.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 14 with IslandBank

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

the class GiveCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) {
    if (args.length == 5) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
        Optional<Island> island = user.getIsland();
        if (island.isPresent()) {
            Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[3])).findFirst();
            if (bankItem.isPresent()) {
                try {
                    IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), bankItem.get());
                    islandBank.setNumber(islandBank.getNumber() + Double.parseDouble(args[4]));
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().gaveBank.replace("%player%", player.getName()).replace("%amount%", args[4]).replace("%item%", bankItem.get().getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                    return true;
                } catch (NumberFormatException exception) {
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            } else {
                sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            }
        } else {
            sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    } else {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return false;
}
Also used : CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) List(java.util.List) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Duration(java.time.Duration) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) Optional(java.util.Optional) Command(com.iridium.iridiumskyblock.commands.Command) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Bukkit(org.bukkit.Bukkit) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) Island(com.iridium.iridiumskyblock.database.Island)

Example 15 with IslandBank

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

the class SetCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) {
    if (args.length == 5) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
        Optional<Island> island = user.getIsland();
        if (island.isPresent()) {
            Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[3])).findFirst();
            if (bankItem.isPresent()) {
                try {
                    IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), bankItem.get());
                    islandBank.setNumber(Math.max(Double.parseDouble(args[4]), 0));
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().setBank.replace("%player%", player.getName()).replace("%amount%", args[4]).replace("%item%", bankItem.get().getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                    return true;
                } catch (NumberFormatException exception) {
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            } else {
                sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            }
        } else {
            sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    } else {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return false;
}
Also used : CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) List(java.util.List) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Duration(java.time.Duration) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) Optional(java.util.Optional) Command(com.iridium.iridiumskyblock.commands.Command) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Bukkit(org.bukkit.Bukkit) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) 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