Search in sources :

Example 11 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class VoteToday method voteTodayGUI.

public String[] voteTodayGUI() {
    ArrayList<String> msg = new ArrayList<String>();
    for (TopVoterPlayer user : plugin.getVoteToday().keySet()) {
        LocalDateTime mostRecent = null;
        VoteSite mostRecentSite = null;
        for (Entry<VoteSite, LocalDateTime> entry : plugin.getVoteToday().get(user).entrySet()) {
            if (mostRecent == null || entry.getValue().isAfter(mostRecent)) {
                mostRecent = entry.getValue();
                mostRecentSite = entry.getKey();
            }
        }
        if (mostRecent != null) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
            String timeString = mostRecent.format(formatter);
            HashMap<String, String> placeholders = new HashMap<String, String>();
            placeholders.put("player", user.getPlayerName());
            placeholders.put("votesite", mostRecentSite.getKey());
            placeholders.put("time", timeString);
            msg.add(StringParser.getInstance().replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteTodayLine(), placeholders));
        }
    }
    msg = ArrayUtils.getInstance().colorize(msg);
    return ArrayUtils.getInstance().convert(msg);
}
Also used : LocalDateTime(java.time.LocalDateTime) VoteSite(com.bencodez.votingplugin.objects.VoteSite) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 12 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite 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);
}
Also used : VoteSite(com.bencodez.votingplugin.objects.VoteSite) RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) UpdatingBInventoryButton(com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) Player(org.bukkit.entity.Player) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) UpdatingBInventoryButton(com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 13 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class VotingPluginUser method getLastVotes.

public HashMap<VoteSite, Long> getLastVotes() {
    HashMap<VoteSite, Long> lastVotes = new HashMap<VoteSite, Long>();
    ArrayList<String> LastVotesList = getUserData().getStringList("LastVotes");
    for (String str : LastVotesList) {
        String[] data = str.split("//");
        if (data.length > 1 && plugin.hasVoteSite(data[0])) {
            VoteSite site = plugin.getVoteSite(data[0], true);
            if (site != null) {
                long time = 0;
                try {
                    time = Long.parseLong(data[1]);
                } catch (NumberFormatException e) {
                    time = 0;
                    plugin.debug("Not long: " + data[1]);
                }
                lastVotes.put(site, time);
            }
        }
    }
    return lastVotes;
}
Also used : VoteSite(com.bencodez.votingplugin.objects.VoteSite) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite 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);
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) PlaceHolder(com.bencodez.advancedcore.api.placeholder.PlaceHolder) NonPlayerPlaceHolder(com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UserDataChanged(com.bencodez.advancedcore.api.user.UserDataChanged) VoteSite(com.bencodez.votingplugin.objects.VoteSite) Entry(java.util.Map.Entry) TopVoter(com.bencodez.votingplugin.topvoter.TopVoter) UUID(java.util.UUID) HashSet(java.util.HashSet) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) Duration(java.time.Duration) AdvancedCoreUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser) NonPlayerPlaceHolder(com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser) NumberFormat(java.text.NumberFormat)

Example 15 with VoteSite

use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class ConfigVoteSites method getVoteSitesLoad.

/**
 * Gets the vote sites load.
 *
 * @return the vote sites load
 */
public ArrayList<VoteSite> getVoteSitesLoad() {
    ArrayList<VoteSite> voteSites = new ArrayList<VoteSite>();
    ArrayList<String> voteSiteNames = getVoteSitesNames(true);
    if (voteSiteNames != null) {
        for (String site : voteSiteNames) {
            if (getVoteSiteEnabled(site) && !site.equalsIgnoreCase("null")) {
                if (!siteCheck(site)) {
                    plugin.getLogger().warning("Failed to load site " + site + ", see above");
                } else {
                    voteSites.add(new VoteSite(plugin, site));
                }
            }
        }
    }
    Collections.sort(voteSites, new Comparator<VoteSite>() {

        @Override
        public int compare(VoteSite v1, VoteSite v2) {
            int v1P = v1.getPriority();
            int v2P = v2.getPriority();
            if (v1P < v2P) {
                return 1;
            }
            if (v1P > v2P) {
                return -1;
            }
            return 0;
        }
    });
    return voteSites;
}
Also used : VoteSite(com.bencodez.votingplugin.objects.VoteSite) ArrayList(java.util.ArrayList)

Aggregations

VoteSite (com.bencodez.votingplugin.objects.VoteSite)28 ArrayList (java.util.ArrayList)15 Player (org.bukkit.entity.Player)10 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)9 VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)9 HashMap (java.util.HashMap)9 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)7 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)7 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)7 TopVoterPlayer (com.bencodez.votingplugin.topvoter.TopVoterPlayer)6 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)5 UpdatingBInventoryButton (com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton)4 PlayerVoteEvent (com.bencodez.votingplugin.events.PlayerVoteEvent)4 DateTimeFormatter (java.time.format.DateTimeFormatter)4 LinkedHashMap (java.util.LinkedHashMap)4 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)3 LocalDateTime (java.time.LocalDateTime)3 BookWrapper (com.bencodez.advancedcore.api.bookgui.BookWrapper)2 Layout (com.bencodez.advancedcore.api.bookgui.Layout)2 EditGUI (com.bencodez.advancedcore.api.inventory.editgui.EditGUI)2