use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class VoteNext method getChat.
@Override
public ArrayList<String> getChat(CommandSender sender) {
ArrayList<String> msg = new ArrayList<String>();
String playerName = user.getPlayerName();
msg.add(StringParser.getInstance().colorize(StringParser.getInstance().replaceIgnoreCase(plugin.getConfigFile().getFormatCommandsVoteNextTitle(), "%player%", playerName)));
for (VoteSite voteSite : plugin.getVoteSites()) {
if (!voteSite.isHidden()) {
String msgLine = plugin.getConfigFile().getFormatCommandsVoteNextLayout();
msgLine = StringParser.getInstance().replaceIgnoreCase(msgLine, "%info%", user.voteCommandNextInfo(voteSite));
msgLine = StringParser.getInstance().replaceIgnoreCase(msgLine, "%SiteName%", voteSite.getDisplayName());
msg.add(StringParser.getInstance().colorize(msgLine));
}
}
return msg;
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class VotingPluginUser method getLastVoteTimesSorted.
/**
* Gets the last vote times sorted.
*
* @return the last vote times sorted
*/
public HashMap<VoteSite, Long> getLastVoteTimesSorted() {
LinkedHashMap<VoteSite, Long> times = new LinkedHashMap<VoteSite, Long>();
for (VoteSite voteSite : plugin.getVoteSites()) {
times.put(voteSite, getTime(voteSite));
}
LinkedHashMap<VoteSite, Long> sorted = new LinkedHashMap<>(times.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
return sorted;
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class VotingPluginUser method checkAllVotes.
/**
* Check all votes.
*
* @return true, if successful
*/
public boolean checkAllVotes() {
VotingPluginUser user = this;
ArrayList<Integer> months = new ArrayList<Integer>();
ArrayList<Integer> days = new ArrayList<Integer>();
for (VoteSite voteSite : plugin.getVoteSites()) {
if (voteSite.isEnabled() && !voteSite.isHidden()) {
long time = user.getTime(voteSite);
if (time != 0) {
months.add(MiscUtils.getInstance().getMonthFromMili(time));
days.add(MiscUtils.getInstance().getDayFromMili(time));
} else {
return false;
}
}
}
// check months
for (int i = 0; i < months.size(); i++) {
if (!months.get(0).equals(months.get(i))) {
return false;
}
}
// check days
for (int i = 0; i < days.size(); i++) {
if (!days.get(0).equals(days.get(i))) {
return false;
}
}
return true;
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class PlayerVoteListener method onplayerVote.
/**
* On votifer event.
*
* @param event the event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onplayerVote(PlayerVoteEvent event) {
if (!plugin.isEnabled()) {
return;
}
String playerName = event.getPlayer();
if (!PlayerUtils.getInstance().isValidUser(playerName, plugin.getConfigFile().isAllowUnJoinedCheckServer())) {
if (!plugin.getConfigFile().isAllowUnjoined()) {
plugin.getLogger().warning("Player " + playerName + " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
if (event.isBungee() && plugin.getBungeeSettings().isRemoveInvalidUsers()) {
UserManager.getInstance().getVotingPluginUser(playerName).remove();
}
return;
}
}
if (playerName.isEmpty()) {
plugin.getLogger().warning("Empty player name for vote");
return;
}
if (event.isBungee()) {
plugin.debug("BungeePlayerVote forcebungee: " + event.isForceBungee() + ", bungeetotals: " + event.getBungeeTextTotals());
if (plugin.getBungeeSettings().isTriggerVotifierEvent()) {
new BungeeVotifierEvent().send(plugin, event);
}
}
VoteSite voteSite = event.getVoteSite();
if (voteSite == null) {
voteSite = plugin.getVoteSite(plugin.getVoteSiteName(true, event.getServiceSite()), true);
}
// check valid service sites
if (voteSite == null) {
if (!plugin.getConfigFile().isDisableNoServiceSiteMessage()) {
plugin.getLogger().warning("No voting site with the service site: '" + event.getServiceSite() + "'");
ArrayList<String> services = new ArrayList<String>();
for (VoteSite site : plugin.getVoteSites()) {
services.add(site.getServiceSite());
}
plugin.getLogger().warning("Current known service sites: " + ArrayUtils.getInstance().makeStringList(services));
}
return;
}
if (!voteSite.isEnabled()) {
plugin.debug("Votesite: " + voteSite.getKey() + " is not enabled");
return;
}
VotingPluginUser user = null;
if (event.getVotingPluginUser() != null) {
user = event.getVotingPluginUser();
} else {
user = UserManager.getInstance().getVotingPluginUser(playerName);
}
if (voteSite.isWaitUntilVoteDelay() && !user.canVoteSite(voteSite)) {
plugin.getLogger().info(user.getPlayerName() + " must wait until votedelay is over, ignoring vote");
return;
}
synchronized (object) {
if (!plugin.isEnabled()) {
return;
}
// reupdate cache
user.clearCache();
user.cache();
user.updateName(true);
// vote party
plugin.getVoteParty().vote(user, event.isRealVote(), event.isForceBungee());
if (event.isBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
// broadcast vote if enabled in config
if (plugin.getConfigFile().isBroadcastVotesEnabled() && (plugin.getBungeeSettings().isBungeeBroadcast() || !event.isBungee())) {
if (!plugin.getConfigFile().getFormatBroadcastWhenOnline() || user.isOnline()) {
voteSite.broadcastVote(user);
}
}
}
if (plugin.getBroadcastHandler() != null) {
plugin.getBroadcastHandler().onVote(playerName);
}
// update last vote time
if (event.getTime() != 0) {
user.setTime(voteSite, event.getTime());
} else {
user.setTime(voteSite);
}
plugin.getCoolDownCheck().vote(user);
// try logging to file
if (plugin.getConfigFile().isLogVotesToFile()) {
try {
plugin.logVote(LocalDateTime.now().atZone(ZoneId.systemDefault()).toLocalDateTime(), playerName, voteSite.getKey());
} catch (Exception e) {
e.printStackTrace();
}
}
// check first vote rewards
plugin.getSpecialRewards().checkFirstVote(user, event.isForceBungee());
plugin.getSpecialRewards().checkFirstVoteToday(user, event.isForceBungee());
if (user.isReminded() && plugin.getConfigFile().getVoteRemindingRemindOnlyOnce()) {
user.setReminded(false);
}
// check if player has voted on all sites in one day
if (((user.isOnline() || voteSite.isGiveOffline()) && plugin.getOptions().isProcessRewards()) || event.isBungee()) {
boolean online = true;
if (event.isBungee()) {
online = event.isWasOnline();
}
user.playerVote(voteSite, online, false, event.isForceBungee());
user.sendVoteEffects(online);
if (plugin.getConfigFile().isCloseInventoryOnVote()) {
user.closeInv();
}
} else {
user.addOfflineVote(voteSite.getKey());
plugin.debug("Offline vote set for " + playerName + " (" + user.getUUID() + ") on " + voteSite.getKey());
}
// add to total votes
if ((plugin.getConfigFile().isCountFakeVotes() || event.isRealVote()) && event.isAddTotals()) {
if (plugin.getConfigFile().isAddTotals()) {
user.addTotal();
user.addTotalDaily();
user.addTotalWeekly();
}
user.addPoints();
}
user.checkDayVoteStreak(event.isForceBungee());
// other rewards
plugin.getSpecialRewards().checkAllSites(user, event.isForceBungee());
plugin.getSpecialRewards().checkCumualativeVotes(user, event.getBungeeTextTotals(), event.isForceBungee());
plugin.getSpecialRewards().checkMilestone(user, event.getBungeeTextTotals(), event.isForceBungee());
if (plugin.getBungeeSettings().isUseBungeecoord()) {
if (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.MYSQL)) {
final String uuid = user.getUUID();
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (Bukkit.getOnlinePlayers().size() > 0) {
plugin.getPluginMessaging().sendPluginMessage("VoteUpdate", uuid);
}
}
}, 40);
}
}
if (!user.isOnline()) {
user.clearCache();
}
}
PlayerPostVoteEvent postVoteEvent = new PlayerPostVoteEvent(voteSite, user, event.isRealVote(), event.isForceBungee());
plugin.getServer().getPluginManager().callEvent(postVoteEvent);
plugin.setUpdate(true);
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class VoteLast method onChest.
@Override
public void onChest(Player player) {
BInventory inv = new BInventory(plugin.getGui().getChestVoteLastName());
inv.addPlaceholder("player", user.getPlayerName());
for (VoteSite site : plugin.getVoteSites()) {
if (!site.isHidden()) {
inv.addButton(inv.getNextSlot(), new UpdatingBInventoryButton(site.getItem().setName(site.getDisplayName()).setLore(user.voteCommandLastGUILine(site)).setAmountNone(1), 1000, 1000) {
@Override
public void onClick(ClickEvent clickEvent) {
}
@Override
public ItemBuilder onUpdate(Player p) {
return site.getItem().setName(site.getDisplayName()).setLore(user.voteCommandLastGUILine(site)).setAmountNone(1);
}
});
}
}
if (plugin.getGui().getChestVoteLastBackButton()) {
inv.addButton(plugin.getCommandLoader().getBackButton(user));
}
inv.openInventory(player);
}
Aggregations