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;
}
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));
}
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;
}
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;
}
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;
}
Aggregations