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);
}
}
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);
}
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() {
}
});
}
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);
}
});
}
}
});
}
}
}
});
}
});
}
});
}
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);
}
Aggregations