Search in sources :

Example 6 with RewardOptions

use of com.bencodez.advancedcore.api.rewards.RewardOptions in project VotingPlugin by Ben12345rocks.

the class SpecialRewards method giveFirstVoteTodayRewards.

public void giveFirstVoteTodayRewards(VotingPluginUser user, boolean online, boolean forceBungee) {
    PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.FIRSTVOTETODAY);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    RewardHandler.getInstance().giveReward(user, plugin.getSpecialRewardsConfig().getData(), plugin.getSpecialRewardsConfig().getFirstVoteTodayRewardsPath(), new RewardOptions().setServer(forceBungee).setOnline(online));
}
Also used : RewardOptions(com.bencodez.advancedcore.api.rewards.RewardOptions) PlayerSpecialRewardEvent(com.bencodez.votingplugin.events.PlayerSpecialRewardEvent)

Example 7 with RewardOptions

use of com.bencodez.advancedcore.api.rewards.RewardOptions in project VotingPlugin by Ben12345rocks.

the class SpecialRewards method giveFirstVoteRewards.

public void giveFirstVoteRewards(VotingPluginUser user, boolean online, boolean forceBungee) {
    PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.FIRSTVOTE);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    RewardHandler.getInstance().giveReward(user, plugin.getSpecialRewardsConfig().getData(), plugin.getSpecialRewardsConfig().getFirstVoteRewardsPath(), new RewardOptions().setServer(forceBungee).setOnline(online));
}
Also used : RewardOptions(com.bencodez.advancedcore.api.rewards.RewardOptions) PlayerSpecialRewardEvent(com.bencodez.votingplugin.events.PlayerSpecialRewardEvent)

Example 8 with RewardOptions

use of com.bencodez.advancedcore.api.rewards.RewardOptions 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 9 with RewardOptions

use of com.bencodez.advancedcore.api.rewards.RewardOptions in project VotingPlugin by Ben12345rocks.

the class VoteShopConfirm method onChest.

@Override
public void onChest(Player player) {
    PlayerUtils.getInstance().setPlayerMeta(player, "ident", identifier);
    BInventory inv = new BInventory(plugin.getGui().getChestShopConfirmPurchaseTitle());
    inv.dontClose();
    inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopConfirmPurchaseYesItem())) {

        @Override
        public void onClick(ClickEvent event) {
            user.clearCache();
            int points = plugin.getGui().getChestShopIdentifierCost(identifier);
            int limit = plugin.getGui().getChestShopIdentifierLimit(identifier);
            HashMap<String, String> placeholders = new HashMap<String, String>();
            placeholders.put("identifier", identifier);
            placeholders.put("points", "" + points);
            placeholders.put("limit", "" + limit);
            if (user.removePoints(points)) {
                plugin.getLogger().info("VoteShop: " + user.getPlayerName() + "/" + user.getUUID() + " bought " + identifier + " for " + points);
                RewardHandler.getInstance().giveReward(user, plugin.getGui().getData(), plugin.getGui().getChestShopIdentifierRewardsPath(identifier), new RewardOptions().setPlaceholders(placeholders));
                user.sendMessage(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getCHESTVoteShopPurchase(identifier), placeholders));
                if (limit > 0) {
                    user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
                }
            } else {
                user.sendMessage(StringParser.getInstance().replacePlaceHolder(plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
            }
            if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
                event.getButton().getInv().closeInv(player, null);
            } else {
                new VoteShop(plugin, event.getPlayer(), user).open();
            }
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopConfirmPurchaseNoItem())) {

        @Override
        public void onClick(ClickEvent event) {
            if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
                event.getButton().getInv().closeInv(player, null);
            } else {
                new VoteShop(plugin, event.getPlayer(), user).open();
            }
        }
    });
    inv.openInventory(player);
}
Also used : RewardOptions(com.bencodez.advancedcore.api.rewards.RewardOptions) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) HashMap(java.util.HashMap) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) BInventory(com.bencodez.advancedcore.api.inventory.BInventory)

Aggregations

RewardOptions (com.bencodez.advancedcore.api.rewards.RewardOptions)9 VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)5 HashMap (java.util.HashMap)4 Player (org.bukkit.entity.Player)4 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)3 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)3 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)3 PlayerSpecialRewardEvent (com.bencodez.votingplugin.events.PlayerSpecialRewardEvent)3 ArrayList (java.util.ArrayList)3 CommandHandler (com.bencodez.advancedcore.api.command.CommandHandler)2 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)2 AdminVoteHelp (com.bencodez.votingplugin.commands.gui.admin.AdminVoteHelp)2 AdminVotePlaceholdersPlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVotePlaceholdersPlayer)2 AdminVoteVotePlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVoteVotePlayer)2 AdminVoteVoteShop (com.bencodez.votingplugin.commands.gui.admin.voteshop.AdminVoteVoteShop)2 VoteTopVoter (com.bencodez.votingplugin.commands.gui.player.VoteTopVoter)2 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)2 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)2 CommandSender (org.bukkit.command.CommandSender)2 UpdatingBInventoryButton (com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton)1