Search in sources :

Example 21 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class BungeeHandler method load.

public void load() {
    plugin.debug("Loading bungee handler");
    method = BungeeMethod.getByName(plugin.getBungeeSettings().getBungeeMethod());
    plugin.getLogger().info("Using BungeeMethod: " + method.toString());
    if (method.equals(BungeeMethod.MYSQL)) {
        plugin.registerBungeeChannels("vp:vp");
    } else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
        plugin.registerBungeeChannels("vp:vp");
        bungeeVotePartyCurrent = plugin.getServerData().getBungeeVotePartyCurrent();
        bungeeVotePartyRequired = plugin.getServerData().getBungeeVotePartyRequired();
        plugin.getPluginMessaging().setDebug(plugin.getBungeeSettings().isBungeeDebug());
        plugin.getPluginMessaging().add(new PluginMessageHandler("Vote") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                if (args.size() > 8) {
                    int bungeeVersion = Integer.parseInt(args.get(8));
                    if (bungeeVersion != BungeeVersion.getPluginMessageVersion()) {
                        plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                        return;
                    }
                    String player = args.get(0);
                    String uuid = args.get(1);
                    String service = args.get(2);
                    long time = Long.parseLong(args.get(3));
                    plugin.debug("pluginmessaging vote received from " + player + "/" + uuid + " on " + service);
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), player);
                    boolean wasOnline = Boolean.valueOf(args.get(4));
                    BungeeMessageData text = new BungeeMessageData(args.get(6));
                    bungeeVotePartyCurrent = text.getVotePartyCurrent();
                    bungeeVotePartyRequired = text.getVotePartyRequired();
                    plugin.getPlaceholders().onBungeeVotePartyUpdate();
                    boolean setTotals = Boolean.valueOf(args.get(7));
                    user.clearCache();
                    boolean broadcast = true;
                    boolean bungeeBroadcast = false;
                    if (args.size() > 9) {
                        bungeeBroadcast = Boolean.valueOf(args.get(9));
                    }
                    if (!bungeeBroadcast) {
                        if (!plugin.getBungeeSettings().isBungeeBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
                            if (wasOnline || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
                                VoteSite site = plugin.getVoteSite(service, true);
                                if (site != null) {
                                    site.broadcastVote(user, false);
                                    broadcast = false;
                                } else {
                                    plugin.getLogger().warning("No votesite for " + service);
                                }
                            }
                        }
                    } else {
                        broadcast = false;
                    }
                    user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    if (Boolean.valueOf(args.get(5))) {
                        plugin.getServerData().addServiceSite(service);
                    }
                } else {
                    plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VoteOnline") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                if (args.size() > 8) {
                    int bungeeVersion = Integer.parseInt(args.get(8));
                    if (bungeeVersion != BungeeVersion.getPluginMessageVersion()) {
                        plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                        return;
                    }
                    String player = args.get(0);
                    String uuid = args.get(1);
                    String service = args.get(2);
                    long time = Long.parseLong(args.get(3));
                    BungeeMessageData text = new BungeeMessageData(args.get(6));
                    bungeeVotePartyCurrent = text.getVotePartyCurrent();
                    bungeeVotePartyRequired = text.getVotePartyRequired();
                    plugin.getPlaceholders().onBungeeVotePartyUpdate();
                    plugin.debug("pluginmessaging voteonline received from " + player + "/" + uuid + " on " + service);
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), player);
                    user.clearCache();
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    boolean setTotals = Boolean.valueOf(args.get(7));
                    boolean wasOnline = Boolean.valueOf(args.get(4));
                    boolean broadcast = true;
                    boolean bungeeBroadcast = false;
                    if (args.size() > 9) {
                        bungeeBroadcast = Boolean.valueOf(args.get(9));
                    }
                    if (!bungeeBroadcast) {
                        if (!plugin.getBungeeSettings().isBungeeBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
                            if (Boolean.valueOf(args.get(4)) || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
                                VoteSite site = plugin.getVoteSite(service, true);
                                if (site != null) {
                                    site.broadcastVote(user, false);
                                    broadcast = false;
                                } else {
                                    plugin.getLogger().warning("No votesite for " + service);
                                }
                            }
                        }
                    } else {
                        broadcast = false;
                    }
                    user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    if (Boolean.valueOf(args.get(5))) {
                        plugin.getServerData().addServiceSite(service);
                    }
                } else {
                    plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VoteUpdate") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                String player = args.get(0);
                plugin.debug("pluginmessaging voteupdate received for " + player);
                VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(player));
                user.clearCache();
                user.offVote();
                if (args.size() > 2) {
                    bungeeVotePartyCurrent = Integer.parseInt(args.get(1));
                    bungeeVotePartyRequired = Integer.parseInt(args.get(2));
                }
                plugin.setUpdate(true);
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VoteBroadcast") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                if (args.size() > 2) {
                    String uuid = args.get(0);
                    String service = args.get(2);
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), args.get(1));
                    VoteSite site = plugin.getVoteSite(service, true);
                    if (site != null) {
                        site.broadcastVote(user, false);
                    } else {
                        plugin.getLogger().warning("No votesite for " + service);
                    }
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("Status") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                String server = args.get(0);
                plugin.getPluginMessaging().sendPluginMessage("statusokay", server);
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBungee") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                for (Player p : Bukkit.getOnlinePlayers()) {
                    new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBroadcast") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                String broadcast = args.get(0);
                MiscUtils.getInstance().broadcast(broadcast);
            }
        });
    } else if (method.equals(BungeeMethod.SOCKETS)) {
        encryptionHandler = new EncryptionHandler(new File(plugin.getDataFolder(), "secretkey.key"));
        clientHandler = new ClientHandler(plugin.getBungeeSettings().getBungeeServerHost(), plugin.getBungeeSettings().getBungeeServerPort(), encryptionHandler, plugin.getBungeeSettings().isBungeeDebug());
        socketHandler = new SocketHandler(plugin.getVersion(), plugin.getBungeeSettings().getSpigotServerHost(), plugin.getBungeeSettings().getSpigotServerPort(), encryptionHandler, plugin.getBungeeSettings().isBungeeDebug());
        socketHandler.add(new SocketReceiver("bungeevote") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 5) {
                    plugin.extraDebug("BungeeVote from " + data[2] + ", processing");
                    String uuid = data[1];
                    VotingPluginUser user = null;
                    if (!uuid.isEmpty()) {
                        user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
                    } else {
                        user = UserManager.getInstance().getVotingPluginUser(data[2]);
                    }
                    user.clearCache();
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    user.bungeeVote(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
                }
            }
        });
        socketHandler.add(new SocketReceiver("bungeevoteonline") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 5) {
                    plugin.extraDebug("BungeeVoteOnline from " + data[2] + ", processing");
                    String uuid = data[1];
                    VotingPluginUser user = null;
                    if (!uuid.isEmpty()) {
                        user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
                    } else {
                        user = UserManager.getInstance().getVotingPluginUser(data[2]);
                    }
                    user.clearCache();
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    user.bungeeVoteOnline(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
                }
            }
        });
        socketHandler.add(new SocketReceiver("BungeeBroadcast") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 2) {
                    VoteSite site = plugin.getVoteSite(data[1], true);
                    String p = data[3];
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
                    if (site != null) {
                        site.broadcastVote(user, false);
                    } else {
                        plugin.getLogger().warning("No votesite for " + data[1]);
                    }
                }
            }
        });
        socketHandler.add(new SocketReceiver("Status") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 0) {
                    plugin.getLogger().info("Received status command, sending status back");
                    sendData("StatusOkay", plugin.getOptions().getServer());
                }
            }
        });
        socketHandler.add(new SocketReceiver("BungeeUpdate") {

            @Override
            public void onReceive(String[] data) {
                plugin.setUpdate(true);
            }
        });
        socketHandler.add(new SocketReceiver("VotePartyBungee") {

            @Override
            public void onReceive(String[] data) {
                for (Player p : Bukkit.getOnlinePlayers()) {
                    new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
                }
            }
        });
        socketHandler.add(new SocketReceiver("VotePartyBroadcast") {

            @Override
            public void onReceive(String[] data) {
                String broadcast = data[0];
                MiscUtils.getInstance().broadcast(broadcast);
            }
        });
        if (plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
            plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) SocketHandler(com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler) SocketReceiver(com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver) ArrayList(java.util.ArrayList) ClientHandler(com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler) PluginMessageHandler(com.bencodez.advancedcore.bungeeapi.pluginmessage.PluginMessageHandler) EncryptionHandler(com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler) VoteSite(com.bencodez.votingplugin.objects.VoteSite) RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) BungeeMessageData(com.bencodez.votingplugin.bungee.BungeeMessageData) File(java.io.File) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 22 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class AdminVotePlaceholders method onBook.

