Search in sources :

Example 1 with BankItem

use of com.iridium.iridiumskyblock.bank.BankItem in project IridiumSkyblock by Iridium-Development.

the class IslandBankGUI method onInventoryClick.

/**
 * Called when there is a click in this GUI.
 * Cancelled automatically.
 *
 * @param event The InventoryClickEvent provided by Bukkit
 */
@Override
public void onInventoryClick(InventoryClickEvent event) {
    Optional<BankItem> bankItemOptional = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getItem().slot == event.getSlot()).findFirst();
    if (!bankItemOptional.isPresent())
        return;
    BankItem bankItem = bankItemOptional.get();
    IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(getIsland(), bankItem);
    switch(event.getClick()) {
        case LEFT:
            IridiumSkyblock.getInstance().getCommands().withdrawCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(bankItem.getDefaultAmount()) });
            break;
        case SHIFT_LEFT:
            IridiumSkyblock.getInstance().getCommands().withdrawCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(islandBank.getNumber()) });
            break;
        case RIGHT:
            IridiumSkyblock.getInstance().getCommands().depositCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(bankItem.getDefaultAmount()) });
            break;
        case SHIFT_RIGHT:
            IridiumSkyblock.getInstance().getCommands().depositCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(islandBank.getNumber()) });
            break;
    }
    addContent(event.getInventory());
}
Also used : BankItem(com.iridium.iridiumskyblock.bank.BankItem) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Island(com.iridium.iridiumskyblock.database.Island) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Placeholder(com.iridium.iridiumcore.utils.Placeholder) Inventory(org.bukkit.inventory.Inventory) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) BankItem(com.iridium.iridiumskyblock.bank.BankItem)

Example 2 with BankItem

use of com.iridium.iridiumskyblock.bank.BankItem in project IridiumSkyblock by Iridium-Development.

the class IslandBankGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
    for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) {
        IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(getIsland(), bankItem);
        inventory.setItem(bankItem.getItem().slot, ItemStackUtils.makeItem(bankItem.getItem(), Collections.singletonList(new Placeholder("amount", IridiumSkyblock.getInstance().getNumberFormatter().format(islandBank.getNumber())))));
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Placeholder(com.iridium.iridiumcore.utils.Placeholder) BankItem(com.iridium.iridiumskyblock.bank.BankItem)

Example 3 with BankItem

use of com.iridium.iridiumskyblock.bank.BankItem in project IridiumSkyblock by Iridium-Development.

the class WithdrawCommand 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).
 * Withdraws a currency from the Island bank.
 *
 * @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 != 3) {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    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;
    }
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.WITHDRAW_BANK)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotWithdraw.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[1])).findFirst();
    if (!bankItem.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    try {
        double amount = bankItem.get().withdraw(player, Double.parseDouble(args[2]));
        if (amount > 0) {
            IslandLog islandLog = new IslandLog(island.get(), LogAction.BANK_WITHDRAW, user, null, amount, bankItem.get().getName());
            IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
        }
        return true;
    } catch (NumberFormatException exception) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) LogAction(com.iridium.iridiumskyblock.LogAction) BankItem(com.iridium.iridiumskyblock.bank.BankItem) List(java.util.List) PermissionType(com.iridium.iridiumskyblock.PermissionType) Duration(java.time.Duration) Optional(java.util.Optional) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) BankItem(com.iridium.iridiumskyblock.bank.BankItem) Island(com.iridium.iridiumskyblock.database.Island)

Example 4 with BankItem

use of com.iridium.iridiumskyblock.bank.BankItem in project IridiumSkyblock by Iridium-Development.

the class RemoveCommand 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(islandBank.getNumber() - Double.parseDouble(args[4]), 0));
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().removedBank.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 5 with BankItem

use of com.iridium.iridiumskyblock.bank.BankItem in project IridiumSkyblock by Iridium-Development.

the class DepositCommand 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).
 * Deposits a currency into the Island bank.
 *
 * @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 != 3) {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    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;
    }
    Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[1])).findFirst();
    if (!bankItem.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    try {
        double amount = bankItem.get().deposit(player, Double.parseDouble(args[2]));
        if (amount > 0) {
            IslandLog islandLog = new IslandLog(island.get(), LogAction.BANK_DEPOSIT, user, null, amount, bankItem.get().getName());
            IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
        }
        return true;
    } catch (NumberFormatException exception) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) LogAction(com.iridium.iridiumskyblock.LogAction) BankItem(com.iridium.iridiumskyblock.bank.BankItem) List(java.util.List) Duration(java.time.Duration) Optional(java.util.Optional) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) BankItem(com.iridium.iridiumskyblock.bank.BankItem) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

BankItem (com.iridium.iridiumskyblock.bank.BankItem)7 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)6 Island (com.iridium.iridiumskyblock.database.Island)6 Collections (java.util.Collections)6 Optional (java.util.Optional)6 StringUtils (com.iridium.iridiumcore.utils.StringUtils)5 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)5 User (com.iridium.iridiumskyblock.database.User)5 Duration (java.time.Duration)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 CommandSender (org.bukkit.command.CommandSender)5 Command (com.iridium.iridiumskyblock.commands.Command)3 PlayerUtils (com.iridium.iridiumskyblock.utils.PlayerUtils)3 Bukkit (org.bukkit.Bukkit)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Placeholder (com.iridium.iridiumcore.utils.Placeholder)2 LogAction (com.iridium.iridiumskyblock.LogAction)2 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)2 Player (org.bukkit.entity.Player)2