Search in sources :

Example 1 with StringListener

use of com.bencodez.advancedcore.api.valuerequest.listeners.StringListener 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)

Example 2 with StringListener

use of com.bencodez.advancedcore.api.valuerequest.listeners.StringListener 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) {
    EditGUI inv = new EditGUI("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;
                        PlayerVoteEvent voteEvent = new PlayerVoteEvent(site, value, site.getServiceSite(), false);
                        plugin.getServer().getPluginManager().callEvent(voteEvent);
                    }
                }
            }, ArrayUtils.getInstance().convert(playerNames)).usingMethod(InputMethod.INVENTORY).allowCustomOption(true).request(event.getWhoClicked());
        }
    });
    inv.addButton(new EditGUIButton(new EditGUIValueNumber("Priority", voteSite.getPriority()) {

        @Override
        public void setValue(Player player, Number num) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            plugin.getConfigVoteSites().setPriority(voteSite.getKey(), num.intValue());
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueString("ServiceSite", voteSite.getServiceSite()) {

        @Override
        public void setValue(Player player, String value) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            String siteName = voteSite.getKey();
            plugin.getConfigVoteSites().setServiceSite(siteName, value);
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueString("Name", voteSite.getDisplayName()) {

        @Override
        public void setValue(Player player, String value) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            plugin.getConfigVoteSites().setDisplayName(voteSite.getKey(), value);
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueString("VoteURL", voteSite.getVoteURL()) {

        @Override
        public void setValue(Player player, String value) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            String siteName = voteSite.getKey();
            plugin.getConfigVoteSites().setVoteURL(siteName, value);
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueNumber("VoteDelay", voteSite.getVoteDelay()) {

        @Override
        public void setValue(Player player, Number num) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            String siteName = voteSite.getKey();
            plugin.getConfigVoteSites().setVoteDelay(siteName, num.intValue());
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueNumber("VoteDelayMin", voteSite.getVoteDelay()) {

        @Override
        public void setValue(Player player, Number num) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            String siteName = voteSite.getKey();
            plugin.getConfigVoteSites().setVoteDelay(siteName, num.intValue());
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueBoolean("Enabled", voteSite.isEnabled()) {

        @Override
        public void setValue(Player player, boolean value) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            String siteName = voteSite.getKey();
            plugin.getConfigVoteSites().setEnabled(siteName, value);
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueBoolean("ForceOffline", voteSite.isGiveOffline()) {

        @Override
        public void setValue(Player player, boolean value) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            String siteName = voteSite.getKey();
            plugin.getConfigVoteSites().setForceOffline(siteName, value);
            plugin.reload();
        }
    }));
    inv.addButton(new EditGUIButton(new EditGUIValueBoolean("VoteDelayDaily", voteSite.isVoteDelayDaily()) {

        @Override
        public void setValue(Player player, boolean value) {
            VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
            String siteName = voteSite.getKey();
            plugin.getConfigVoteSites().setVoteDelayDaily(siteName, value);
            plugin.reload();
        }
    }));
    if (voteSite.getSiteData().isList("Rewards")) {
        inv.addButton(new EditGUIButton(new EditGUIValueList("Rewards", voteSite.getSiteData().getStringList("Rewards")) {

            @Override
            public void setValue(Player p, ArrayList<String> rewards) {
                VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
                plugin.getConfigVoteSites().set(voteSite.getKey(), "Rewards", rewards);
                plugin.reload();
            }
        }));
    } else {
        inv.addButton(new BInventoryButton(new ItemBuilder(Material.DISPENSER, 1).setName("&cRewards")) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(), RewardHandler.getInstance().getDirectlyDefined("VoteSites." + voteSite.getKey() + ".Rewards"));
            }
        });
    }
    inv.openInventory(player);
}
Also used : EditGUI(com.bencodez.advancedcore.api.inventory.editgui.EditGUI) RewardEditGUI(com.bencodez.advancedcore.command.gui.RewardEditGUI) Player(org.bukkit.entity.Player) EditGUIValueBoolean(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueBoolean) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) EditGUIValueString(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString) EditGUIValueString(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString) ValueRequestBuilder(com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder) VoteSite(com.bencodez.votingplugin.objects.VoteSite) PlayerVoteEvent(com.bencodez.votingplugin.events.PlayerVoteEvent) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) EditGUIValueList(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueList) EditGUIValueNumber(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber) EditGUIButton(com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton) EditGUIValueNumber(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber) StringListener(com.bencodez.advancedcore.api.valuerequest.listeners.StringListener)

Example 3 with StringListener