@Override
public void onBook(Player player) {
    BookWrapper book = new BookWrapper("Placeholders");
    for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
        String msg = "";
        String identifier = placeholder.getIdentifier();
        if (identifier.endsWith("_")) {
            identifier += "#";
        }
        if (placeholder.hasDescription()) {
            msg = "VotingPlugin_" + identifier + " - " + placeholder.getDescription();
        } else {
            msg = "VotingPlugin_" + identifier + "";
        }
        Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
        layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(identifier).color(ChatColor.AQUA).onHover(BookUtil.HoverAction.showText(msg)).build());
        book.addLayout(layout);
    }
    for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
        String msg = "";
        String identifier = placeholder.getIdentifier();
        if (identifier.endsWith("_")) {
            identifier += "#";
        }
        if (placeholder.hasDescription()) {
            msg = "VotingPlugin_" + identifier + " - " + placeholder.getDescription();
        } else {
            msg = "VotingPlugin_" + identifier + "";
        }
        Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
        layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(identifier).color(ChatColor.AQUA).onHover(BookUtil.HoverAction.showText(msg)).build());
        book.addLayout(layout);
    }
    book.open(player);
}
Also used : BookWrapper(com.bencodez.advancedcore.api.bookgui.BookWrapper) Layout(com.bencodez.advancedcore.api.bookgui.Layout) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 23 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser 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);
}
Also used : VoteSite(com.bencodez.votingplugin.objects.VoteSite) PlayerPostVoteEvent(com.bencodez.votingplugin.events.PlayerPostVoteEvent) ArrayList(java.util.ArrayList) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser) EventHandler(org.bukkit.event.EventHandler)

