use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.
the class VoteTopVoterLastMonth method onChest.
@Override
public void onChest(Player player) {
Set<Entry<TopVoterPlayer, Integer>> users = null;
users = plugin.getLastMonthTopVoter().entrySet();
BInventory inv = new BInventory(plugin.getGui().getChestVoteTopName());
inv.addPlaceholder("topvoter", "Last Month");
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
inv.dontClose();
}
int pos = 1;
for (Entry<TopVoterPlayer, Integer> entry : users) {
ItemBuilder playerItem;
if (plugin.getGui().isChestVoteTopUseSkull()) {
playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
} else {
playerItem = new ItemBuilder(Material.valueOf(plugin.getGui().getChestVoteTopPlayerItemMaterial()));
}
playerItem.setLore(new ArrayList<String>());
inv.addButton(new BInventoryButton(playerItem.setName(plugin.getGui().getChestVoteTopItemName()).addLoreLine(plugin.getGui().getChestVoteTopItemLore()).addPlaceholder("position", "" + pos).addPlaceholder("player", entry.getKey().getPlayerName()).addPlaceholder("votes", "" + entry.getValue())) {
@Override
public void onClick(ClickEvent clickEvent) {
TopVoterPlayer user = (TopVoterPlayer) getData("User");
new VoteGUI(plugin, player, user.getUser()).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
}
}.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
pos++;
}
if (plugin.getGui().getChestVoteTopBackButton()) {
inv.getPageButtons().add(plugin.getCommandLoader().getBackButton(user).setSlot(1));
}
inv.setPages(true);
inv.setMaxInvSize(plugin.getGui().getChestVoteTopSize());
inv.openInventory(player);
}
use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.
the class SignHandler method updateLines.
/**
* Update lines.
*/
public void updateLines() {
lines = new ArrayList<String>();
checkValidSign();
if (position != 0) {
String line1 = plugin.getConfigFile().getFormatSignTopVoterSignLine1();
String line2 = plugin.getConfigFile().getFormatSignTopVoterSignLine2();
String line3 = plugin.getConfigFile().getFormatSignTopVoterSignLine3();
String line4 = plugin.getConfigFile().getFormatSignTopVoterSignLine4();
lines.add(line1);
lines.add(line2);
lines.add(line3);
lines.add(line4);
ArrayList<TopVoterPlayer> users = null;
if (data.equalsIgnoreCase("all")) {
users = plugin.convertSet(plugin.getTopVoter(TopVoter.AllTime).keySet());
} else if (data.equalsIgnoreCase("monthly")) {
users = plugin.convertSet(plugin.getTopVoter(TopVoter.Monthly).keySet());
} else if (data.equalsIgnoreCase("weekly")) {
users = plugin.convertSet(plugin.getTopVoter(TopVoter.Weekly).keySet());
} else if (data.equalsIgnoreCase("daily")) {
users = plugin.convertSet(plugin.getTopVoter(TopVoter.Daily).keySet());
}
if (users != null && users.size() >= position) {
TopVoterPlayer user = users.get(position - 1);
playerName = user.getPlayerName();
votes = 0;
if (data.equalsIgnoreCase("all")) {
votes = plugin.getTopVoter(TopVoter.AllTime).get(user);
} else if (data.equalsIgnoreCase("monthly")) {
votes = plugin.getTopVoter(TopVoter.Monthly).get(user);
} else if (data.equalsIgnoreCase("weekly")) {
votes = plugin.getTopVoter(TopVoter.Weekly).get(user);
} else if (data.equalsIgnoreCase("daily")) {
votes = plugin.getTopVoter(TopVoter.Daily).get(user);
}
for (int j = 0; j < lines.size(); j++) {
lines.set(j, lines.get(j).replace("%votes%", "" + votes).replace("%player%", playerName));
}
} else {
playerName = "No Player";
votes = 0;
for (int j = 0; j < lines.size(); j++) {
lines.set(j, lines.get(j).replace("%votes%", "" + votes).replace("%player%", playerName));
}
}
for (int j = 0; j < lines.size(); j++) {
lines.set(j, lines.get(j).replace("%SiteName%", data).replace("%position%", "" + position));
}
lines = ArrayUtils.getInstance().colorize(lines);
}
}
use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.
the class PlaceHolders method load.
public void load() {
placeholders.clear();
nonPlayerPlaceholders.clear();
// older placeholders, might be removed in the future
placeholders.add(new PlaceHolder<VotingPluginUser>("total") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getTotal(TopVoter.Monthly));
}
}.withDescription("Month total").updateDataKey("MonthTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("alltimetotal") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getTotal(TopVoter.AllTime));
}
}.withDescription("Alltime total").updateDataKey("AllTimeTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("lastmonthtotal") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getLastMonthTotal());
}
}.withDescription("Last month total").updateDataKey("LastMonthTotal"));
// end of older placeholders
placeholders.add(new PlaceHolder<VotingPluginUser>("DisableBroadcast") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getDisableBroadcast();
}
}.withDescription("Returns true/false if user has broadcast disabled").updateDataKey("DisableBroadcast"));
placeholders.add(new PlaceHolder<VotingPluginUser>("MilestoneCount") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getMilestoneCount();
}
}.withDescription("User milestonecount").updateDataKey("MilestoneCount"));
for (final String identifier : plugin.getGui().getChestShopIdentifiers()) {
if (plugin.getGui().getChestShopIdentifierLimit(identifier) > 0) {
placeholders.add(new PlaceHolder<VotingPluginUser>("VoteShopLimit_" + identifier) {
@Override
public String placeholderRequest(VotingPluginUser user, String ident) {
return "" + user.getVoteShopIdentifierLimit(identifier);
}
}.withDescription("User voteshop limit for " + identifier).updateDataKey("VoteShopLimit" + identifier));
}
}
for (final TopVoter top : TopVoter.values()) {
placeholders.add(new PlaceHolder<VotingPluginUser>("Total_" + top.toString()) {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getTotal(top));
}
}.withDescription("User total for " + top.getName()).updateDataKey(top.getColumnName()));
}
placeholders.add(new PlaceHolder<VotingPluginUser>("BestDailyTotal") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getHighestDailyTotal());
}
}.withDescription("Best daily total").updateDataKey("HighestDailyTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestWeeklyTotal") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getHighestWeeklyTotal());
}
}.withDescription("Best weekly total").updateDataKey("HighestWeeklyTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestMonthlyTotal") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getHighestMonthlyTotal());
}
}.withDescription("Best monthly total").updateDataKey("HighestMonthlyTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("DailyVoteStreak") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getDayVoteStreak());
}
}.withDescription("Current daily votestreak").updateDataKey("DayVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("WeeklyVoteStreak") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getWeekVoteStreak());
}
}.withDescription("Current weekly votestreak").updateDataKey("WeekVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("MonthVoteStreak") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getMonthVoteStreak());
}
}.withDescription("Current month votestreak").updateDataKey("MonthVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestDailyVoteStreak") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getBestDayVoteStreak());
}
}.withDescription("Best daily votestreak").updateDataKey("BestDayVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestWeeklyVoteStreak") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getBestWeekVoteStreak());
}
}.withDescription("Best weekly votestreak").updateDataKey("BestWeekVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestMonthVoteStreak") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getBestMonthVoteStreak());
}
}.withDescription("Best month votestreak").updateDataKey("BestMonthVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Points") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getPoints());
}
}.withDescription("User points").updateDataKey("Points"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Points_Format") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
return numberFormat.format(user.getPoints());
}
}.withDescription("User points").updateDataKey("Points"));
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVote") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Boolean.toString(user.canVoteAll());
}
}.withDescription("Return true/false if player can vote on all sites").updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVoteSites") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getSitesNotVotedOn();
}
}.withDescription("Return number of votesites available").updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Next_AnySite") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
if (user.canVoteAny()) {
return plugin.getConfigFile().getFormatCommandsVoteNextInfoCanVote();
}
long smallest = -1;
HashMap<Long, VoteSite> times = new HashMap<Long, VoteSite>();
for (VoteSite site : plugin.getVoteSites()) {
long t = user.voteNextDurationTime(site);
if (smallest == -1) {
smallest = t;
}
if (t < smallest) {
smallest = t;
}
times.put(t, site);
}
for (Entry<Long, VoteSite> entry : times.entrySet()) {
if (entry.getKey().longValue() == smallest) {
return user.voteCommandNextInfo(entry.getValue());
}
}
return "Error";
}
}.withDescription("How long until user can vote on anysite").updateDataKey("LastVotes"));
for (final VoteSite voteSite : plugin.getVoteSites()) {
placeholders.add(new PlaceHolder<VotingPluginUser>("Next_" + voteSite.getKey()) {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return user.voteCommandNextInfo(voteSite);
}
}.withDescription("How long until user can vote on " + voteSite.getKey()).updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Last_" + voteSite.getKey()) {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return user.voteCommandLastDuration(voteSite);
}
}.withDescription("How long ago user voted on " + voteSite.getKey()).updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVote_" + voteSite.getKey()) {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.canVoteSite(voteSite);
}
}.withDescription("Whether or not player can vote on " + voteSite.getKey()).updateDataKey("LastVotes"));
}
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_All_Position") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
}
return "";
}
}.withDescription("Get user top voter position"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_AllVotes_") {
@Override
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
if (num == number) {
return "" + entry.getValue().intValue();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user votes at position in top voter"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_All_") {
@Override
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
if (num == number) {
return entry.getKey().getPlayerName();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user at postion in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Month_Position") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
}
return "";
}
}.withDescription("Get user top voter position"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_Month_") {
@Override
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
if (num == number) {
return entry.getKey().getPlayerName();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user at position in top voter"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_MonthVotes_") {
@Override
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
if (num == number) {
return "" + entry.getValue().intValue();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user votes at position in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Week_Position") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
}
return "";
}
}.withDescription("Get user top voter position"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_Week_") {
@Override
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
if (num == number) {
return entry.getKey().getPlayerName();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user at postion in top voter"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_WeekVotes_") {
@Override
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
if (num == number) {
return "" + entry.getValue().intValue();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user votes at position in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Daily_Position") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
}
return "";
}
}.withDescription("Get user top voter position"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_Daily_") {
@Override
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
if (num == number) {
return entry.getKey().getPlayerName();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user at postion in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("VotePartyContributedVotes") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getVotePartyVotes();
}
}.useStartsWith().withDescription("See vote party placeholders contributed").updateDataKey("VotePartyVotes"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_DailyVotes_") {
@Override
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
if (num == number) {
return "" + entry.getValue().intValue();
}
num++;
}
return "";
}
}.useStartsWith().withDescription("Get user votes at position in top voter"));
// non players
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("VotePartyVotesCurrent") {
@Override
public String placeholderRequest(String identifier) {
return Integer.toString(plugin.getVoteParty().getTotalVotes());
}
}.withDescription("Current amount of voteparty votes"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("VotePartyVotesNeeded") {
@Override
public String placeholderRequest(String identifier) {
return Integer.toString(plugin.getVoteParty().getNeededVotes());
}
}.withDescription("Voteparty votes needed"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("VotePartyVotesRequired") {
@Override
public String placeholderRequest(String identifier) {
return Integer.toString(plugin.getVoteParty().getVotesRequired());
}
}.withDescription("Amount of votes needed for voteparty"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("BungeeVotePartyVotesCurrent") {
@Override
public String placeholderRequest(String identifier) {
if (plugin.getBungeeHandler() != null) {
return Integer.toString(plugin.getBungeeHandler().getBungeeVotePartyCurrent());
}
return "" + 0;
}
}.withDescription("Current amount of bungee voteparty votes"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("BungeeVotePartyVotesNeeded") {
@Override
public String placeholderRequest(String identifier) {
if (plugin.getBungeeHandler() != null) {
return Integer.toString(plugin.getBungeeHandler().getBungeeVotePartyRequired() - plugin.getBungeeHandler().getBungeeVotePartyCurrent());
}
return "" + 0;
}
}.withDescription("Voteparty bungee votes needed"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("BungeeVotePartyVotesRequired") {
@Override
public String placeholderRequest(String identifier) {
if (plugin.getBungeeHandler() != null) {
return Integer.toString(plugin.getBungeeHandler().getBungeeVotePartyRequired());
}
return "" + 0;
}
}.withDescription("Amount of votes needed for bungee voteparty"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalMonthTotal") {
@Override
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Monthly).values()) {
total += num;
}
return Integer.toString(total);
}
}.withDescription("Global month total"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalAllTimeTotal") {
@Override
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.AllTime).values()) {
total += num;
}
return Integer.toString(total);
}
}.withDescription("Global alltime total"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalWeeklyTotal") {
@Override
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Weekly).values()) {
total += num;
}
return Integer.toString(total);
}
}.withDescription("Global weekly total"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalDailyTotal") {
@Override
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Daily).values()) {
total += num;
}
return Integer.toString(total);
}
}.withDescription("Global daily total"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("TimeUntilDayReset") {
@Override
public String placeholderRequest(String identifier) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime offsetoclocktoday = plugin.getTimeChecker().getTime().withHour(0).withMinute(0);
LocalDateTime offsetoclocktomorrow = plugin.getTimeChecker().getTime().plusDays(1).withHour(0).withMinute(0);
String timeMsg = "%hours% Hours %minutes% Minutes";
Duration dur = null;
if (!now.isBefore(offsetoclocktoday)) {
dur = Duration.between(now, offsetoclocktomorrow);
} else {
dur = Duration.between(now, offsetoclocktoday);
}
int diffHours = (int) (dur.getSeconds() / (60 * 60));
long diffMinutes = dur.getSeconds() / 60 - diffHours * 60;
if (diffHours < 0) {
diffHours = diffHours * -1;
}
if (diffHours >= 24) {
diffHours = diffHours - 24;
}
if (diffMinutes < 0) {
diffMinutes = diffMinutes * -1;
}
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%hours%", Integer.toString(diffHours));
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%minutes%", Long.toString(diffMinutes));
return timeMsg;
}
}.withDescription("Time until plugin time day changes"));
Set<String> placeholdersSet = new HashSet<String>();
placeholdersSet.addAll(plugin.getConfigFile().getCachedPlaceholders());
if (plugin.getConfigFile().isAutoCachePlaceholders()) {
placeholdersSet.addAll(plugin.getServerData().getAutoCachedPlaceholder());
}
for (String toCache : placeholdersSet) {
if (toCache.startsWith("VotingPlugin")) {
toCache = toCache.substring("VotingPlugin_".length());
}
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.isUseStartsWith()) {
if (toCache.startsWith(placeholder.getIdentifier())) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
} else {
if (placeholder.getIdentifier().equalsIgnoreCase(toCache)) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
}
}
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
if (placeholder.isUseStartsWith()) {
if (toCache.startsWith(placeholder.getIdentifier())) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
} else {
if (placeholder.getIdentifier().equalsIgnoreCase(toCache)) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
}
}
}
plugin.getUserManager().getUserDataChange().add(new UserDataChanged() {
@Override
public void onChange(AdvancedCoreUser user, String... keys) {
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
if (placeholder.isUsesCache()) {
for (String key : keys) {
if (placeholder.getUpdateDataKey().equalsIgnoreCase(key)) {
VotingPluginUser vpUser = UserManager.getInstance().getVotingPluginUser(user);
for (String ident : placeholder.getCache().keySet()) {
placeholder.getCache().get(ident).put(vpUser.getJavaUUID(), placeholder.placeholderRequest(vpUser, ident));
plugin.devDebug("Updated cache for " + vpUser.getUUID() + " on " + key);
}
}
}
}
}
}
});
}
use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.
the class VotingPluginMain method update.
public void update() {
if (update || configFile.isAlwaysUpdate()) {
if (!updateStarted && plugin != null) {
if (!configFile.isUpdateWithPlayersOnlineOnly() || Bukkit.getOnlinePlayers().size() != 0) {
updateStarted = true;
update = false;
synchronized (plugin) {
if (plugin != null && plugin.isEnabled()) {
getUserManager().getDataManager().clearCacheBasic();
plugin.debug("Starting background task, current cached users: " + plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
placeholders.onUpdate();
int dataLoadLimit = getConfigFile().getPlayerDataLoadLimit();
try {
boolean extraBackgroundUpdate = configFile.isExtraBackgroundUpdate();
long startTime = System.currentTimeMillis();
LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>> voteToday = new LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>>();
LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>> tempTopVoter = new LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>>();
ArrayList<TopVoter> topVotersToCheck = new ArrayList<TopVoter>();
for (TopVoter top : TopVoter.values()) {
if (plugin.getConfigFile().getLoadTopVoter(top)) {
topVotersToCheck.add(top);
tempTopVoter.put(top, new LinkedHashMap<TopVoterPlayer, Integer>());
}
}
boolean topVoterIgnorePermissionUse = plugin.getConfigFile().getTopVoterIgnorePermission();
ArrayList<String> blackList = plugin.getConfigFile().getBlackList();
ArrayList<String> uuids = UserManager.getInstance().getAllUUIDs();
int currentDay = LocalDateTime.now().getDayOfMonth();
int currentDataLoad = 0;
for (String uuid : uuids) {
if (uuid != null && !uuid.isEmpty()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), false);
user.dontCache();
user.tempCache();
user.getUserData().updateCacheWithTemp();
if (!user.isBanned() && !blackList.contains(user.getPlayerName())) {
if (!topVoterIgnorePermissionUse || !user.isTopVoterIgnore()) {
for (TopVoter top : topVotersToCheck) {
int total = user.getTotal(top);
if (total > 0) {
tempTopVoter.get(top).put(user.getTopVoterPlayer(), total);
}
}
}
HashMap<VoteSite, LocalDateTime> times = new HashMap<VoteSite, LocalDateTime>();
for (Entry<VoteSite, Long> entry : user.getLastVotes().entrySet()) {
if (entry.getKey().isEnabled() && !entry.getKey().isHidden()) {
long time = entry.getValue();
if ((currentDay == MiscUtils.getInstance().getDayFromMili(time)) && (LocalDateTime.now().getMonthValue() == MiscUtils.getInstance().getMonthFromMili(time)) && (LocalDateTime.now().getYear() == MiscUtils.getInstance().getYearFromMili(time))) {
times.put(entry.getKey(), LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
}
}
}
if (times.keySet().size() > 0) {
voteToday.put(user.getTopVoterPlayer(), times);
}
}
if (!extraBackgroundUpdate) {
if (user.isOnline()) {
user.offVote();
}
}
plugin.getPlaceholders().onUpdate(user);
user.clearTempCache();
user = null;
if (dataLoadLimit > 0) {
currentDataLoad++;
if (currentDataLoad >= dataLoadLimit) {
currentDataLoad -= dataLoadLimit;
Thread.sleep(1000);
}
}
}
}
update = false;
long time1 = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Finished loading player data in " + time1 + " seconds, " + uuids.size() + " users, " + plugin.getStorageType().toString() + ", data load limit: " + dataLoadLimit);
time1 = System.currentTimeMillis();
topVoterHandler.updateTopVoters(tempTopVoter);
setVoteToday(voteToday);
serverData.updateValues();
getSigns().updateSigns();
tempTopVoter = null;
time1 = ((System.currentTimeMillis() - time1) / 1000);
long totalTime = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Background task finished. Final processing took " + time1 + " seconds. Total time: " + totalTime + " seconds");
plugin.extraDebug("Current cached users: " + plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
checkFirstTimeLoaded();
} catch (Exception ex) {
if (plugin != null) {
plugin.getLogger().info("Looks like something went wrong");
}
ex.printStackTrace();
}
}
}
updateStarted = false;
}
}
}
}
use of com.bencodez.votingplugin.topvoter.TopVoterPlayer 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