use of com.iridium.iridiumskyblock.database.User 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.User 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.User in project IridiumSkyblock by Iridium-Development.
the class PublicCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Makes the user's Island visitable.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
island.get().setVisitable(true);
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandNowPublic.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return true;
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class RewardsCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Opens the Island rewards GUI.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
player.openInventory(new IslandRewardsGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
return true;
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class AddCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length < 4) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> optionalIsland = user.getIsland();
if (!optionalIsland.isPresent()) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException exception) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Island island = optionalIsland.get();
island.setExtraValue(island.getExtraValue() + amount);
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().extraValueSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%amount%", String.valueOf(island.getExtraValue()))));
return true;
}
Aggregations