Search in sources :

Example 21 with User

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

the class Commands method sendTopVoterMonthlyScoreBoard.

/**
 * Send top voter monthly score board.
 *
 * @param player
 *            the player
 * @param page
 *            the page
 */
public void sendTopVoterMonthlyScoreBoard(Player player, int page) {
    if (AdvancedCoreHook.getInstance().isSendScoreboards()) {
        int pagesize = Config.getInstance().getFormatPageSize();
        ArrayList<User> users = plugin.convertSet(plugin.topVoterMonthly.keySet());
        int pageSize = (users.size() / pagesize);
        if ((users.size() % pagesize) != 0) {
            pageSize++;
        }
        String title = StringUtils.getInstance().colorize(config.getFormatCommandVoteTopTitle().replace("%page%", "" + page).replace("%maxpages%", "" + pageSize).replace("%Top%", "Monthly"));
        SimpleScoreboard scoreboard = new SimpleScoreboard(title);
        for (int i = (page - 1) * pagesize; (i < users.size()) && (i < (((page - 1) * pagesize) + 10)); i++) {
            scoreboard.add("" + (i + 1) + ": " + users.get(i).getPlayerName(), plugin.topVoterMonthly.get(users.get(i)));
        }
        scoreboard.build();
        scoreboard.send(player);
        Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {

            @Override
            public void run() {
                SimpleScoreboard clear = new SimpleScoreboard("Empty");
                clear.send(player);
            }
        }, 90);
    }
}
Also used : User(com.Ben12345rocks.VotingPlugin.Objects.User) SimpleScoreboard(com.Ben12345rocks.AdvancedCore.Util.Scoreboards.SimpleScoreboard)

Example 22 with User

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

the class Commands method voteToday.

/**
 * Vote today.
 *
 * @return the string[]
 */
public String[] voteToday() {
    ArrayList<String> msg = new ArrayList<String>();
    for (User user : plugin.voteToday.keySet()) {
        for (VoteSite voteSite : plugin.voteToday.get(user).keySet()) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Config.getInstance().getFormatTimeFormat());
            String timeString = plugin.voteToday.get(user).get(voteSite).format(formatter);
            msg.add("&6" + user.getPlayerName() + " : " + voteSite.getKey() + " : " + timeString);
        }
    }
    msg = ArrayUtils.getInstance().colorize(msg);
    return ArrayUtils.getInstance().convert(msg);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) User(com.Ben12345rocks.VotingPlugin.Objects.User) ArrayList(java.util.ArrayList) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 23 with User

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

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

the class PlayerGUIs method openVoteURL.

public void openVoteURL(Player player, String voteSite) {
    User user = UserManager.getInstance().getVotingPluginUser(player);
    VoteSite site = plugin.getVoteSite(voteSite);
    BInventory inv = new BInventory(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteURLSiteName(), "site", site.getDisplayName()));
    inv.setMeta(player, "VoteSite", site);
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.BOW).setName("&4URL").addLoreLine("Click to see URL")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            VoteSite site = (VoteSite) clickEvent.getMeta("VoteSite");
            clickEvent.getWhoClicked().sendMessage(site.getVoteURL());
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.COMPASS).setName("&4Next Vote").addLoreLine(Commands.getInstance().voteCommandNextInfo(user, site))) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            openVoteURL(clickEvent.getPlayer());
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.WATCH).setName("&4Last Vote").addLoreLine(Commands.getInstance().voteCommandLastLine(user, site))) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            openVoteURL(clickEvent.getPlayer());
        }
    });
    if (Config.getInstance().getGUIVoteURLBackButton()) {
        inv.addButton(new BInventoryButton(getBackButton()) {

            @Override
            public void onClick(ClickEvent event) {
                openVoteGUI(event.getPlayer(), getSelectedPlayer(event.getPlayer()));
            }
        });
    }
    inv.openInventory(player);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) User(com.Ben12345rocks.VotingPlugin.Objects.User) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)

Example 25 with User

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

the class PlayerGUIs method openVoteGUI.

