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