Search in sources :

Example 26 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class TopVoterHandler method onDayChange.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDayChange(DayChangeEvent event) {
    synchronized (VotingPluginMain.plugin) {
        long startTime = System.currentTimeMillis();
        for (String uuid : UserManager.getInstance().getAllUUIDs()) {
            VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), false);
            user.dontCache();
            user.tempCache();
            user.getUserData().updateCacheWithTemp();
            if (plugin.getConfigFile().isUseVoteStreaks()) {
                if (!user.voteStreakUpdatedToday(LocalDateTime.now().minusDays(1))) {
                    if (user.getDayVoteStreak() != 0) {
                        user.setDayVoteStreak(0);
                    }
                }
            }
            if (plugin.getConfigFile().isUseHighestTotals()) {
                if (user.getHighestDailyTotal() < user.getTotal(TopVoter.Daily)) {
                    user.setHighestDailyTotal(user.getTotal(TopVoter.Daily));
                }
            }
            user.clearTempCache();
        }
        if (plugin.getConfigFile().getStoreTopVotersDaily()) {
            plugin.getLogger().info("Saving TopVoters Daily");
            storeTopVoters(TopVoter.Daily);
        }
        try {
            if (plugin.getSpecialRewardsConfig().isEnableDailyRewards()) {
                HashMap<Integer, String> places = handlePlaces(plugin.getSpecialRewardsConfig().getDailyPossibleRewardPlaces());
                int i = 0;
                int lastTotal = -1;
                @SuppressWarnings("unchecked") LinkedHashMap<TopVoterPlayer, Integer> clone = (LinkedHashMap<TopVoterPlayer, Integer>) plugin.getTopVoter(TopVoter.Daily).clone();
                for (Entry<TopVoterPlayer, Integer> entry : clone.entrySet()) {
                    VotingPluginUser user = entry.getKey().getUser();
                    user.dontCache();
                    if (!plugin.getConfigFile().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
                        if (plugin.getConfigFile().getTopVoterAwardsTies()) {
                            if (entry.getValue().intValue() != lastTotal) {
                                i++;
                            }
                        } else {
                            i++;
                        }
                        if (places.containsKey(i)) {
                            user.giveDailyTopVoterAward(i, places.get(i));
                        }
                    }
                    lastTotal = entry.getValue().intValue();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) {
            if (plugin.getGui().getChestVoteShopResetDaily(shopIdent)) {
                resetVoteShopLimit(shopIdent);
            }
        }
        resetTotals(TopVoter.Daily);
        if (plugin.getStorageType().equals(UserStorage.MYSQL)) {
            plugin.getMysql().clearCacheBasic();
        }
        plugin.getUserManager().getDataManager().clearCache();
        long now = ((System.currentTimeMillis() - startTime) / 1000);
        plugin.getLogger().info("Finished processing day change, took " + now + " seconds");
    }
}
Also used : VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser) LinkedHashMap(java.util.LinkedHashMap) EventHandler(org.bukkit.event.EventHandler)

Example 27 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class VoteToday method onChest.

@Override
public void onChest(Player player) {
    BInventory inv = new BInventory(plugin.getGui().getChestVoteTodayName());
    if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
        inv.dontClose();
    }
    for (TopVoterPlayer user : plugin.getVoteToday().keySet()) {
        for (VoteSite voteSite : plugin.getVoteToday().get(user).keySet()) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
            String timeString = plugin.getVoteToday().get(user).get(voteSite).format(formatter);
            String msg = plugin.getGui().getChestVoteTodayLine();
            HashMap<String, String> placeholders = new HashMap<String, String>();
            placeholders.put("VoteSite", voteSite.getDisplayName());
            placeholders.put("Time", timeString);
            msg = StringParser.getInstance().replacePlaceHolder(msg, placeholders);
            ItemBuilder item = null;
            if (plugin.getGui().isChestVoteTodayUseSkull() && !NMSManager.getInstance().isVersion("1.12")) {
                item = new ItemBuilder(user.getPlayerHead());
            } else {
                item = new ItemBuilder(plugin.getGui().getChestVoteTodayPlayerItem());
            }
            item.setName(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getChestVoteTodayIconTitle(), "player", user.getPlayerName()));
            item.setLore(msg);
            final UUID uuid = user.getUuid();
            inv.addButton(inv.getNextSlot(), new BInventoryButton(item) {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(uuid);
                    new VoteGUI(plugin, player, user).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
                }
            });
        }
    }
    if (plugin.getGui().getChestVoteTodayBackButton()) {
        inv.addButton(plugin.getCommandLoader().getBackButton(user));
    }
    inv.openInventory(player);
}
Also used : HashMap(java.util.HashMap) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) VoteSite(com.bencodez.votingplugin.objects.VoteSite) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) UUID(java.util.UUID) DateTimeFormatter(java.time.format.DateTimeFormatter) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Aggregations

VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)27 Player (org.bukkit.entity.Player)11 VoteSite (com.bencodez.votingplugin.objects.VoteSite)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)6 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)5 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)5 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)5 RewardOptions (com.bencodez.advancedcore.api.rewards.RewardOptions)5 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)5 TopVoterPlayer (com.bencodez.votingplugin.topvoter.TopVoterPlayer)5 EventHandler (org.bukkit.event.EventHandler)5 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)4 AdminVotePlaceholdersPlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVotePlaceholdersPlayer)3 AdminVoteVotePlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVoteVotePlayer)3 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)3 BookWrapper (com.bencodez.advancedcore.api.bookgui.BookWrapper)2 Layout (com.bencodez.advancedcore.api.bookgui.Layout)2 CommandHandler (com.bencodez.advancedcore.api.command.CommandHandler)2