Search in sources :

Example 6 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class Main method onEnable.

/*
	 * (non-Javadoc)
	 *
	 * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
	 */
@Override
public void onEnable() {
    plugin = this;
    setupFiles();
    loadVoteSites();
    updateAdvancedCoreHook();
    AdvancedCoreHook.getInstance().loadHook(this);
    if (AdvancedCoreHook.getInstance().getStorageType().equals(UserStorage.MYSQL)) {
        debug("UseBatchUpdates: " + AdvancedCoreHook.getInstance().getMysql().isUseBatchUpdates());
    }
    registerCommands();
    registerEvents();
    checkVotifier();
    CheckUpdate.getInstance().startUp();
    VoteReminding.getInstance().loadRemindChecking();
    plugin.signs = new ArrayList<SignHandler>();
    Bukkit.getScheduler().runTask(plugin, new Runnable() {

        @Override
        public void run() {
            Signs.getInstance().loadSigns();
        }
    });
    topVoterMonthly = new LinkedHashMap<User, Integer>();
    topVoterWeekly = new LinkedHashMap<User, Integer>();
    topVoterDaily = new LinkedHashMap<User, Integer>();
    voteToday = new LinkedHashMap<User, HashMap<VoteSite, LocalDateTime>>();
    topVoterAllTime = new LinkedHashMap<User, Integer>();
    voteLog = new Logger(plugin, new File(plugin.getDataFolder() + File.separator + "Log", "votelog.txt"));
    AdminGUI.getInstance().loadHook();
    if (Config.getInstance().getVotePartyEnabled()) {
        VoteParty.getInstance().check();
    }
    VoteParty.getInstance().register();
    TopVoterHandler.getInstance().register();
    metrics();
    AdvancedCoreHook.getInstance().getJavascriptEngineRequests().add(new JavascriptPlaceholderRequest("User") {

        @Override
        public Object getObject(OfflinePlayer player) {
            return getUserManager().getVotingPluginUser(player);
        }
    });
    loadTimer();
    plugin.getLogger().info("Enabled VotingPlugin " + plugin.getDescription().getVersion());
    boolean hasRewards = RewardHandler.getInstance().hasRewards(ConfigVoteSites.getInstance().getData(), ConfigVoteSites.getInstance().getEverySiteRewardPath());
    boolean noIssues = true;
    ArrayList<String> services = ServerData.getInstance().getServiceSites();
    for (VoteSite site : getVoteSites()) {
        if (!site.hasRewards() && !hasRewards) {
            noIssues = false;
            plugin.getLogger().warning("No rewards detected for the site: " + site.getKey() + ". See https://github.com/Ben12345rocks/AdvancedCore/wiki/Rewards on how to add rewards");
        }
        boolean contains = false;
        for (String service : services) {
            if (service.equalsIgnoreCase(site.getServiceSite())) {
                contains = true;
            }
        }
        if (!contains) {
            noIssues = false;
            plugin.getLogger().warning("No vote has been recieved from " + site.getServiceSite() + ", may be an invalid service site. Vote on the site and look in console for a service site, if you get nothing then there is an issue with votifier");
        }
    }
    if (!noIssues) {
        Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {

            @Override
            public void run() {
                plugin.getLogger().warning("Detected an issue with voting sites, check the plugin startup log for more details");
            }
        }, 30l);
    }
}
Also used : User(com.Ben12345rocks.VotingPlugin.Objects.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Logger(com.Ben12345rocks.AdvancedCore.Util.Logger.Logger) JavascriptPlaceholderRequest(com.Ben12345rocks.AdvancedCore.Util.Javascript.JavascriptPlaceholderRequest) VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) OfflinePlayer(org.bukkit.OfflinePlayer) File(java.io.File) SignHandler(com.Ben12345rocks.VotingPlugin.Objects.SignHandler)

Example 7 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class VotiferEvent method playerVote.

