Search in sources :

Example 16 with User

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

the class VotiferEvent method playerVote.

public static void playerVote(final String playerName, final String voteSiteURL, final boolean realVote) {
    if (!config.allowUnJoined() && !PlayerUtils.getInstance().isValidUser(playerName)) {
        plugin.getLogger().warning("Player " + playerName + " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
        return;
    }
    User user = UserManager.getInstance().getVotingPluginUser(playerName);
    VoteSite voteSite = plugin.getVoteSite(voteSiteURL);
    if (voteSite == null) {
        if (!Config.getInstance().getDisableNoServiceSiteMessage()) {
            plugin.getLogger().warning("No voting site with the service site: '" + voteSiteURL + "'");
            plugin.getLogger().warning("Please read here on how to fix it: https://github.com/Ben12345rocks/VotingPlugin/wiki/Common-Problems");
            ArrayList<String> services = new ArrayList<String>();
            for (VoteSite site : plugin.getVoteSites()) {
                services.add(site.getServiceSite());
            }
            plugin.getLogger().warning("Current known service sites: " + ArrayUtils.getInstance().makeStringList(services));
        }
        return;
    }
    synchronized (object) {
        // vote party
        VoteParty.getInstance().vote(user, realVote);
        // broadcast vote if enabled in config
        if (config.getBroadCastVotesEnabled()) {
            if (!Config.getInstance().getFormatBroadcastWhenOnline() || user.isOnline()) {
                voteSite.broadcastVote(user);
            }
        }
        // update last vote time
        user.setTime(voteSite);
        OtherVoteReward.getInstance().checkFirstVote(user);
        if (user.isReminded()) {
            user.setReminded(false);
        }
        if (user.isOnline() || voteSite.isGiveOffline()) {
            user.playerVote(voteSite, true, false);
            user.closeInv();
        } else {
            user.addOfflineVote(voteSite.getKey());
            // plugin.debug(ArrayUtils.getInstance().makeStringList(user.getOfflineVotes()));
            plugin.debug("Offline vote set for " + playerName + " (" + user.getUUID() + ") on " + voteSite.getKey());
        }
        // add to total votes
        if (Config.getInstance().getCountFakeVotes() || realVote) {
            if (Config.getInstance().getAddTotals()) {
                user.addTotal();
                user.addTotalDaily();
                user.addTotalWeekly();
            }
            user.addPoints();
        }
        OtherVoteReward.getInstance().checkAllSites(user);
        OtherVoteReward.getInstance().checkCumualativeVotes(user);
        OtherVoteReward.getInstance().checkMilestone(user);
        if (Config.getInstance().getClearCacheOnVote()) {
            if (AdvancedCoreHook.getInstance().getStorageType().equals(UserStorage.MYSQL)) {
                AdvancedCoreHook.getInstance().getMysql().removePlayer(user.getUUID());
            }
        }
    }
    plugin.setUpdate(true);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) User(com.Ben12345rocks.VotingPlugin.Objects.User) ArrayList(java.util.ArrayList)

Example 17 with User

use of com.Ben12345rocks.VotingPlugin.Objects.User 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.Ben12345rocks.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) {
                                    VotiferEvent.playerVote(UserGUI.getInstance().getCurrentPlayer(player), value, false);
                                    player.sendMessage("Forced vote for " + UserGUI.getInstance().getCurrentPlayer(player) + " on " + value);
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("Set Vote Points", new String[] {}, new ItemStack(Material.STONE)) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            Player player = clickEvent.getPlayer();
                            User user = UserManager.getInstance().getVotingPluginUser(UserGUI.getInstance().getCurrentPlayer(player));
                            new ValueRequest().requestNumber(player, "" + user.getPoints(), new Number[] { 0, 5, 100 }, true, new NumberListener() {

                                @Override
                                public void onInput(Player player, Number value) {
                                    User user = UserManager.getInstance().getVotingPluginUser(UserGUI.getInstance().getCurrentPlayer(player));
                                    user.setPoints(value.intValue());
                                    player.sendMessage("Points set to " + value.intValue() + " for " + user.getPlayerName());
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton(new ItemBuilder(Material.BOOK).setName("Set Month Total")) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            String playerName = (String) clickEvent.getMeta(clickEvent.getPlayer(), "Player");
                            User user = UserManager.getInstance().getVotingPluginUser(playerName);
                            new ValueRequest().requestNumber(clickEvent.getPlayer(), "" + user.getMonthTotal(), new Number[] { 0, 10, 50, 100 }, new NumberListener() {

                                @Override
                                public void onInput(Player player, Number value) {
                                    String playerName = (String) clickEvent.getMeta(clickEvent.getPlayer(), "Player");
                                    User user = UserManager.getInstance().getVotingPluginUser(playerName);
                                    user.setMonthTotal(value.intValue());
                                    player.sendMessage(StringUtils.getInstance().colorize("&cTotal set"));
                                }
                            });
                        }
                    });
                    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 : Config.getInstance().getMilestoneVotes()) {
                                if (StringUtils.getInstance().isInt(mileStoneName)) {
                                    int mileStone = Integer.parseInt(mileStoneName);
                                    inv.addButton(inv.getNextSlot(), new BInventoryButton("" + mileStone, new String[] { "Enabled: " + Config.getInstance().getMilestoneRewardEnabled(mileStone), "&cClick to set wether this has been completed or not" }, new ItemStack(Material.STONE)) {

                                        @Override
                                        public void onClick(ClickEvent clickEvent) {
                                            if (StringUtils.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");
                                                User 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);
                                                        User 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) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.Ben12345rocks.VotingPlugin.Objects.User) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) ValueRequest(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory) VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) NumberListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener) ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) BooleanListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener) StringListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack)