use of com.bencodez.advancedcore.api.valuerequest.listeners.StringListener 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>();
    buttons.add(new BInventoryButton("&cVoteSites", new String[] { "&cOnly enabled sites are listed in this section", "&cMiddle Click to create" }, new ItemStack(Material.STONE)) {

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

                    @Override
                    public void onInput(Player player, String value) {
                        plugin.getConfigVoteSites().generateVoteSite(value);
                        player.sendMessage("Generated site");
                        plugin.reload();
                    }
                });
            } else {
                openAdminGUIVoteSites(player);
            }
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.CHEST, 1).setName("&cEdit VoteShop")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new AdminVoteVoteShop(plugin, clickEvent.getPlayer()).open(GUIMethod.CHEST);
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.DIAMOND_BLOCK, 1).setName("&cEdit Milestones")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new AdminVoteMilestones(plugin, clickEvent.getPlayer()).open(GUIMethod.CHEST);
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.COBBLESTONE, 1).setName("&cEdit Cumulative")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new AdminVoteCumulative(plugin, clickEvent.getPlayer()).open(GUIMethod.CHEST);
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit VoteParty")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new AdminVoteVoteParty(plugin, clickEvent.getPlayer()).open(GUIMethod.CHEST);
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit FirstVote reward")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(), RewardHandler.getInstance().getDirectlyDefined("FirstVote"));
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit FirstVoteToday reward")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(), RewardHandler.getInstance().getDirectlyDefined("FirstVoteToday"));
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit AllSites reward")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(), RewardHandler.getInstance().getDirectlyDefined("AllSites"));
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit AnySiteRewards")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(), RewardHandler.getInstance().getDirectlyDefined("AnySiteRewards"));
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit EverySiteReward")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(), RewardHandler.getInstance().getDirectlyDefined("EverySiteReward"));
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit BungeeVotePartyRewards")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(), RewardHandler.getInstance().getDirectlyDefined("BungeeVotePartyRewards"));
        }
    });
    buttons.add(new BInventoryButton(new ItemBuilder("GRASS_BLOCK").setName("&cEdit BungeeSettings.yml")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new AdminVoteBungeeSettings(plugin, clickEvent.getPlayer()).open();
        }
    });
    buttons.add(new BInventoryButton("&cReload Plugin", new String[] {}, new ItemStack(Material.BUCKET, 1)) {

        @Override
        public void onClick(ClickEvent event) {
            plugin.reload();
        }
    });
    return buttons;
}
Also used : Player(org.bukkit.entity.Player) AdminVoteCumulative(com.bencodez.votingplugin.commands.gui.admin.cumulative.AdminVoteCumulative) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) EditGUIValueString(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString) ValueRequest(com.bencodez.advancedcore.api.valuerequest.ValueRequest) AdminVoteVoteParty(com.bencodez.votingplugin.commands.gui.admin.AdminVoteVoteParty) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) AdminVoteVoteShop(com.bencodez.votingplugin.commands.gui.admin.voteshop.AdminVoteVoteShop) AdminVoteMilestones(com.bencodez.votingplugin.commands.gui.admin.milestones.AdminVoteMilestones) AdminVoteBungeeSettings(com.bencodez.votingplugin.commands.gui.admin.AdminVoteBungeeSettings) StringListener(com.bencodez.advancedcore.api.valuerequest.listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with StringListener

use of com.bencodez.advancedcore.api.valuerequest.listeners.StringListener in project VotingPlugin by Ben12345rocks.

the class AdminVoteVoteShop method onChest.

@Override
public void onChest(Player player) {
    BInventory inv = new BInventory("Edit VoteShop");
    inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteShop");
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.DIAMOND).setName("&cEdit existing item")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new AdminVoteVoteShopItems(plugin, clickEvent.getPlayer()).open(GUIMethod.CHEST);
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&aAdd voteshop item")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new ValueRequest().requestString(player, new StringListener() {

                @Override
                public void onInput(Player player, String value) {
                    plugin.getGui().createShop(value);
                    plugin.reload();
                }
            });
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.REDSTONE_BLOCK).setName("&cRemove item")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new AdminVoteVoteShopItemRemove(plugin, clickEvent.getPlayer()).open();
        }
    });
    inv.openInventory(player);
}
Also used : ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) Player(org.bukkit.entity.Player) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) ValueRequest(com.bencodez.advancedcore.api.valuerequest.ValueRequest) StringListener(com.bencodez.advancedcore.api.valuerequest.listeners.StringListener)

Aggregations

ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)4 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)4 StringListener (com.bencodez.advancedcore.api.valuerequest.listeners.StringListener)4 Player (org.bukkit.entity.Player)4 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)3 ValueRequest (com.bencodez.advancedcore.api.valuerequest.ValueRequest)3 ArrayList (java.util.ArrayList)3 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)2 EditGUIValueString (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString)2 PlayerVoteEvent (com.bencodez.votingplugin.events.PlayerVoteEvent)2 VoteSite (com.bencodez.votingplugin.objects.VoteSite)2 ItemStack (org.bukkit.inventory.ItemStack)2 EditGUI (com.bencodez.advancedcore.api.inventory.editgui.EditGUI)1 EditGUIButton (com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton)1 EditGUIValueBoolean (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueBoolean)1 EditGUIValueList (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueList)1 EditGUIValueNumber (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber)1 ValueRequestBuilder (com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder)1 BooleanListener (com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener)1 RewardEditGUI (com.bencodez.advancedcore.command.gui.RewardEditGUI)1