public void openVoteGUI(Player player, User user) {
    if (user == null) {
        user = UserManager.getInstance().getVotingPluginUser(player);
        setSelectedPlayer(player, user);
    }
    if ((!player.getName().equals(user.getPlayerName()) && !player.hasPermission("VotingPlugin.Commands.Vote.GUI.Other") && !player.hasPermission("VotingPlugin.Mod")) || (!player.hasPermission("VotingPlugin.Commands.Vote.GUI") && !player.hasPermission("VotingPlugin.Player"))) {
        player.sendMessage(StringUtils.getInstance().colorize(AdvancedCoreHook.getInstance().getFormatNoPerms()));
        return;
    }
    setSelectedPlayer(player, user);
    BInventory inv = new BInventory(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteGUIName(), "player", user.getPlayerName()));
    for (String slot : Config.getInstance().getVoteGUISlots()) {
        ItemBuilder builder = new ItemBuilder(Config.getInstance().getVoteGUISlotSection(slot));
        String[] lore = new String[1];
        lore = ArrayUtils.getInstance().convert(Config.getInstance().getVoteGUISlotLore(slot));
        if (lore.length == 0) {
            if (slot.equalsIgnoreCase("url")) {
                lore = Commands.getInstance().voteURLs(user);
            } else if (slot.equalsIgnoreCase("next")) {
                lore = Commands.getInstance().voteCommandNext(user);
            } else if (slot.equalsIgnoreCase("last")) {
                lore = Commands.getInstance().voteCommandLast(user);
            } else if (slot.equalsIgnoreCase("total")) {
                lore = Commands.getInstance().voteCommandTotal(user);
            } else if (slot.equalsIgnoreCase("top")) {
                String str = Config.getInstance().getVoteTopDefault();
                if (str.equalsIgnoreCase("monthly")) {
                    lore = TopVoterHandler.getInstance().topVoterMonthly(1);
                } else if (str.equalsIgnoreCase("weekly")) {
                    lore = TopVoterHandler.getInstance().topVoterWeekly(1);
                } else if (str.equalsIgnoreCase("daily")) {
                    lore = TopVoterHandler.getInstance().topVoterDaily(1);
                } else {
                    lore = TopVoterHandler.getInstance().topVoterAllTime(1);
                }
            } else if (slot.equalsIgnoreCase("today")) {
                lore = Commands.getInstance().voteToday();
            } else if (slot.equalsIgnoreCase("help")) {
                lore = new String[] { "Click to view help" };
            }
        }
        HashMap<String, String> placeholders = new HashMap<String, String>();
        placeholders.put("points", "" + user.getPoints());
        builder.setPlaceholders(placeholders);
        builder.setLore(ArrayUtils.getInstance().convert(lore));
        inv.addButton(Config.getInstance().getVoteGUISlotSlot(slot), new BInventoryButton(builder) {

            @Override
            public void onClick(ClickEvent event) {
                Player player = event.getWhoClicked();
                String cmd = Config.getInstance().getVoteGUISlotCommand(slot);
                User user = getSelectedPlayer(player);
                if (!cmd.equals("")) {
                    player.performCommand(cmd);
                } else {
                    if (slot.equalsIgnoreCase("url")) {
                        openVoteURL(player);
                    } else if (slot.equalsIgnoreCase("next")) {
                        openVoteNext(player, user);
                    } else if (slot.equalsIgnoreCase("last")) {
                        openVoteLast(player, user);
                    } else if (slot.equalsIgnoreCase("total")) {
                        openVoteTotal(player, user);
                    } else if (slot.equalsIgnoreCase("top")) {
                        openVoteTop(player, null);
                    } else if (slot.equalsIgnoreCase("today")) {
                        openVoteToday(player);
                    } else if (slot.equalsIgnoreCase("help")) {
                        player.performCommand("vote help");
                    } else if (slot.equalsIgnoreCase("shop")) {
                        VoteShop.getInstance().voteShop(player);
                    }
                }
            }
        });
    }
    inv.openInventory(player);
}
Also used : ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) Player(org.bukkit.entity.Player) User(com.Ben12345rocks.VotingPlugin.Objects.User) HashMap(java.util.HashMap) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)

Aggregations

User (com.Ben12345rocks.VotingPlugin.Objects.User)32 ArrayList (java.util.ArrayList)12 UUID (com.Ben12345rocks.AdvancedCore.Objects.UUID)9 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)9 BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)7 ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)7 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)7 Player (org.bukkit.entity.Player)7 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)6 HashMap (java.util.HashMap)6 OfflinePlayer (org.bukkit.OfflinePlayer)5 SimpleScoreboard (com.Ben12345rocks.AdvancedCore.Util.Scoreboards.SimpleScoreboard)4 File (java.io.File)4 LocalDateTime (java.time.LocalDateTime)4 YMLFileHandler (com.Ben12345rocks.AdvancedCore.YML.YMLFileHandler)3 Entry (java.util.Map.Entry)3 EventHandler (org.bukkit.event.EventHandler)3 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)2 UserStorage (com.Ben12345rocks.AdvancedCore.Objects.UserStorage)2 IOException (java.io.IOException)2