Search in sources :

Example 11 with IslandLog

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

the class IslandLogsGUI method setItemStack.

public void setItemStack(Inventory inventory, Item item, int page, LogAction... logActions) {
    ItemStack itemStack = ItemStackUtils.makeItem(item, new PlaceholderBuilder().applyIslandPlaceholders(getIsland()).build());
    ItemMeta itemMeta = itemStack.getItemMeta();
    List<String> lore = new ArrayList<>();
    List<IslandLog> islandLogs = IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().getEntries(getIsland()).stream().filter(islandLog -> Arrays.stream(logActions).anyMatch(logAction -> logAction.equals(islandLog.getLogAction()))).sorted(Comparator.comparing(IslandLog::getTime).reversed()).collect(Collectors.toList());
    int index = 0;
    for (IslandLog islandLog : islandLogs) {
        if ((page - 1) * 10 <= index && page * 10 > index) {
            long time = (System.currentTimeMillis() - islandLog.getTime()) / 1000L;
            int days = (int) TimeUnit.SECONDS.toDays(time);
            int hours = (int) Math.floor(TimeUnit.SECONDS.toHours(time - days * 86400L));
            int minutes = (int) Math.floor((time - (days * 86400) - (hours * 3600)) / 60.0D);
            int seconds = (int) Math.floor((time - (days * 86400) - (hours * 3600)) % 60.0D);
            lore.add(StringUtils.color(getLore(islandLog.getLogAction()).replace("%type%", islandLog.getData()).replace("%amount%", String.valueOf(islandLog.getAmount())).replace("%user%", islandLog.getUser().getName())).replace("%target%", islandLog.getTarget().getName()).replace("%seconds%", String.valueOf(seconds)).replace("%minutes%", String.valueOf(minutes)).replace("%hours%", String.valueOf(hours)).replace("%days%", String.valueOf(days)));
        }
        index++;
    }
    if (itemMeta.getLore() != null) {
        lore.addAll(itemMeta.getLore());
    }
    int maxPage = (int) Math.ceil(islandLogs.size() / 10.00);
    itemMeta.setLore(lore.stream().map(loreLine -> loreLine.replace("%current_page%", String.valueOf(page)).replace("%max_page%", String.valueOf(maxPage > 0 ? maxPage : 1))).collect(Collectors.toList()));
    itemStack.setItemMeta(itemMeta);
    inventory.setItem(item.slot, itemStack);
}
Also used : ClickType(org.bukkit.event.inventory.ClickType) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Arrays(java.util.Arrays) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) Item(com.iridium.iridiumcore.Item) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Collectors(java.util.stream.Collectors) Inventory(org.bukkit.inventory.Inventory) StringUtils(com.iridium.iridiumcore.utils.StringUtils) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) LogAction(com.iridium.iridiumskyblock.LogAction) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) LogInventoryConfig(com.iridium.iridiumskyblock.configs.inventories.LogInventoryConfig) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 12 with IslandLog

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

the class PromoteCommand 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).
 * Promotes a user in the Island rank system.
 *
 * @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 != 2) {
        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;
    }
    OfflinePlayer targetPlayer = Bukkit.getServer().getOfflinePlayer(args[1]);
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    if (!island.get().equals(targetUser.getIsland().orElse(null))) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandRank nextRank = IslandRank.getByLevel(targetUser.getIslandRank().getLevel() + 1);
    if (nextRank == null || nextRank.getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.PROMOTE)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotPromoteUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    UserPromoteEvent userPromoteEvent = new UserPromoteEvent(island.get(), user, nextRank);
    Bukkit.getPluginManager().callEvent(userPromoteEvent);
    if (userPromoteEvent.isCancelled())
        return false;
    targetUser.setIslandRank(nextRank);
    for (User member : island.get().getMembers()) {
        Player islandMember = Bukkit.getPlayer(member.getUuid());
        if (islandMember != null) {
            if (islandMember.equals(player)) {
                islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().promotedPlayer.replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            } else {
                islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userPromotedPlayer.replace("%promoter%", player.getName()).replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            }
        }
    }
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_PROMOTED, user, targetUser, 0, nextRank.getDisplayName());
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) UserPromoteEvent(com.iridium.iridiumskyblock.api.UserPromoteEvent) IslandRank(com.iridium.iridiumskyblock.IslandRank) OfflinePlayer(org.bukkit.OfflinePlayer) Island(com.iridium.iridiumskyblock.database.Island)

Example 13 with IslandLog

use of com.iridium.iridiumskyblock.database.IslandLog 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)

Example 14 with IslandLog

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

the class Reward method claim.

/**
 * Claims this reward for the provided user and island.
 * Sets the experience, executes the commands and plays the sound.
 *
 * @param player The Player which should receive the reward
 * @param island The Island of the Player
 */
public void claim(Player player, Island island) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    island.setExperience(island.getTotalExperience() + islandExperience);
    commands.forEach(command -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("%player%", player.getName())));
    sound.play(player);
    IslandBank islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
    IslandBank islandExperience = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().experienceBankItem);
    IslandBank islandMoney = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().moneyBankItem);
    islandCrystals.setNumber(islandCrystals.getNumber() + crystals);
    islandExperience.setNumber(islandExperience.getNumber() + experience);
    islandMoney.setNumber(islandMoney.getNumber() + money);
    IslandLog islandLog = new IslandLog(island, LogAction.REWARD_REDEEMED, user, null, 0, ChatColor.stripColor(item.displayName));
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) User(com.iridium.iridiumskyblock.database.User)

Aggregations

IslandLog (com.iridium.iridiumskyblock.database.IslandLog)14 Island (com.iridium.iridiumskyblock.database.Island)13 User (com.iridium.iridiumskyblock.database.User)13 Player (org.bukkit.entity.Player)12 OfflinePlayer (org.bukkit.OfflinePlayer)4 StringUtils (com.iridium.iridiumcore.utils.StringUtils)3 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)3 LogAction (com.iridium.iridiumskyblock.LogAction)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IslandRank (com.iridium.iridiumskyblock.IslandRank)2 BankItem (com.iridium.iridiumskyblock.bank.BankItem)2 IslandInvite (com.iridium.iridiumskyblock.database.IslandInvite)2 IslandTrusted (com.iridium.iridiumskyblock.database.IslandTrusted)2 IslandUpgrade (com.iridium.iridiumskyblock.database.IslandUpgrade)2 Duration (java.time.Duration)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2 CommandSender (org.bukkit.command.CommandSender)2 Item (com.iridium.iridiumcore.Item)1