Search in sources :

Example 6 with ItemBuilder

use of com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder in project VotingPlugin by Ben12345rocks.

the class PlayerGUIs method voteReward.

/**
 * Vote reward.
 *
 * @param player
 *            the player
 * @param siteName
 *            the site name
 */
public void voteReward(Player player, String siteName) {
    BInventory inv = new BInventory(Config.getInstance().getGUIVoteRewardName());
    if ((siteName == null) || (siteName == "")) {
        int count = 0;
        for (VoteSite voteSite : plugin.getVoteSites()) {
            try {
                ItemBuilder builder = voteSite.getItem();
                final VoteSite site = voteSite;
                inv.addButton(count, new BInventoryButton(builder) {

                    @Override
                    public void onClick(ClickEvent event) {
                        Player player = event.getWhoClicked();
                        if (player != null) {
                            player.closeInventory();
                            Bukkit.getScheduler().runTask(plugin, new Runnable() {

                                @Override
                                public void run() {
                                    player.performCommand("vote reward " + site.getKey());
                                }
                            });
                        }
                    }
                });
                count++;
            } catch (Exception ex) {
            }
        }
    } else {
        for (String itemName : Config.getInstance().getVoteSiteItems(siteName)) {
            ItemBuilder builder = new ItemBuilder(Config.getInstance().getVoteSiteItemsSection(siteName, itemName));
            inv.addButton(Config.getInstance().getVoteSiteItemsSlot(siteName, itemName), new BInventoryButton(builder) {

                @Override
                public void onClick(ClickEvent event) {
                    Player player = event.getWhoClicked();
                    if (player != null) {
                        player.closeInventory();
                    }
                }
            });
        }
    }
    inv.openInventory(player);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) Player(org.bukkit.entity.Player) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)

Example 7 with ItemBuilder

use of com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder in project VotingPlugin by Ben12345rocks.

the class PlayerGUIs method openVoteBest.

public void openVoteBest(Player player, User user) {
    setSelectedPlayer(player, user);
    BInventory inv = new BInventory(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteBestName(), "player", user.getPlayerName()));
    inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteBestDayBestItem()).addPlaceholder("Best", "" + user.getBestDayVoteStreak())) {

        @Override
        public void onClick(ClickEvent clickEvent) {
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteBestWeekBestItem()).addPlaceholder("Best", "" + user.getBestWeekVoteStreak())) {

        @Override
        public void onClick(ClickEvent clickEvent) {
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteBestMonthBestItem()).addPlaceholder("Best", "" + user.getBestMonthVoteStreak())) {

        @Override
        public void onClick(ClickEvent clickEvent) {
        }
    });
    inv.openInventory(player);
}
Also used : ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)

Example 8 with ItemBuilder

use of com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder in project VotingPlugin by Ben12345rocks.

the class PlayerGUIs method openVoteURL.

public void openVoteURL(Player player, String voteSite) {
    User user = UserManager.getInstance().getVotingPluginUser(player);
    VoteSite site = plugin.getVoteSite(voteSite);
    BInventory inv = new BInventory(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteURLSiteName(), "site", site.getDisplayName()));
    inv.setMeta(player, "VoteSite", site);
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.BOW).setName("&4URL").addLoreLine("Click to see URL")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            VoteSite site = (VoteSite) clickEvent.getMeta("VoteSite");
            clickEvent.getWhoClicked().sendMessage(site.getVoteURL());
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.COMPASS).setName("&4Next Vote").addLoreLine(Commands.getInstance().voteCommandNextInfo(user, site))) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            openVoteURL(clickEvent.getPlayer());
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.WATCH).setName("&4Last Vote").addLoreLine(Commands.getInstance().voteCommandLastLine(user, site))) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            openVoteURL(clickEvent.getPlayer());
        }
    });
    if (Config.getInstance().getGUIVoteURLBackButton()) {
        inv.addButton(new BInventoryButton(getBackButton()) {

            @Override
            public void onClick(ClickEvent event) {
                openVoteGUI(event.getPlayer(), getSelectedPlayer(event.getPlayer()));
            }
        });
    }
    inv.openInventory(player);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) 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)

Example 9 with ItemBuilder

use of com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder in project VotingPlugin by Ben12345rocks.

the class PlayerGUIs method openVoteGUI.

