Search in sources :

Example 1 with IslandUpgradesGUI

use of com.iridium.iridiumskyblock.gui.IslandUpgradesGUI in project IridiumSkyblock by Iridium-Development.

the class UpgradesCommand 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).
 * Shows an overview over the members of the Island and allows quick rank management.
 *
 * @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;
    }
    if (args.length != 2) {
        player.openInventory(new IslandUpgradesGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
        return true;
    }
    String upgradeName = args[1];
    Upgrade<?> upgrade = IridiumSkyblock.getInstance().getUpgradesList().get(upgradeName);
    if (upgrade == null) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownUpgrade.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), upgradeName);
    UpgradeData upgradeData = upgrade.upgrades.get(islandUpgrade.getLevel() + 1);
    if (upgradeData == null) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().maxLevelReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!PlayerUtils.pay(player, island.get(), upgradeData.crystals, upgradeData.money)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    islandUpgrade.setLevel(islandUpgrade.getLevel() + 1);
    IslandLog islandLog = new IslandLog(island.get(), LogAction.UPGRADE_PURCHASE, user, null, 0, upgradeName);
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    IridiumSkyblock.getInstance().getIslandManager().sendIslandBorder(island.get());
    island.get().resetCache();
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().successfullyBoughtUpgrade.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%upgrade%", upgrade.name).replace("%vault_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(upgradeData.money)).replace("%crystal_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(upgradeData.crystals))));
    return true;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) UpgradeData(com.iridium.iridiumskyblock.upgrades.UpgradeData) IslandUpgradesGUI(com.iridium.iridiumskyblock.gui.IslandUpgradesGUI) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)1 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)1 IslandUpgrade (com.iridium.iridiumskyblock.database.IslandUpgrade)1 User (com.iridium.iridiumskyblock.database.User)1 IslandUpgradesGUI (com.iridium.iridiumskyblock.gui.IslandUpgradesGUI)1 UpgradeData (com.iridium.iridiumskyblock.upgrades.UpgradeData)1 Player (org.bukkit.entity.Player)1