Search in sources :

Example 1 with ValueRequestBuilder

use of com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequestBuilder 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)

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 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 ValueRequestBuilder (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequestBuilder)1 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)1 ArrayList (java.util.ArrayList)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1