public void openVoteGUI(Player player, User user) {
    if (user == null) {
        user = UserManager.getInstance().getVotingPluginUser(player);
        setSelectedPlayer(player, user);
    }
    if ((!player.getName().equals(user.getPlayerName()) && !player.hasPermission("VotingPlugin.Commands.Vote.GUI.Other") && !player.hasPermission("VotingPlugin.Mod")) || (!player.hasPermission("VotingPlugin.Commands.Vote.GUI") && !player.hasPermission("VotingPlugin.Player"))) {
        player.sendMessage(StringUtils.getInstance().colorize(AdvancedCoreHook.getInstance().getFormatNoPerms()));
        return;
    }
    setSelectedPlayer(player, user);
    BInventory inv = new BInventory(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteGUIName(), "player", user.getPlayerName()));
    for (String slot : Config.getInstance().getVoteGUISlots()) {
        ItemBuilder builder = new ItemBuilder(Config.getInstance().getVoteGUISlotSection(slot));
        String[] lore = new String[1];
        lore = ArrayUtils.getInstance().convert(Config.getInstance().getVoteGUISlotLore(slot));
        if (lore.length == 0) {
            if (slot.equalsIgnoreCase("url")) {
                lore = Commands.getInstance().voteURLs(user);
            } else if (slot.equalsIgnoreCase("next")) {
                lore = Commands.getInstance().voteCommandNext(user);
            } else if (slot.equalsIgnoreCase("last")) {
                lore = Commands.getInstance().voteCommandLast(user);
            } else if (slot.equalsIgnoreCase("total")) {
                lore = Commands.getInstance().voteCommandTotal(user);
            } else if (slot.equalsIgnoreCase("top")) {
                String str = Config.getInstance().getVoteTopDefault();
                if (str.equalsIgnoreCase("monthly")) {
                    lore = TopVoterHandler.getInstance().topVoterMonthly(1);
                } else if (str.equalsIgnoreCase("weekly")) {
                    lore = TopVoterHandler.getInstance().topVoterWeekly(1);
                } else if (str.equalsIgnoreCase("daily")) {
                    lore = TopVoterHandler.getInstance().topVoterDaily(1);
                } else {
                    lore = TopVoterHandler.getInstance().topVoterAllTime(1);
                }
            } else if (slot.equalsIgnoreCase("today")) {
                lore = Commands.getInstance().voteToday();
            } else if (slot.equalsIgnoreCase("help")) {
                lore = new String[] { "Click to view help" };
            }
        }
        HashMap<String, String> placeholders = new HashMap<String, String>();
        placeholders.put("points", "" + user.getPoints());
        builder.setPlaceholders(placeholders);
        builder.setLore(ArrayUtils.getInstance().convert(lore));
        inv.addButton(Config.getInstance().getVoteGUISlotSlot(slot), new BInventoryButton(builder) {

            @Override
            public void onClick(ClickEvent event) {
                Player player = event.getWhoClicked();
                String cmd = Config.getInstance().getVoteGUISlotCommand(slot);
                User user = getSelectedPlayer(player);
                if (!cmd.equals("")) {
                    player.performCommand(cmd);
                } else {
                    if (slot.equalsIgnoreCase("url")) {
                        openVoteURL(player);
                    } else if (slot.equalsIgnoreCase("next")) {
                        openVoteNext(player, user);
                    } else if (slot.equalsIgnoreCase("last")) {
                        openVoteLast(player, user);
                    } else if (slot.equalsIgnoreCase("total")) {
                        openVoteTotal(player, user);
                    } else if (slot.equalsIgnoreCase("top")) {
                        openVoteTop(player, null);
                    } else if (slot.equalsIgnoreCase("today")) {
                        openVoteToday(player);
                    } else if (slot.equalsIgnoreCase("help")) {
                        player.performCommand("vote help");
                    } else if (slot.equalsIgnoreCase("shop")) {
                        VoteShop.getInstance().voteShop(player);
                    }
                }
            }
        });
    }
    inv.openInventory(player);
}
Also used : ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) Player(org.bukkit.entity.Player) User(com.Ben12345rocks.VotingPlugin.Objects.User) HashMap(java.util.HashMap) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)

Example 10 with ItemBuilder

use of com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder in project VotingPlugin by Ben12345rocks.

the class VoteShop method voteShop.

public void voteShop(Player player) {
    BInventory inv = new BInventory(Config.getInstance().getVoteShopName());
    for (String identifier : Config.getInstance().getIdentifiers()) {
        ItemBuilder builder = new ItemBuilder(Config.getInstance().getIdentifierSection(identifier));
        inv.addButton(Config.getInstance().getIdentifierSlot(identifier), new BInventoryButton(builder) {

            @Override
            public void onClick(ClickEvent event) {
                Player player = event.getWhoClicked();
                User user = UserManager.getInstance().getVotingPluginUser(player);
                int points = Config.getInstance().getIdentifierCost(identifier);
                String identifier = Config.getInstance().getIdentifierFromSlot(event.getSlot());
                if (identifier != null) {
                    if (user.removePoints(points)) {
                        RewardHandler.getInstance().giveReward(user, Config.getInstance().getData(), Config.getInstance().getIdentifierRewardsPath(identifier));
                        user.sendMessage(Config.getInstance().getFormatShopPurchaseMsg().replace("%Identifier%", identifier).replace("%Points%", "" + points));
                    } else {
                        user.sendMessage(Config.getInstance().getFormatShopFailedMsg().replace("%Identifier%", identifier).replace("%Points%", "" + points));
                    }
                }
            }
        });
    }
    if (Config.getInstance().getVoteShopBackButton()) {
        inv.addButton(new BInventoryButton(PlayerGUIs.getInstance().getBackButton()) {

            @Override
            public void onClick(ClickEvent event) {
                PlayerGUIs.getInstance().openVoteGUI(event.getPlayer(), UserManager.getInstance().getVotingPluginUser(player));
            }
        });
    }
    inv.openInventory(player);
}
Also used : ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) Player(org.bukkit.entity.Player) 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)

Aggregations

BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)10 ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)10 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)10 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)10 User (com.Ben12345rocks.VotingPlugin.Objects.User)6 Player (org.bukkit.entity.Player)5 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)4 BooleanListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener)1 NumberListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener)1 StringListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener)1 ValueRequest (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest)1 TopVoter (com.Ben12345rocks.VotingPlugin.Objects.TopVoter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 ItemStack (org.bukkit.inventory.ItemStack)1