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