Search in sources :

Example 1 with LogAction

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

Aggregations

Item (com.iridium.iridiumcore.Item)1 InventoryUtils (com.iridium.iridiumcore.utils.InventoryUtils)1 ItemStackUtils (com.iridium.iridiumcore.utils.ItemStackUtils)1 StringUtils (com.iridium.iridiumcore.utils.StringUtils)1 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)1 LogAction (com.iridium.iridiumskyblock.LogAction)1 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)1 LogInventoryConfig (com.iridium.iridiumskyblock.configs.inventories.LogInventoryConfig)1 Island (com.iridium.iridiumskyblock.database.Island)1 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 ClickType (org.bukkit.event.inventory.ClickType)1 InventoryClickEvent (org.bukkit.event.inventory.InventoryClickEvent)1 Inventory (org.bukkit.inventory.Inventory)1 ItemStack (org.bukkit.inventory.ItemStack)1