Search in sources :

Example 26 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class VoteToday method onChest.

@Override
public void onChest(Player player) {
    BInventory inv = new BInventory(plugin.getGui().getChestVoteTodayName());
    if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
        inv.dontClose();
    }
    for (TopVoterPlayer user : plugin.getVoteToday().keySet()) {
        for (VoteSite voteSite : plugin.getVoteToday().get(user).keySet()) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
            String timeString = plugin.getVoteToday().get(user).get(voteSite).format(formatter);
            String msg = plugin.getGui().getChestVoteTodayLine();
            HashMap<String, String> placeholders = new HashMap<String, String>();
            placeholders.put("VoteSite", voteSite.getDisplayName());
            placeholders.put("Time", timeString);
            msg = StringParser.getInstance().replacePlaceHolder(msg, placeholders);
            ItemBuilder item = null;
            if (plugin.getGui().isChestVoteTodayUseSkull() && !NMSManager.getInstance().isVersion("1.12")) {
                item = new ItemBuilder(user.getPlayerHead());
            } else {
                item = new ItemBuilder(plugin.getGui().getChestVoteTodayPlayerItem());
            }
            item.setName(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getChestVoteTodayIconTitle(), "player", user.getPlayerName()));
            item.setLore(msg);
            final UUID uuid = user.getUuid();
            inv.addButton(inv.getNextSlot(), new BInventoryButton(item) {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(uuid);
                    new VoteGUI(plugin, player, user).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
                }
            });
        }
    }
    if (plugin.getGui().getChestVoteTodayBackButton()) {
        inv.addButton(plugin.getCommandLoader().getBackButton(user));
    }
    inv.openInventory(player);
}
Also used : HashMap(java.util.HashMap) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) VoteSite(com.bencodez.votingplugin.objects.VoteSite) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) UUID(java.util.UUID) DateTimeFormatter(java.time.format.DateTimeFormatter) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 27 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class VoteURL method getChat.

@Override
public ArrayList<String> getChat(CommandSender arg0) {
    ArrayList<String> sites = new ArrayList<String>();
    List<String> title = plugin.getConfigFile().getFormatCommandsVoteText();
    if (title != null) {
        sites.addAll(title);
    }
    if (plugin.getConfigFile().getFormatCommandsVoteAutoInputSites()) {
        int counter = 0;
        for (VoteSite voteSite : plugin.getVoteSites()) {
            if (!voteSite.isHidden()) {
                counter++;
                String voteURL = voteSite.getVoteURL(json);
                MessageBuilder message = new MessageBuilder(plugin.getConfigFile().getFormatCommandsVoteURLS());
                message.replacePlaceholder("num", Integer.toString(counter)).replacePlaceholder("url", voteURL).replacePlaceholder("SiteName", voteSite.getDisplayName());
                if (user != null && user.getPlayerName() != null) {
                    message.replacePlaceholder("player", "" + user.getPlayerName()).replacePlaceholder("Next", "" + user.voteCommandNextInfo(voteSite));
                }
                sites.add(message.colorize().getText());
            }
        }
    }
    if (user != null) {
        HashMap<String, String> phs = new HashMap<String, String>();
        phs.put("DailyTotal", "" + user.getTotal(TopVoter.Daily));
        phs.put("WeekTotal", "" + user.getTotal(TopVoter.Weekly));
        phs.put("MonthTotal", "" + user.getTotal(TopVoter.Monthly));
        phs.put("Total", "" + user.getTotal(TopVoter.AllTime));
        sites = ArrayUtils.getInstance().replacePlaceHolder(sites, phs);
    }
    return ArrayUtils.getInstance().colorize(sites);
}
Also used : VoteSite(com.bencodez.votingplugin.objects.VoteSite) MessageBuilder(com.bencodez.advancedcore.api.messages.MessageBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 28 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class VoteURL method onBook.

@Override
public void onBook(Player player) {
    BookWrapper book = new BookWrapper(plugin.getGui().getBookVoteURLBookGUITitle());
    for (VoteSite site : plugin.getVoteSites()) {
        Layout layout = new Layout(plugin.getGui().getBookVoteURLBookGUILayout()).addPlaceholder("sitename", site.getDisplayName());
        String text = plugin.getGui().getBookVoteURLBookGUIAlreadyVotedText();
        ChatColor color = ChatColor.valueOf(plugin.getGui().getBookVoteURLBookGUIAlreadyVotedColor());
        if (user.canVoteSite(site)) {
            color = ChatColor.valueOf(plugin.getGui().getBookVoteURLBookGUICanVoteColor());
            text = plugin.getGui().getBookVoteURLBookGUICanVoteText();
        }
        String url = StringParser.getInstance().replacePlaceHolder(site.getVoteURLJsonStrip(), "player", user.getPlayerName());
        layout.replaceTextComponent("[UrlText]", BookUtil.TextBuilder.of(text).color(color).onClick(BookUtil.ClickAction.openUrl(url)).onHover(BookUtil.HoverAction.showText(url)).build());
        book.addLayout(layout);
    }
    book.open(player);
}
Also used : BookWrapper(com.bencodez.advancedcore.api.bookgui.BookWrapper) VoteSite(com.bencodez.votingplugin.objects.VoteSite) Layout(com.bencodez.advancedcore.api.bookgui.Layout) ChatColor(org.bukkit.ChatColor)

Aggregations

VoteSite (com.bencodez.votingplugin.objects.VoteSite)28 ArrayList (java.util.ArrayList)15 Player (org.bukkit.entity.Player)10 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)9 VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)9 HashMap (java.util.HashMap)9 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)7 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)7 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)7 TopVoterPlayer (com.bencodez.votingplugin.topvoter.TopVoterPlayer)6 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)5 UpdatingBInventoryButton (com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton)4 PlayerVoteEvent (com.bencodez.votingplugin.events.PlayerVoteEvent)4 DateTimeFormatter (java.time.format.DateTimeFormatter)4 LinkedHashMap (java.util.LinkedHashMap)4 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)3 LocalDateTime (java.time.LocalDateTime)3 BookWrapper (com.bencodez.advancedcore.api.bookgui.BookWrapper)2 Layout (com.bencodez.advancedcore.api.bookgui.Layout)2 EditGUI (com.bencodez.advancedcore.api.inventory.editgui.EditGUI)2