public static void playerVote(final String playerName, final String voteSiteURL, final boolean realVote) {
    if (!config.allowUnJoined() && !PlayerUtils.getInstance().isValidUser(playerName)) {
        plugin.getLogger().warning("Player " + playerName + " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
        return;
    }
    User user = UserManager.getInstance().getVotingPluginUser(playerName);
    VoteSite voteSite = plugin.getVoteSite(voteSiteURL);
    if (voteSite == null) {
        if (!Config.getInstance().getDisableNoServiceSiteMessage()) {
            plugin.getLogger().warning("No voting site with the service site: '" + voteSiteURL + "'");
            plugin.getLogger().warning("Please read here on how to fix it: https://github.com/Ben12345rocks/VotingPlugin/wiki/Common-Problems");
            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;
    }
    synchronized (object) {
        // vote party
        VoteParty.getInstance().vote(user, realVote);
        // broadcast vote if enabled in config
        if (config.getBroadCastVotesEnabled()) {
            if (!Config.getInstance().getFormatBroadcastWhenOnline() || user.isOnline()) {
                voteSite.broadcastVote(user);
            }
        }
        // update last vote time
        user.setTime(voteSite);
        OtherVoteReward.getInstance().checkFirstVote(user);
        if (user.isReminded()) {
            user.setReminded(false);
        }
        if (user.isOnline() || voteSite.isGiveOffline()) {
            user.playerVote(voteSite, true, false);
            user.closeInv();
        } else {
            user.addOfflineVote(voteSite.getKey());
            // plugin.debug(ArrayUtils.getInstance().makeStringList(user.getOfflineVotes()));
            plugin.debug("Offline vote set for " + playerName + " (" + user.getUUID() + ") on " + voteSite.getKey());
        }
        // add to total votes
        if (Config.getInstance().getCountFakeVotes() || realVote) {
            if (Config.getInstance().getAddTotals()) {
                user.addTotal();
                user.addTotalDaily();
                user.addTotalWeekly();
            }
            user.addPoints();
        }
        OtherVoteReward.getInstance().checkAllSites(user);
        OtherVoteReward.getInstance().checkCumualativeVotes(user);
        OtherVoteReward.getInstance().checkMilestone(user);
        if (Config.getInstance().getClearCacheOnVote()) {
            if (AdvancedCoreHook.getInstance().getStorageType().equals(UserStorage.MYSQL)) {
                AdvancedCoreHook.getInstance().getMysql().removePlayer(user.getUUID());
            }
        }
    }
    plugin.setUpdate(true);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) User(com.Ben12345rocks.VotingPlugin.Objects.User) ArrayList(java.util.ArrayList)

Example 8 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class CommandLoader method loadTabComplete.

/**
 * Load tab complete.
 */
public void loadTabComplete() {
    ArrayList<String> sites = new ArrayList<String>();
    for (VoteSite site : plugin.getVoteSites()) {
        sites.add(site.getKey());
    }
    TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(Sitename)", sites) {

        @Override
        public void reload() {
            ArrayList<String> sites = new ArrayList<String>();
            for (VoteSite site : plugin.getVoteSites()) {
                sites.add(site.getKey());
            }
            setReplace(sites);
        }

        @Override
        public void updateReplacements() {
        }
    });
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) ArrayList(java.util.ArrayList) TabCompleteHandle(com.Ben12345rocks.AdvancedCore.Objects.TabCompleteHandle)

Example 9 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class CommandLoader method loadCommands.

/**
 * Load commands.
 */