Example 18 with User

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

the class Commands method best.

public String[] best(CommandSender sender, String name) {
    ArrayList<String> msg = new ArrayList<String>();
    msg.add(config.getFormatCommandsVoteBestTitle());
    msg.addAll(config.getFormatCommandsVoteBestLines());
    User user = UserManager.getInstance().getVotingPluginUser(name);
    HashMap<String, String> placeholders = new HashMap<String, String>();
    placeholders.put("HighestDailyTotal", "" + user.getHighestDailyTotal());
    placeholders.put("HighestWeeklyTotal", "" + user.getHighestWeeklyTotal());
    placeholders.put("HighestMonthlyTotal", "" + user.getHighestMonthlyTotal());
    placeholders.put("player", name);
    msg = ArrayUtils.getInstance().replacePlaceHolder(msg, placeholders);
    return ArrayUtils.getInstance().convert(ArrayUtils.getInstance().colorize(msg));
}
Also used : User(com.Ben12345rocks.VotingPlugin.Objects.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 19 with User

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

the class Commands method sendTopVoterDailyScoreBoard.

/**
 * Send top voter daily score board.
 *
 * @param player
 *            the player
 * @param page
 *            the page
 */
public void sendTopVoterDailyScoreBoard(Player player, int page) {
    if (AdvancedCoreHook.getInstance().isSendScoreboards()) {
        int pagesize = Config.getInstance().getFormatPageSize();
        ArrayList<User> users = plugin.convertSet(plugin.topVoterDaily.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%", "Daily"));
        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.topVoterDaily.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 20 with User

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

the class Commands method voteCommandTotalAll.

/**
 * Vote command total all.
 *
 * @return the string[]
 */
public String[] voteCommandTotalAll() {
    ArrayList<String> msg = new ArrayList<String>();
    ArrayList<String> uuids = UserManager.getInstance().getAllUUIDs();
    int daily = 0;
    int weekly = 0;
    int month = 0;
    int all = 0;
    for (String uuid : uuids) {
        User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
        daily += user.getDailyTotal();
        weekly += user.getWeeklyTotal();
        month += user.getMonthTotal();
        all += user.getAllTimeTotal();
    }
    for (String s : config.getFormatCommandsVoteTotalAll()) {
        String str = StringUtils.getInstance().replaceIgnoreCase(s, "%DailyTotal%", "" + daily);
        str = StringUtils.getInstance().replaceIgnoreCase(str, "%WeeklyTotal%", "" + weekly);
        str = StringUtils.getInstance().replaceIgnoreCase(str, "%MonthlyTotal%", "" + month);
        str = StringUtils.getInstance().replaceIgnoreCase(str, "%AllTimeTotal%", "" + all);
        msg.add(str);
    }
    msg = ArrayUtils.getInstance().colorize(msg);
    return ArrayUtils.getInstance().convert(msg);
}
Also used : User(com.Ben12345rocks.VotingPlugin.Objects.User) ArrayList(java.util.ArrayList) UUID(com.Ben12345rocks.AdvancedCore.Objects.UUID)

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