Search in sources :

Example 1 with Booster

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

the class IslandBoostersGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
    for (Map.Entry<String, Booster> entry : IridiumSkyblock.getInstance().getBoosterList().entrySet()) {
        Item item = entry.getValue().item;
        IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(getIsland(), entry.getKey());
        long minutes = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.MINUTES);
        long seconds = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.SECONDS) - minutes * 60;
        inventory.setItem(item.slot, ItemStackUtils.makeItem(item, Arrays.asList(new Placeholder("timeremaining_minutes", String.valueOf(Math.max(minutes, 0))), new Placeholder("timeremaining_seconds", String.valueOf(Math.max(seconds, 0))), new Placeholder("crystalcost", IridiumSkyblock.getInstance().getNumberFormatter().format(entry.getValue().crystalsCost)), new Placeholder("vaultcost", IridiumSkyblock.getInstance().getNumberFormatter().format(entry.getValue().vaultCost)))));
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : Item(com.iridium.iridiumcore.Item) Placeholder(com.iridium.iridiumcore.utils.Placeholder) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) Booster(com.iridium.iridiumskyblock.Booster) Map(java.util.Map)

Example 2 with Booster

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

the class BoosterCommand 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 IslandBoostersGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
        return true;
    }
    String boosterName = args[1];
    Booster booster = IridiumSkyblock.getInstance().getBoosterList().get(boosterName);
    if (booster == null) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), boosterName);
    if (islandBooster.isActive() && !booster.stackable) {
        return false;
    }
    if (!PlayerUtils.pay(player, island.get(), booster.crystalsCost, booster.vaultCost)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    islandBooster.setTime(LocalDateTime.now().plusSeconds(booster.time + (islandBooster.isActive() && booster.stackable ? islandBooster.getRemainingTime() : 0)));
    IslandLog islandLog = new IslandLog(island.get(), LogAction.BOOSTER_PURCHASE, user, null, 0, boosterName);
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().successfullyBoughtBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%booster%", IridiumSkyblock.getInstance().getBoosterList().get(islandBooster.getBooster()).name).replace("%vault_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(booster.vaultCost)).replace("%crystal_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(booster.crystalsCost))));
    return true;
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) Booster(com.iridium.iridiumskyblock.Booster) Island(com.iridium.iridiumskyblock.database.Island) IslandBoostersGUI(com.iridium.iridiumskyblock.gui.IslandBoostersGUI)

Aggregations

Booster (com.iridium.iridiumskyblock.Booster)2 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)2 Item (com.iridium.iridiumcore.Item)1 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 Island (com.iridium.iridiumskyblock.database.Island)1 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)1 User (com.iridium.iridiumskyblock.database.User)1 IslandBoostersGUI (com.iridium.iridiumskyblock.gui.IslandBoostersGUI)1 Map (java.util.Map)1 Player (org.bukkit.entity.Player)1