Search in sources :

Example 6 with ClickEvent

use of com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent in project VotingPlugin by Ben12345rocks.

the class CommandLoader method loadCommands.

/**
 * Load commands.
 */
public void loadCommands() {
    loadAdminVoteCommand();
    loadVoteCommand();
    Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

        @Override
        public void run() {
            com.Ben12345rocks.AdvancedCore.Thread.Thread.getInstance().run(new Runnable() {

                @Override
                public void run() {
                    loadTabComplete();
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("Force Vote", new String[] {}, new ItemStack(Material.STONE)) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            Player player = clickEvent.getPlayer();
                            ArrayList<String> voteSites = new ArrayList<String>();
                            for (VoteSite voteSite : plugin.getVoteSites()) {
                                voteSites.add(voteSite.getKey());
                            }
                            new ValueRequest().requestString(player, "", ArrayUtils.getInstance().convert(voteSites), true, new StringListener() {

                                @Override
                                public void onInput(Player player, String value) {
                                    VotiferEvent.playerVote(UserGUI.getInstance().getCurrentPlayer(player), value, false);
                                    player.sendMessage("Forced vote for " + UserGUI.getInstance().getCurrentPlayer(player) + " on " + value);
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("Set Vote Points", new String[] {}, new ItemStack(Material.STONE)) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            Player player = clickEvent.getPlayer();
                            User user = UserManager.getInstance().getVotingPluginUser(UserGUI.getInstance().getCurrentPlayer(player));
                            new ValueRequest().requestNumber(player, "" + user.getPoints(), new Number[] { 0, 5, 100 }, true, new NumberListener() {

                                @Override
                                public void onInput(Player player, Number value) {
                                    User user = UserManager.getInstance().getVotingPluginUser(UserGUI.getInstance().getCurrentPlayer(player));
                                    user.setPoints(value.intValue());
                                    player.sendMessage("Points set to " + value.intValue() + " for " + user.getPlayerName());
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton(new ItemBuilder(Material.BOOK).setName("Set Month Total")) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            String playerName = (String) clickEvent.getMeta(clickEvent.getPlayer(), "Player");
                            User user = UserManager.getInstance().getVotingPluginUser(playerName);
                            new ValueRequest().requestNumber(clickEvent.getPlayer(), "" + user.getMonthTotal(), new Number[] { 0, 10, 50, 100 }, new NumberListener() {

                                @Override
                                public void onInput(Player player, Number value) {
                                    String playerName = (String) clickEvent.getMeta(clickEvent.getPlayer(), "Player");
                                    User user = UserManager.getInstance().getVotingPluginUser(playerName);
                                    user.setMonthTotal(value.intValue());
                                    player.sendMessage(StringUtils.getInstance().colorize("&cTotal set"));
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("MileStones", new String[0], new ItemStack(Material.STONE)) {

                        @Override
                        public void onClick(ClickEvent event) {
                            Player player = event.getWhoClicked();
                            String playerName = (String) event.getMeta(player, "Player");
                            BInventory inv = new BInventory("MileStones: " + playerName);
                            for (String mileStoneName : Config.getInstance().getMilestoneVotes()) {
                                if (StringUtils.getInstance().isInt(mileStoneName)) {
                                    int mileStone = Integer.parseInt(mileStoneName);
                                    inv.addButton(inv.getNextSlot(), new BInventoryButton("" + mileStone, new String[] { "Enabled: " + Config.getInstance().getMilestoneRewardEnabled(mileStone), "&cClick to set wether this has been completed or not" }, new ItemStack(Material.STONE)) {

                                        @Override
                                        public void onClick(ClickEvent clickEvent) {
                                            if (StringUtils.getInstance().isInt(clickEvent.getClickedItem().getItemMeta().getDisplayName())) {
                                                Player player = clickEvent.getPlayer();
                                                int mileStone = Integer.parseInt(clickEvent.getClickedItem().getItemMeta().getDisplayName());
                                                String playerName = (String) event.getMeta(player, "Player");
                                                User user = UserManager.getInstance().getVotingPluginUser(playerName);
                                                new ValueRequest().requestBoolean(player, "" + user.hasGottenMilestone(mileStone), new BooleanListener() {

                                                    @Override
                                                    public void onInput(Player player, boolean value) {
                                                        String playerName = UserGUI.getInstance().getCurrentPlayer(player);
                                                        User user = UserManager.getInstance().getVotingPluginUser(playerName);
                                                        user.setHasGotteMilestone(mileStone, value);
                                                        player.sendMessage("Set milestone completetion to " + value + " on " + mileStone);
                                                    }
                                                });
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.Ben12345rocks.VotingPlugin.Objects.User) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) ValueRequest(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory) VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) NumberListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener) ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) BooleanListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener) StringListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with ClickEvent

use of com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent in project VotingPlugin by Ben12345rocks.

the class AdminGUI method openAdminGUIVoteSiteSite.

/**
 * Open admin GUI vote site site.
 *
 * @param player
 *            the player
 * @param voteSite
 *            the vote site
 */
public void openAdminGUIVoteSiteSite(Player player, VoteSite voteSite) {
    BInventory inv = new BInventory("VoteSite: " + voteSite.getDisplayName());
    inv.setMeta(player, "VoteSite", voteSite);
    inv.addButton(new BInventoryButton(voteSite.getItem().setName("&cForce vote")) {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<String> playerNames = new ArrayList<String>();
            for (Player p : Bukkit.getOnlinePlayers()) {
                playerNames.add(p.getName());
            }
            new ValueRequestBuilder(new StringListener() {

                @Override
                public void onInput(Player player, String value) {
                    Object ob = PlayerUtils.getInstance().getPlayerMeta(player, "VoteSite");
                    if (ob != null) {
                        VoteSite site = (VoteSite) ob;
                        VotiferEvent.playerVote(value, site.getServiceSite(), false);
                    }
                }
            }, ArrayUtils.getInstance().convert(playerNames)).usingMethod(InputMethod.INVENTORY).allowCustomOption(true).request(event.getWhoClicked());
        }
    });
    inv.addButton(new BInventoryButton("SetPriority", new String[0], new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent event) {
            Player player = event.getWhoClicked();
            new ValueRequest().requestNumber(player, "" + voteSite.getPriority(), null, new NumberListener() {

                @Override
                public void onInput(Player player, Number value) {
                    VoteSite voteSite = (VoteSite) event.getMeta("VoteSite");
                    ConfigVoteSites.getInstance().setPriority(voteSite.getKey(), value.intValue());
                    player.sendMessage("Set Priority");
                    plugin.reload();
                }
            });
        }
    });
    inv.addButton(new BInventoryButton("SetServiceSite", new String[0], new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent event) {
            if (event.getWhoClicked() instanceof Player) {
                Player player = event.getWhoClicked();
                new ValueRequest().requestString(player, voteSite.getServiceSite(), null, new StringListener() {

                    @Override
                    public void onInput(Player player, String value) {
                        VoteSite voteSite = (VoteSite) event.getMeta("VoteSite");
                        String siteName = voteSite.getKey();
                        ConfigVoteSites.getInstance().setServiceSite(siteName, value);
                        player.sendMessage("Set ServiceSite");
                        plugin.reload();
                    }
                });
            }
        }
    });
    inv.addButton(new BInventoryButton("SetName", new String[0], new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent event) {
            if (event.getWhoClicked() instanceof Player) {
                Player player = event.getWhoClicked();
                new ValueRequest().requestString(player, voteSite.getServiceSite(), null, new StringListener() {

                    @Override
                    public void onInput(Player player, String value) {
                        VoteSite voteSite = (VoteSite) event.getMeta("VoteSite");
                        ConfigVoteSites.getInstance().setDisplayName(voteSite.getKey(), value);
                        player.sendMessage("Set name");
                        plugin.reload();
                    }
                });
            }
        }
    });
    inv.addButton(new BInventoryButton("SetVoteURL", new String[0], new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent event) {
            if (event.getWhoClicked() instanceof Player) {
                Player player = event.getWhoClicked();
                new ValueRequest().requestString(player, voteSite.getVoteURL(), null, new StringListener() {

                    @Override
                    public void onInput(Player player, String value) {
                        VoteSite voteSite = (VoteSite) event.getMeta("VoteSite");
                        String siteName = voteSite.getKey();
                        ConfigVoteSites.getInstance().setVoteURL(siteName, value);
                        player.sendMessage("Set VoteURL");
                        plugin.reload();
                    }
                });
            }
        }
    });
    inv.addButton(new BInventoryButton("SetVoteDelay", new String[0], new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent event) {
            Player player = event.getWhoClicked();
            new ValueRequest().requestNumber(player, "" + voteSite.getVoteDelay(), null, new NumberListener() {

                @Override
                public void onInput(Player player, Number value) {
                    VoteSite voteSite = (VoteSite) event.getMeta("VoteSite");
                    String siteName = voteSite.getKey();
                    ConfigVoteSites.getInstance().setVoteDelay(siteName, value.intValue());
                    player.sendMessage("Set VoteDelay");
                    plugin.reload();
                }
            });
        }
    });
    inv.addButton(inv.getNextSlot(), new BInventoryButton("SetEnabled", new String[0], new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent event) {
            Player player = event.getWhoClicked();
            new ValueRequest().requestBoolean(player, "" + ConfigVoteSites.getInstance().getVoteSiteEnabled(voteSite.getKey()), new BooleanListener() {

                @Override
                public void onInput(Player player, boolean value) {
                    VoteSite voteSite = (VoteSite) event.getMeta("VoteSite");
                    String siteName = voteSite.getKey();
                    ConfigVoteSites.getInstance().setEnabled(siteName, value);
                    player.sendMessage("Set Enabled");
                    plugin.reload();
                }
            });
        }
    });
    inv.openInventory(player);
}
Also used : Player(org.bukkit.entity.Player) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory) ValueRequest(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest) ValueRequestBuilder(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequestBuilder) VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) NumberListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener) BooleanListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener) StringListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with ClickEvent

use of com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent in project VotingPlugin by Ben12345rocks.

the class AdminGUI method adminGUIButtons.

/**
 * Open admin GUI.
 *
 * @return ArrayList of buttons
 */
public ArrayList<BInventoryButton> adminGUIButtons() {
    ArrayList<BInventoryButton> buttons = new ArrayList<BInventoryButton>();
    ArrayList<String> lore = new ArrayList<String>();
    lore.add("&cOnly enabled sites are listed in this section");
    lore.add("&cMiddle Click to create");
    buttons.add(new BInventoryButton("&cVoteSites", ArrayUtils.getInstance().convert(lore), new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent event) {
            if (event.getWhoClicked() instanceof Player) {
                Player player = event.getWhoClicked();
                if (event.getClick().equals(ClickType.MIDDLE)) {
                    new ValueRequest().requestString(player, new StringListener() {

                        @Override
                        public void onInput(Player player, String value) {
                            ConfigVoteSites.getInstance().generateVoteSite(value);
                            player.sendMessage("Generated site");
                            plugin.reload();
                        }
                    });
                } else {
                    openAdminGUIVoteSites(player);
                }
            }
        }
    });
    lore = new ArrayList<String>();
    buttons.add(new BInventoryButton("&cReload Plugin", ArrayUtils.getInstance().convert(lore), new ItemStack(Material.STONE, 1, (short) 3)) {

        @Override
        public void onClick(ClickEvent event) {
            event.getPlayer().performCommand("av reload");
        }
    });
    return buttons;
}
Also used : Player(org.bukkit.entity.Player) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) ValueRequest(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest) StringListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with ClickEvent

use of com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent in project VotingPlugin by Ben12345rocks.

the class AdminGUI method openAdminGUIVoteSites.

/**
 * Open admin GUI vote sites.
 *
 * @param player
 *            the player
 */
public void openAdminGUIVoteSites(Player player) {
    BInventory inv = new BInventory("VoteSites");
    int count = 0;
    for (VoteSite voteSite : plugin.getVoteSites()) {
        ArrayList<String> lore = new ArrayList<String>();
        lore.add("Priority: " + voteSite.getPriority());
        lore.add("Name: " + voteSite.getDisplayName());
        lore.add("ServiceSite: " + voteSite.getServiceSite());
        lore.add("VoteURL: " + voteSite.getVoteURL());
        lore.add("VoteDelay: " + voteSite.getVoteDelay());
        // lore.add("Rewards: " +
        // ArrayUtils.getInstance().makeStringList(voteSite.getRewards()));
        inv.addButton(count, new BInventoryButton(voteSite.getKey(), ArrayUtils.getInstance().convert(lore), new ItemStack(Material.STONE)) {

            @Override
            public void onClick(ClickEvent event) {
                Player player = event.getWhoClicked();
                openAdminGUIVoteSiteSite(player, voteSite);
            }
        });
        count++;
    }
    inv.openInventory(player);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) Player(org.bukkit.entity.Player) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with ClickEvent

use of com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent 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)

Aggregations

ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)16 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)16 BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)15 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)10 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)9 Player (org.bukkit.entity.Player)8 User (com.Ben12345rocks.VotingPlugin.Objects.User)7 ArrayList (java.util.ArrayList)4 ItemStack (org.bukkit.inventory.ItemStack)4 StringListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener)3 ValueRequest (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest)3 BooleanListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener)2 NumberListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener)2 ValueRequestBuilder (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequestBuilder)1 TopVoter (com.Ben12345rocks.VotingPlugin.Objects.TopVoter)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 OfflinePlayer (org.bukkit.OfflinePlayer)1