Search in sources :

Example 11 with VotingPluginUser

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

the class VoteParty method giveRewards.

public void giveRewards(boolean forceBungee) {
    MiscUtils.getInstance().broadcast(plugin.getSpecialRewardsConfig().getVotePartyBroadcast());
    for (final String cmd : plugin.getSpecialRewardsConfig().getVotePartyCommands()) {
        Bukkit.getScheduler().runTask(plugin, new Runnable() {

            @Override
            public void run() {
                Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
            }
        });
    }
    if (plugin.getSpecialRewardsConfig().getVotePartyGiveAllPlayers()) {
        plugin.debug("Trying to give all players vote party");
        ArrayList<String> alreadyGotten = new ArrayList<String>();
        for (Player p : Bukkit.getOnlinePlayers()) {
            VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
            user.dontCache();
            if (!plugin.getSpecialRewardsConfig().isVotePartyGiveOnlinePlayersOnly() || user.isOnline()) {
                giveReward(user, forceBungee);
            }
            alreadyGotten.add(p.getUniqueId().toString());
        }
        for (String uuid : UserManager.getInstance().getAllUUIDs()) {
            if (!alreadyGotten.contains(uuid)) {
                VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
                user.dontCache();
                if (!plugin.getSpecialRewardsConfig().isVotePartyGiveOnlinePlayersOnly() || user.isOnline()) {
                    giveReward(user, forceBungee);
                }
            }
        }
    } else {
        plugin.debug("Trying to give all voted players vote party");
        plugin.debug(ArrayUtils.getInstance().makeStringList(getVotedUsers()));
        for (String uuid : getVotedUsers()) {
            VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
            user.dontCache();
            if (!plugin.getSpecialRewardsConfig().isVotePartyGiveOnlinePlayersOnly() || user.isOnline()) {
                giveReward(user, forceBungee);
            }
        }
    }
    reset(false);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 12 with VotingPluginUser

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

the class VoteURL method onChest.

@Override
public void onChest(Player player) {
    // normal GUI
    BInventory inv = new BInventory(plugin.getGui().getChestVoteURLName());
    if (plugin.getGui().getChestVoteURLViewAllUrlsButtonEnabled()) {
        ItemBuilder builderAll = getItemAll();
        inv.addButton(new UpdatingBInventoryButton(builderAll, 5000, 5000) {

            @Override
            public void onClick(ClickEvent event) {
                VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(event.getPlayer());
                json = true;
                user.sendMessage(getChat(player));
            }

            @Override
            public ItemBuilder onUpdate(Player player) {
                return getItemAll();
            }
        });
    }
    int startSlot = plugin.getGui().getChestVoteURLAllUrlsButtonStartSlot();
    for (final VoteSite voteSite : plugin.getVoteSites()) {
        if (!voteSite.isHidden()) {
            ItemBuilder builder = getItemVoteSite(voteSite);
            if (startSlot >= 0) {
                builder.setSlot(startSlot);
                startSlot++;
            }
            inv.addButton(new UpdatingBInventoryButton(builder, 5000, 5000) {

                @Override
                public void onClick(ClickEvent event) {
                    Player player = event.getPlayer();
                    if (player != null) {
                        VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
                        user.sendMessage(StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getChestVoteURLURLText(), "voteurl", voteSite.getVoteURL()), "sitename", voteSite.getDisplayName()), "player", player.getName()));
                    }
                }

                @Override
                public ItemBuilder onUpdate(Player player) {
                    return getItemVoteSite(voteSite);
                }
            });
        }
    }
    for (final String str : plugin.getGui().getChestVoteURLExtraItems()) {
        inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteURLExtraItemsItem(str))) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                new RewardBuilder(plugin.getGui().getData(), "CHEST.VoteURL.ExtraItems." + str + ".Rewards").setGiveOffline(false).send(clickEvent.getPlayer());
            }
        });
    }
    if (plugin.getGui().getChestVoteURLBackButton()) {
        inv.addButton(plugin.getCommandLoader().getBackButton(user));
    }
    inv.openInventory(player);
}
Also used : VoteSite(com.bencodez.votingplugin.objects.VoteSite) RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) UpdatingBInventoryButton(com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) Player(org.bukkit.entity.Player) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) UpdatingBInventoryButton(com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 13 with VotingPluginUser

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

the class VoteReminding method loadRemindChecking.

/**
 * Load remind checking.
 */
public void loadRemindChecking() {
    if (timer != null) {
        timer.cancel();
    }
    if (plugin.getConfigFile().getVoteRemindingRemindDelay() > 0) {
        timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                if (plugin != null && plugin.isEnabled()) {
                    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                        VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
                        checkRemind(user);
                    }
                } else {
                    cancel();
                }
            }
        }, 1000 * 30, plugin.getConfigFile().getVoteRemindingRemindDelay() * 1000 * 60);
    }
}
Also used : Player(org.bukkit.entity.Player) Timer(java.util.Timer) TimerTask(java.util.TimerTask) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 14 with VotingPluginUser

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

