Search in sources :

Example 11 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class Commands method updateVoteToday.

public void updateVoteToday(ArrayList<User> users) {
    plugin.voteToday.clear();
    for (User user : users) {
        HashMap<VoteSite, LocalDateTime> times = new HashMap<VoteSite, LocalDateTime>();
        for (VoteSite voteSite : plugin.getVoteSites()) {
            long time = user.getTime(voteSite);
            if ((LocalDateTime.now().getDayOfMonth() == MiscUtils.getInstance().getDayFromMili(time)) && (LocalDateTime.now().getMonthValue() == MiscUtils.getInstance().getMonthFromMili(time)) && (LocalDateTime.now().getYear() == MiscUtils.getInstance().getYearFromMili(time))) {
                times.put(voteSite, LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
            }
        }
        if (times.keySet().size() > 0) {
            plugin.voteToday.put(user, times);
        }
    }
    plugin.debug("Updated VoteToday");
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) LocalDateTime(java.time.LocalDateTime) User(com.Ben12345rocks.VotingPlugin.Objects.User) HashMap(java.util.HashMap)

Example 12 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class Commands method voteCommandNext.

/**
 * Vote command next.
 *
 * @param user
 *            the user
 * @return the string[]
 */
public String[] voteCommandNext(User user) {
    ArrayList<String> msg = new ArrayList<String>();
    String playerName = user.getPlayerName();
    msg.add(StringUtils.getInstance().colorize(StringUtils.getInstance().replaceIgnoreCase(config.getFormatCommandsVoteNextTitle(), "%player%", playerName)));
    for (VoteSite voteSite : plugin.getVoteSites()) {
        String msgLine = config.getFormatCommandsVoteNextLayout();
        msgLine = StringUtils.getInstance().replaceIgnoreCase(msgLine, "%info%", voteCommandNextInfo(user, voteSite));
        msgLine = StringUtils.getInstance().replaceIgnoreCase(msgLine, "%SiteName%", voteSite.getDisplayName());
        msg.add(StringUtils.getInstance().colorize(msgLine));
    }
    return ArrayUtils.getInstance().convert(msg);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) ArrayList(java.util.ArrayList)

Example 13 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite 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 14 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite 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 15 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite 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

VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)19 ArrayList (java.util.ArrayList)11 BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)9 ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)9 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)9 User (com.Ben12345rocks.VotingPlugin.Objects.User)9 Player (org.bukkit.entity.Player)6 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)4 HashMap (java.util.HashMap)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 ItemStack (org.bukkit.inventory.ItemStack)3 BooleanListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener)2 NumberListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener)2 StringListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener)2 ValueRequest (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)1 TabCompleteHandle (com.Ben12345rocks.AdvancedCore.Objects.TabCompleteHandle)1 UUID (com.Ben12345rocks.AdvancedCore.Objects.UUID)1 UserStorage (com.Ben12345rocks.AdvancedCore.Objects.UserStorage)1