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