Search in sources :

Example 1 with TopVoterPlayer

use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.

the class VotingPluginMain method onPostLoad.

@Override
public void onPostLoad() {
    loadVersionFile();
    getOptions().setServer(bungeeSettings.getServer());
    if (bungeeSettings.isUseBungeecoord()) {
        bungeeHandler = new BungeeHandler(this);
        bungeeHandler.load();
        if (getOptions().getServer().equalsIgnoreCase("PleaseSet")) {
            getLogger().warning("Bungeecoord is true and server name is not set, bungeecoord features may not work");
        }
    }
    registerCommands();
    checkVotifier();
    registerEvents();
    loadDirectlyDefined();
    checkUpdate = new CheckUpdate(this);
    checkUpdate.startUp();
    voteReminding = new VoteReminding(this);
    voteReminding.loadRemindChecking();
    specialRewards = new SpecialRewards(this);
    signs = new Signs(this);
    coolDownCheck.checkEnabled();
    coolDownCheck.load();
    Bukkit.getScheduler().runTask(plugin, new Runnable() {

        @Override
        public void run() {
            signs.loadSigns();
        }
    });
    topVoterHandler = new TopVoterHandler(this);
    lastMonthTopVoter = new LinkedHashMap<TopVoterPlayer, Integer>();
    Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

        @Override
        public void run() {
            topVoterHandler.loadLastMonth();
            debug("Loaded last month top voters");
        }
    });
    topVoter = new LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>>();
    for (TopVoter top : TopVoter.values()) {
        topVoter.put(top, new LinkedHashMap<TopVoterPlayer, Integer>());
    }
    voteToday = new LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>>();
    voteLog = new Logger(plugin, new File(plugin.getDataFolder() + File.separator + "Log", "votelog.txt"));
    new AdminGUI(this).loadHook();
    // vote party
    voteParty = new VoteParty(this);
    voteParty.register();
    topVoterHandler.register();
    metrics();
    // javascript api
    getJavascriptEngineRequests().add(new JavascriptPlaceholderRequest("User") {

        @Override
        public Object getObject(OfflinePlayer player) {
            return getVotingPluginUserManager().getVotingPluginUser(player);
        }
    });
    getJavascriptEngine().put("VotingPluginHooks", VotingPluginHooks.getInstance());
    loadTimer();
    // placeholderapi loading
    placeholders = new PlaceHolders(this);
    placeholders.load();
    if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
        mvdwPlaceholders = new MVdWPlaceholders(this);
        mvdwPlaceholders.loadMVdWPlaceholders();
    }
    // Add rewards
    RewardHandler.getInstance().addInjectedReward(new RewardInjectInt("Points", 0) {

        @Override
        public String onRewardRequest(Reward reward, com.bencodez.advancedcore.api.user.AdvancedCoreUser user, int num, HashMap<String, String> placeholders) {
            UserManager.getInstance().getVotingPluginUser(user).addPoints(num);
            return null;
        }
    }.synchronize().addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueNumber("Points", null) {

        @Override
        public void setValue(Player player, Number value) {
            RewardEditData reward = (RewardEditData) getInv().getData("Reward");
            reward.setValue("Points", value.intValue());
        }
    }.addLore("Give player voting points"))).validator(new RewardInjectValidator() {

        @Override
        public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
            if (data.getInt(inject.getPath(), -1) == 0) {
                warning(reward, inject, "Points can not be 0");
            }
        }
    }));
    RewardHandler.getInstance().addInjectedReward(new RewardInjectConfigurationSection("VoteBossBar") {

        @Override
        public String onRewardRequested(Reward arg0, com.bencodez.advancedcore.api.user.AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
            if (section.getBoolean("Enabled")) {
                user.sendBossBar(StringParser.getInstance().replacePlaceHolder(section.getString("Message", ""), placeholders), section.getString("Color", "BLUE"), section.getString("Style", "SOLID"), (double) UserManager.getInstance().getVotingPluginUser(user).getSitesVotedOn() / plugin.getVoteSites().size(), section.getInt("Delay", 30));
            }
            return null;
        }
    });
    for (final TopVoter top : TopVoter.values()) {
        RewardHandler.getInstance().addPlaceholder(new RewardPlaceholderHandle("Total_" + top.toString()) {

            @Override
            public String getValue(Reward reward, com.bencodez.advancedcore.api.user.AdvancedCoreUser user) {
                VotingPluginUser vUser = UserManager.getInstance().getVotingPluginUser(user);
                return "" + vUser.getTotal(top);
            }
        });
    }
    if (plugin.getConfigFile().isFormatAlternateBroadcastEnabled()) {
        broadcastHandler = new BroadcastHandler(plugin, plugin.getConfigFile().getFormatAlternateBroadcastDelay());
        plugin.debug("Using alternate broadcast method");
    }
    plugin.getLogger().info("Enabled VotingPlugin " + plugin.getDescription().getVersion());
    if (getProfile().contains("dev")) {
        plugin.getLogger().info("Using dev build, this is not a stable build, use at your own risk. Build number: " + buildNumber);
    }
    boolean hasRewards = RewardHandler.getInstance().hasRewards(getConfigVoteSites().getData(), getConfigVoteSites().getEverySiteRewardPath());
    boolean issues = true;
    ArrayList<String> services = serverData.getServiceSites();
    for (VoteSite site : getVoteSites()) {
        if (!site.hasRewards() && !hasRewards) {
            issues = false;
            plugin.getLogger().warning("No rewards detected for the site: " + site.getKey() + ". See https://github.com/BenCodez/VotingPlugin/wiki/Rewards");
        }
        boolean contains = false;
        for (String service : services) {
            if (service.equalsIgnoreCase(site.getServiceSite())) {
                contains = true;
            }
        }
        if (!contains) {
            issues = false;
            plugin.getLogger().warning("No vote has been recieved from " + site.getServiceSite() + ", may be an invalid service site. Please read: https://github.com/BenCodez/VotingPlugin/wiki/Votifier-Troubleshooting");
        }
    }
    if (!issues) {
        Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {

            @Override
            public void run() {
                plugin.getLogger().warning("Detected an issue with voting sites, check the server startup log for more details: https://github.com/BenCodez/VotingPlugin/wiki/Votifier-Troubleshooting");
            }
        }, 30l);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VoteReminding(com.bencodez.votingplugin.votereminding.VoteReminding) PlaceHolders(com.bencodez.votingplugin.placeholders.PlaceHolders) LinkedHashMap(java.util.LinkedHashMap) OfflinePlayer(org.bukkit.OfflinePlayer) AdminGUI(com.bencodez.votingplugin.commands.gui.AdminGUI) RewardPlaceholderHandle(com.bencodez.advancedcore.api.rewards.RewardPlaceholderHandle) VoteParty(com.bencodez.votingplugin.voteparty.VoteParty) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) RewardInjectInt(com.bencodez.advancedcore.api.rewards.injected.RewardInjectInt) MVdWPlaceholders(com.bencodez.votingplugin.placeholders.MVdWPlaceholders) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) CheckUpdate(com.bencodez.votingplugin.updater.CheckUpdate) EditGUIButton(com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton) EditGUIValueNumber(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber) File(java.io.File) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) RewardInjectConfigurationSection(com.bencodez.advancedcore.api.rewards.injected.RewardInjectConfigurationSection) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser) Logger(com.bencodez.advancedcore.logger.Logger) VoteSite(com.bencodez.votingplugin.objects.VoteSite) TopVoterHandler(com.bencodez.votingplugin.topvoter.TopVoterHandler) EditGUIValueNumber(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber) TopVoter(com.bencodez.votingplugin.topvoter.TopVoter) RewardInjectValidator(com.bencodez.advancedcore.api.rewards.injected.RewardInjectValidator) SpecialRewards(com.bencodez.votingplugin.specialrewards.SpecialRewards) JavascriptPlaceholderRequest(com.bencodez.advancedcore.api.javascript.JavascriptPlaceholderRequest) Signs(com.bencodez.votingplugin.signs.Signs) RewardEditData(com.bencodez.advancedcore.api.rewards.RewardEditData) RewardInjectConfigurationSection(com.bencodez.advancedcore.api.rewards.injected.RewardInjectConfigurationSection) RewardInject(com.bencodez.advancedcore.api.rewards.injected.RewardInject) DirectlyDefinedReward(com.bencodez.advancedcore.api.rewards.DirectlyDefinedReward) Reward(com.bencodez.advancedcore.api.rewards.Reward) BroadcastHandler(com.bencodez.votingplugin.broadcast.BroadcastHandler)

