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);
}
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);
}
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);
}
}
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");
}
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");
}
}
Aggregations