Search in sources :

Example 1 with TopVoter

use of com.Ben12345rocks.VotingPlugin.Objects.TopVoter in project VotingPlugin by Ben12345rocks.

the class PlayerGUIs method openVoteTop.

public void openVoteTop(Player player, TopVoter top) {
    if (top == null) {
        top = TopVoter.getDefault();
    }
    BInventory inv = null;
    Set<Entry<User, Integer>> users = null;
    String topVoter = "";
    if (top.equals(TopVoter.Monthly)) {
        topVoter = Config.getInstance().getFormatTopVoterMonthly();
        users = plugin.topVoterMonthly.entrySet();
    } else if (top.equals(TopVoter.Weekly)) {
        topVoter = Config.getInstance().getFormatTopVoterWeekly();
        users = plugin.topVoterWeekly.entrySet();
    } else if (top.equals(TopVoter.Daily)) {
        topVoter = Config.getInstance().getFormatTopVoterDaily();
        users = plugin.topVoterDaily.entrySet();
    } else {
        topVoter = Config.getInstance().getFormatTopVoterAllTime();
        users = plugin.topVoterAllTime.entrySet();
    }
    inv = new BInventory(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteTopName(), "topvoter", topVoter));
    int pos = 1;
    for (Entry<User, Integer> entry : users) {
        inv.addButton(new BInventoryButton(new ItemBuilder(MiscUtils.getInstance().setSkullOwner(entry.getKey().getOfflinePlayer())).setName(Config.getInstance().getGUIVoteTopItemName()).addLoreLine(Config.getInstance().getGUIVoteTopItemLore()).addPlaceholder("position", "" + pos).addPlaceholder("player", entry.getKey().getPlayerName()).addPlaceholder("votes", "" + entry.getValue())) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // ItemBuilder item = new ItemBuilder(clickEvent.getClickedItem());
                // String name = ChatColor.stripColor(item.getName()).split(":")[1].trim();
                String name = (String) clickEvent.getButton().getData("player");
                User user = UserManager.getInstance().getVotingPluginUser(name);
                openVoteGUI(player, user);
            }
        }.addData("player", entry.getKey().getPlayerName()));
        pos++;
    }
    final TopVoter cur = top;
    inv.getPageButtons().add(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteTopSwitchItem()).addPlaceholder("Top", topVoter)) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            if (!clickEvent.getClick().equals(ClickType.RIGHT)) {
                openVoteTop(player, cur.next());
            } else {
                openVoteTop(player, cur.prev());
            }
        }
    });
    if (Config.getInstance().getGUIVoteTopBackButton()) {
        inv.getPageButtons().add(new BInventoryButton(getBackButton().setSlot(1)) {

            @Override
            public void onClick(ClickEvent event) {
                openVoteGUI(event.getPlayer(), getSelectedPlayer(event.getPlayer()));
            }
        });
    }
    inv.setPages(true);
    inv.setMaxInvSize(Config.getInstance().getGUIVoteTopSize());
    inv.openInventory(player);
}
Also used : User(com.Ben12345rocks.VotingPlugin.Objects.User) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory) Entry(java.util.Map.Entry) ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) TopVoter(com.Ben12345rocks.VotingPlugin.Objects.TopVoter)

Aggregations

BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)1 ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)1 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)1 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)1 TopVoter (com.Ben12345rocks.VotingPlugin.Objects.TopVoter)1 User (com.Ben12345rocks.VotingPlugin.Objects.User)1 Entry (java.util.Map.Entry)1