Example 2 with TopVoterPlayer

use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.

the class VotingPluginMain method checkFirstTimeLoaded.

public void checkFirstTimeLoaded() {
    if (!firstTimeLoaded) {
        if (getGui().isChestVoteTopUseSkull()) {
            int maxToLoad = 200;
            for (TopVoter top : topVoter.keySet()) {
                int num = 1;
                Set<TopVoterPlayer> players = topVoter.get(top).keySet();
                for (TopVoterPlayer p : players) {
                    if (num <= maxToLoad) {
                        SkullHandler.getInstance().loadSkull(p.getPlayerName());
                    }
                    num++;
                }
            }
        }
    }
    firstTimeLoaded = true;
}
Also used : TopVoter(com.bencodez.votingplugin.topvoter.TopVoter) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer)

Example 3 with TopVoterPlayer

use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.

the class VoteTopVoter method onChest.

@Override
public void onChest(Player player) {
    try {
        if (top == null) {
            top = TopVoter.getDefault();
        }
        Set<Entry<TopVoterPlayer, Integer>> users = null;
        String topVoter = top.getName();
        @SuppressWarnings("unchecked") LinkedHashMap<TopVoterPlayer, Integer> topVotes = (LinkedHashMap<TopVoterPlayer, Integer>) plugin.getTopVoter(top).clone();
        users = topVotes.entrySet();
        BInventory inv = new BInventory(plugin.getGui().getChestVoteTopName());
        inv.addPlaceholder("topvoter", topVoter);
        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) {
                    if (plugin.getGui().getChestVoteTopOpenMainGUIOnClick()) {
                        TopVoterPlayer user = (TopVoterPlayer) getData("User");
                        new VoteGUI(plugin, player, user.getUser()).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
                    } else {
                        getInv().forceClose(clickEvent.getPlayer());
                    }
                }
            }.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
            pos++;
        }
        final TopVoter cur = top;
        inv.getPageButtons().add(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteTopSwitchItem()).addPlaceholder("Top", topVoter)) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                if (!clickEvent.getClick().equals(ClickType.RIGHT)) {
                    new VoteTopVoter(plugin, player, user, cur.next(), 0).open(GUIMethod.CHEST);
                } else {
                    new VoteTopVoter(plugin, player, user, cur.prev(), 0).open(GUIMethod.CHEST);
                }
            }
        });
        if (plugin.getGui().getChestVoteTopBackButton()) {
            inv.getPageButtons().add(plugin.getCommandLoader().getBackButton(user).setSlot(1));
        }
        inv.setPages(true);
        inv.setMaxInvSize(plugin.getGui().getChestVoteTopSize());
        inv.openInventory(player);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) TopVoter(com.bencodez.votingplugin.topvoter.TopVoter)

