Search in sources :

Example 6 with PlaceholderBuilder

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

the class ChatCommand 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).
 * Chats with the sender's island members {@link Island}.
 *
 * @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;
    Optional<Island> island = IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland();
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (args.length > 1) {
        String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
        for (User user : island.get().getMembers()) {
            Player recipient = Bukkit.getPlayer(user.getUuid());
            if (recipient != null) {
                recipient.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandMemberChat, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%message%", message)));
            }
        }
    } else {
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
        UserChatToggleEvent userChatToggleEvent = new UserChatToggleEvent(user, !user.isIslandChat());
        Bukkit.getPluginManager().callEvent(userChatToggleEvent);
        if (userChatToggleEvent.isCancelled())
            return false;
        user.setIslandChat(!user.isIslandChat());
        player.sendMessage(StringUtils.color((user.isIslandChat() ? IridiumSkyblock.getInstance().getMessages().islandChatEnabled : IridiumSkyblock.getInstance().getMessages().islandChatDisabled).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) UserChatToggleEvent(com.iridium.iridiumskyblock.api.UserChatToggleEvent) User(com.iridium.iridiumskyblock.database.User) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island)

Example 7 with PlaceholderBuilder

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

the class IslandInvitesGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    List<IslandInvite> islandInvites = IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().getEntries(getIsland());
    inventory.clear();
    InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
    AtomicInteger slot = new AtomicInteger(0);
    for (int i = 0; i < islandInvites.size(); i++) {
        Bukkit.getScheduler().runTaskAsynchronously(IridiumSkyblock.getInstance(), () -> {
            int itemSlot = slot.getAndIncrement();
            List<Placeholder> placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(islandInvites.get(itemSlot).getUser()).applyIslandPlaceholders(getIsland()).build();
            placeholderList.add(new Placeholder("inviter", islandInvites.get(itemSlot).getInviter().getName()));
            placeholderList.add(new Placeholder("time", islandInvites.get(itemSlot).getTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))));
            inventory.setItem(itemSlot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandInvitesGUI.item, placeholderList));
            invites.put(itemSlot, islandInvites.get(itemSlot).getUser().getName());
        });
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : Placeholder(com.iridium.iridiumcore.utils.Placeholder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) IslandInvite(com.iridium.iridiumskyblock.database.IslandInvite)

Example 8 with PlaceholderBuilder

use of com.iridium.iridiumskyblock.PlaceholderBuilder 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 9 with PlaceholderBuilder

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

the class IslandTopGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    List<Island> islands = IridiumSkyblock.getInstance().getIslandManager().getIslands(IslandManager.SortType.VALUE);
    islandSlots.clear();
    inventory.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandTopGUI.background);
    for (int rank : IridiumSkyblock.getInstance().getConfiguration().islandTopSlots.keySet()) {
        int slot = IridiumSkyblock.getInstance().getConfiguration().islandTopSlots.get(rank);
        if (islands.size() >= rank) {
            Island island = islands.get(rank - 1);
            islandSlots.put(slot, island);
            inventory.setItem(slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandTopGUI.item, new PlaceholderBuilder().applyIslandPlaceholders(island).build()));
        } else {
            inventory.setItem(slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandTopGUI.filler));
        }
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island)

Example 10 with PlaceholderBuilder

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

the class IslandVisitorsGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
    inventory.setItem(inventory.getSize() - 3, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().nextPage));
    inventory.setItem(inventory.getSize() - 7, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().previousPage));
    final long elementsPerPage = inventory.getSize() - 9;
    AtomicInteger slot = new AtomicInteger(0);
    IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(getIsland()).stream().filter(user -> user.getIsland().map(Island::getId).orElse(0) != getIsland().getId()).skip((page - 1) * elementsPerPage).limit(elementsPerPage).forEachOrdered(user -> {
        visitors.add(user);
        List<Placeholder> placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(user).applyIslandPlaceholders(getIsland()).build();
        inventory.setItem(slot.getAndIncrement(), ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().visitorsGUI.item, placeholderList));
    });
}
Also used : ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) User(com.iridium.iridiumskyblock.database.User) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Player(org.bukkit.entity.Player) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) NotNull(org.jetbrains.annotations.NotNull) Placeholder(com.iridium.iridiumcore.utils.Placeholder) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Placeholder(com.iridium.iridiumcore.utils.Placeholder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Island (com.iridium.iridiumskyblock.database.Island)6 Placeholder (com.iridium.iridiumcore.utils.Placeholder)5 User (com.iridium.iridiumskyblock.database.User)5 Inventory (org.bukkit.inventory.Inventory)4 InventoryUtils (com.iridium.iridiumcore.utils.InventoryUtils)3 ItemStackUtils (com.iridium.iridiumcore.utils.ItemStackUtils)3 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)3 List (java.util.List)3 Player (org.bukkit.entity.Player)3 InventoryClickEvent (org.bukkit.event.inventory.InventoryClickEvent)3 NotNull (org.jetbrains.annotations.NotNull)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 Item (com.iridium.iridiumcore.Item)1 StringUtils (com.iridium.iridiumcore.utils.StringUtils)1 LogAction (com.iridium.iridiumskyblock.LogAction)1 UserChatToggleEvent (com.iridium.iridiumskyblock.api.UserChatToggleEvent)1 LogInventoryConfig (com.iridium.iridiumskyblock.configs.inventories.LogInventoryConfig)1