the class VoteTester method testRewards.

public void testRewards(int amount, String name, String rewardName) {
    long time1 = System.currentTimeMillis();
    ArrayList<Long> timesPerReward = new ArrayList<Long>();
    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(name);
    Reward reward = RewardHandler.getInstance().getReward(rewardName);
    int rewardsGiven = 0;
    for (int i = 0; i < amount; i++) {
        long start1 = System.currentTimeMillis();
        if (reward.canGiveReward(user, new RewardOptions())) {
            rewardsGiven++;
            RewardHandler.getInstance().giveReward(user, reward, new RewardOptions().setIgnoreRequirements(true));
        }
        long start2 = System.currentTimeMillis();
        timesPerReward.add(start2 - start1);
    }
    long time2 = System.currentTimeMillis();
    long time = time2 - time1;
    long timeTotal = 0;
    for (Long t : timesPerReward) {
        timeTotal += t.longValue();
    }
    long timePerRewardAvg = timeTotal / timesPerReward.size();
    VotingPluginMain.plugin.getLogger().info("Time to process rewards (" + amount + "): " + time + " ms, average per reward " + timePerRewardAvg + " ms. " + VotingPluginMain.plugin.getStorageType() + ", " + UserManager.getInstance().getAllUUIDs().size() + " users. " + rewardsGiven + " rewards given");
}
Also used : RewardOptions(com.bencodez.advancedcore.api.rewards.RewardOptions) ArrayList(java.util.ArrayList) Reward(com.bencodez.advancedcore.api.rewards.Reward) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 15 with VotingPluginUser

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

the class TopVoterHandler method onWeekChange.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWeekChange(WeekChangeEvent event) {
    long startTime = System.currentTimeMillis();
    synchronized (VotingPluginMain.plugin) {
        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.getTotal(TopVoter.Weekly) == 0 && user.getWeekVoteStreak() != 0) {
                    user.setWeekVoteStreak(0);
                } else {
                    if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage() || user.hasPercentageTotal(TopVoter.Weekly, plugin.getSpecialRewardsConfig().getVoteStreakRequirementWeek(), null)) {
                        user.addWeekVoteStreak();
                        plugin.getSpecialRewards().checkVoteStreak(user, "Week", plugin.getBungeeSettings().isUseBungeecoord());
                    }
                }
            }
            if (plugin.getConfigFile().isUseHighestTotals()) {
                if (user.getHighestWeeklyTotal() < user.getTotal(TopVoter.Weekly)) {
                    user.setHighestWeeklyTotal(user.getTotal(TopVoter.Weekly));
                }
            }
            user.clearTempCache();
        }
        if (plugin.getConfigFile().getStoreTopVotersWeekly()) {
            plugin.getLogger().info("Saving TopVoters Weekly");
            storeTopVoters(TopVoter.Weekly);
        }
        try {
            if (plugin.getSpecialRewardsConfig().isEnableWeeklyAwards()) {
                HashMap<Integer, String> places = handlePlaces(plugin.getSpecialRewardsConfig().getWeeklyPossibleRewardPlaces());
                int i = 0;
                int lastTotal = -1;
                @SuppressWarnings("unchecked") LinkedHashMap<TopVoterPlayer, Integer> clone = (LinkedHashMap<TopVoterPlayer, Integer>) plugin.getTopVoter(TopVoter.Weekly).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.giveWeeklyTopVoterAward(i, places.get(i));
                        }
                    }
                    lastTotal = entry.getValue().intValue();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) {
            if (plugin.getGui().getChestVoteShopResetWeekly(shopIdent)) {
                resetVoteShopLimit(shopIdent);
            }
        }
        resetTotals(TopVoter.Weekly);
        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)

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