public void loadCommands() {
    loadAdminVoteCommand();
    loadVoteCommand();
    Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

        @Override
        public void run() {
            com.Ben12345rocks.AdvancedCore.Thread.Thread.getInstance().run(new Runnable() {

                @Override
                public void run() {
                    loadTabComplete();
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("Force Vote", new String[] {}, new ItemStack(Material.STONE)) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            Player player = clickEvent.getPlayer();
                            ArrayList<String> voteSites = new ArrayList<String>();
                            for (VoteSite voteSite : plugin.getVoteSites()) {
                                voteSites.add(voteSite.getKey());
                            }
                            new ValueRequest().requestString(player, "", ArrayUtils.getInstance().convert(voteSites), true, new StringListener() {

                                @Override
                                public void onInput(Player player, String value) {
                                    VotiferEvent.playerVote(UserGUI.getInstance().getCurrentPlayer(player), value, false);
                                    player.sendMessage("Forced vote for " + UserGUI.getInstance().getCurrentPlayer(player) + " on " + value);
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("Set Vote Points", new String[] {}, new ItemStack(Material.STONE)) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            Player player = clickEvent.getPlayer();
                            User user = UserManager.getInstance().getVotingPluginUser(UserGUI.getInstance().getCurrentPlayer(player));
                            new ValueRequest().requestNumber(player, "" + user.getPoints(), new Number[] { 0, 5, 100 }, true, new NumberListener() {

                                @Override
                                public void onInput(Player player, Number value) {
                                    User user = UserManager.getInstance().getVotingPluginUser(UserGUI.getInstance().getCurrentPlayer(player));
                                    user.setPoints(value.intValue());
                                    player.sendMessage("Points set to " + value.intValue() + " for " + user.getPlayerName());
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton(new ItemBuilder(Material.BOOK).setName("Set Month Total")) {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            String playerName = (String) clickEvent.getMeta(clickEvent.getPlayer(), "Player");
                            User user = UserManager.getInstance().getVotingPluginUser(playerName);
                            new ValueRequest().requestNumber(clickEvent.getPlayer(), "" + user.getMonthTotal(), new Number[] { 0, 10, 50, 100 }, new NumberListener() {

                                @Override
                                public void onInput(Player player, Number value) {
                                    String playerName = (String) clickEvent.getMeta(clickEvent.getPlayer(), "Player");
                                    User user = UserManager.getInstance().getVotingPluginUser(playerName);
                                    user.setMonthTotal(value.intValue());
                                    player.sendMessage(StringUtils.getInstance().colorize("&cTotal set"));
                                }
                            });
                        }
                    });
                    UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("MileStones", new String[0], new ItemStack(Material.STONE)) {

                        @Override
                        public void onClick(ClickEvent event) {
                            Player player = event.getWhoClicked();
                            String playerName = (String) event.getMeta(player, "Player");
                            BInventory inv = new BInventory("MileStones: " + playerName);
                            for (String mileStoneName : Config.getInstance().getMilestoneVotes()) {
                                if (StringUtils.getInstance().isInt(mileStoneName)) {
                                    int mileStone = Integer.parseInt(mileStoneName);
                                    inv.addButton(inv.getNextSlot(), new BInventoryButton("" + mileStone, new String[] { "Enabled: " + Config.getInstance().getMilestoneRewardEnabled(mileStone), "&cClick to set wether this has been completed or not" }, new ItemStack(Material.STONE)) {

                                        @Override
                                        public void onClick(ClickEvent clickEvent) {
                                            if (StringUtils.getInstance().isInt(clickEvent.getClickedItem().getItemMeta().getDisplayName())) {
                                                Player player = clickEvent.getPlayer();
                                                int mileStone = Integer.parseInt(clickEvent.getClickedItem().getItemMeta().getDisplayName());
                                                String playerName = (String) event.getMeta(player, "Player");
                                                User user = UserManager.getInstance().getVotingPluginUser(playerName);
                                                new ValueRequest().requestBoolean(player, "" + user.hasGottenMilestone(mileStone), new BooleanListener() {

                                                    @Override
                                                    public void onInput(Player player, boolean value) {
                                                        String playerName = UserGUI.getInstance().getCurrentPlayer(player);
                                                        User user = UserManager.getInstance().getVotingPluginUser(playerName);
                                                        user.setHasGotteMilestone(mileStone, value);
                                                        player.sendMessage("Set milestone completetion to " + value + " on " + mileStone);
                                                    }
                                                });
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.Ben12345rocks.VotingPlugin.Objects.User) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) ValueRequest(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory) VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) NumberListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener) ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) BooleanListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener) StringListener(com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with VoteSite

use of com.Ben12345rocks.VotingPlugin.Objects.VoteSite in project VotingPlugin by Ben12345rocks.

the class Commands method voteToday.

/**
 * Vote today.
 *
 * @return the string[]
 */
public String[] voteToday() {
    ArrayList<String> msg = new ArrayList<String>();
    for (User user : plugin.voteToday.keySet()) {
        for (VoteSite voteSite : plugin.voteToday.get(user).keySet()) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Config.getInstance().getFormatTimeFormat());
            String timeString = plugin.voteToday.get(user).get(voteSite).format(formatter);
            msg.add("&6" + user.getPlayerName() + " : " + voteSite.getKey() + " : " + timeString);
        }
    }
    msg = ArrayUtils.getInstance().colorize(msg);
    return ArrayUtils.getInstance().convert(msg);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) User(com.Ben12345rocks.VotingPlugin.Objects.User) ArrayList(java.util.ArrayList) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)19 ArrayList (java.util.ArrayList)11 BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)9 ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)9 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)9 User (com.Ben12345rocks.VotingPlugin.Objects.User)9 Player (org.bukkit.entity.Player)6 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)4 HashMap (java.util.HashMap)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 ItemStack (org.bukkit.inventory.ItemStack)3 BooleanListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener)2 NumberListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener)2 StringListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener)2 ValueRequest (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)1 TabCompleteHandle (com.Ben12345rocks.AdvancedCore.Objects.TabCompleteHandle)1 UUID (com.Ben12345rocks.AdvancedCore.Objects.UUID)1 UserStorage (com.Ben12345rocks.AdvancedCore.Objects.UserStorage)1