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