Search in sources :

Example 1 with BooleanListener

use of com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener 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.bencodez.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) {
                                    PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(value, true), UserGUI.getInstance().getCurrentPlayer(player), plugin.getVoteSiteServiceSite(value), false);
                                    plugin.getServer().getPluginManager().callEvent(voteEvent);
                                    player.sendMessage("Forced vote for " + UserGUI.getInstance().getCurrentPlayer(player) + " on " + value);
                                }
                            });
                        }
                    });
                    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 : plugin.getSpecialRewardsConfig().getMilestoneVotes()) {
                                if (StringParser.getInstance().isInt(mileStoneName)) {
                                    int mileStone = Integer.parseInt(mileStoneName);
                                    inv.addButton(inv.getNextSlot(), new BInventoryButton("" + mileStone, new String[] { "Enabled: " + plugin.getSpecialRewardsConfig().getMilestoneRewardEnabled(mileStone), "&cClick to set wether this has been completed or not" }, new ItemStack(Material.STONE)) {

                                        @Override
                                        public void onClick(ClickEvent clickEvent) {
                                            if (StringParser.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");
                                                VotingPluginUser 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);
                                                        VotingPluginUser 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) AdminVotePlaceholdersPlayer(com.bencodez.votingplugin.commands.gui.admin.AdminVotePlaceholdersPlayer) AdminVoteVotePlayer(com.bencodez.votingplugin.commands.gui.admin.AdminVoteVotePlayer) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) ValueRequest(com.bencodez.advancedcore.api.valuerequest.ValueRequest) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) VoteSite(com.bencodez.votingplugin.objects.VoteSite) VoteURLVoteSite(com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite) PlayerVoteEvent(com.bencodez.votingplugin.events.PlayerVoteEvent) BooleanListener(com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener) StringListener(com.bencodez.advancedcore.api.valuerequest.listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Aggregations

BInventory (com.bencodez.advancedcore.api.inventory.BInventory)1 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)1 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)1 ValueRequest (com.bencodez.advancedcore.api.valuerequest.ValueRequest)1 BooleanListener (com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener)1 StringListener (com.bencodez.advancedcore.api.valuerequest.listeners.StringListener)1 AdminVotePlaceholdersPlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVotePlaceholdersPlayer)1 AdminVoteVotePlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVoteVotePlayer)1 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)1 PlayerVoteEvent (com.bencodez.votingplugin.events.PlayerVoteEvent)1 VoteSite (com.bencodez.votingplugin.objects.VoteSite)1 VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)1 ArrayList (java.util.ArrayList)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1