Example 4 with TopVoterPlayer

use of com.bencodez.votingplugin.topvoter.TopVoterPlayer in project VotingPlugin by Ben12345rocks.

the class VoteToday method voteToday.

public String[] voteToday() {
    ArrayList<String> msg = new ArrayList<String>();
    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);
            HashMap<String, String> placeholders = new HashMap<String, String>();
            placeholders.put("player", user.getPlayerName());
            placeholders.put("votesite", voteSite.getKey());
            placeholders.put("time", timeString);
            msg.add(StringParser.getInstance().replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteTodayLine(), placeholders));
        // msg.add("&6" + user.getPlayerName() + " : " + voteSite.getKey() + " : " +
        // timeString);
        }
    }
    msg = ArrayUtils.getInstance().colorize(msg);
    return ArrayUtils.getInstance().convert(msg);
}
Also used : 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 5 with TopVoterPlayer

use of com.bencodez.votingplugin.topvoter.TopVoterPlayer 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)

Aggregations

TopVoterPlayer (com.bencodez.votingplugin.topvoter.TopVoterPlayer)10 VoteSite (com.bencodez.votingplugin.objects.VoteSite)6 HashMap (java.util.HashMap)6 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)5 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)4 VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)4 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)3 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)3 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)3 LocalDateTime (java.time.LocalDateTime)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Entry (java.util.Map.Entry)3 EditGUIButton (com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton)1 EditGUIValueNumber (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber)1 JavascriptPlaceholderRequest (com.bencodez.advancedcore.api.javascript.JavascriptPlaceholderRequest)1 NonPlayerPlaceHolder (com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder)1 PlaceHolder (com.bencodez.advancedcore.api.placeholder.PlaceHolder)1 DirectlyDefinedReward (com.bencodez.advancedcore.api.rewards.DirectlyDefinedReward)1