Example 24 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class TopVoterHandler method onMonthChange.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMonthChange(MonthChangeEvent event) {
    long startTime = System.currentTimeMillis();
    synchronized (VotingPluginMain.plugin) {
        plugin.getLogger().info("Saving TopVoters Monthly");
        storeTopVoters(TopVoter.Monthly);
        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.Monthly) == 0 && user.getMonthVoteStreak() != 0) {
                    user.setMonthVoteStreak(0);
                } else {
                    if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage() || user.hasPercentageTotal(TopVoter.Monthly, plugin.getSpecialRewardsConfig().getVoteStreakRequirementMonth(), LocalDateTime.now().minusDays(1))) {
                        user.addMonthVoteStreak();
                        plugin.getSpecialRewards().checkVoteStreak(user, "Month", plugin.getBungeeSettings().isUseBungeecoord());
                    }
                }
            }
            user.setLastMonthTotal(user.getTotal(TopVoter.Monthly));
            if (plugin.getConfigFile().isUseHighestTotals()) {
                if (user.getHighestMonthlyTotal() < user.getTotal(TopVoter.Monthly)) {
                    user.setHighestMonthlyTotal(user.getTotal(TopVoter.Monthly));
                }
            }
            user.clearTempCache();
        }
        try {
            if (plugin.getSpecialRewardsConfig().isEnableMonthlyAwards()) {
                HashMap<Integer, String> places = handlePlaces(plugin.getSpecialRewardsConfig().getMonthlyPossibleRewardPlaces());
                int i = 0;
                int lastTotal = -1;
                @SuppressWarnings("unchecked") LinkedHashMap<TopVoterPlayer, Integer> clone = (LinkedHashMap<TopVoterPlayer, Integer>) plugin.getTopVoter(TopVoter.Monthly).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.giveMonthlyTopVoterAward(i, places.get(i));
                        }
                    }
                    lastTotal = entry.getValue().intValue();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (plugin.getSpecialRewardsConfig().getResetMilestonesMonthly()) {
            resetMilestoneCount();
            resetGottenMilestones();
        }
        for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) {
            if (plugin.getGui().getChestVoteShopResetMonthly(shopIdent)) {
                resetVoteShopLimit(shopIdent);
            }
        }
        resetTotals(TopVoter.Monthly);
        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");
    }
}
Also used : VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser) LinkedHashMap(java.util.LinkedHashMap) EventHandler(org.bukkit.event.EventHandler)

Example 25 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class TopVoterHandler method loadLastMonth.

public void loadLastMonth() {
    if (plugin.getGui().isLastMonthGUI()) {
        plugin.getLastMonthTopVoter().clear();
        LinkedHashMap<TopVoterPlayer, Integer> totals = new LinkedHashMap<TopVoterPlayer, Integer>();
        for (String uuid : UserManager.getInstance().getAllUUIDs()) {
            VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
            user.dontCache();
            int total = user.getLastMonthTotal();
            if (total > 0) {
                totals.put(user.getTopVoterPlayer(), total);
            }
        }
        plugin.getLastMonthTopVoter().putAll(sortByValues(totals, false));
        plugin.debug("Loaded last month top voters");
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Aggregations

VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)27 Player (org.bukkit.entity.Player)11 VoteSite (com.bencodez.votingplugin.objects.VoteSite)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)6 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)5 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)5 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)5 RewardOptions (com.bencodez.advancedcore.api.rewards.RewardOptions)5 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)5 TopVoterPlayer (com.bencodez.votingplugin.topvoter.TopVoterPlayer)5 EventHandler (org.bukkit.event.EventHandler)5 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)4 AdminVotePlaceholdersPlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVotePlaceholdersPlayer)3 AdminVoteVotePlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVoteVotePlayer)3 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)3 BookWrapper (com.bencodez.advancedcore.api.bookgui.BookWrapper)2 Layout (com.bencodez.advancedcore.api.bookgui.Layout)2 CommandHandler (com.bencodez.advancedcore.api.command.CommandHandler)2