use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.
the class PlayerGUIs method openVoteTop.
public void openVoteTop(Player player, TopVoter top) {
if (top == null) {
top = TopVoter.getDefault();
}
BInventory inv = null;
Set<Entry<User, Integer>> users = null;
String topVoter = "";
if (top.equals(TopVoter.Monthly)) {
topVoter = Config.getInstance().getFormatTopVoterMonthly();
users = plugin.topVoterMonthly.entrySet();
} else if (top.equals(TopVoter.Weekly)) {
topVoter = Config.getInstance().getFormatTopVoterWeekly();
users = plugin.topVoterWeekly.entrySet();
} else if (top.equals(TopVoter.Daily)) {
topVoter = Config.getInstance().getFormatTopVoterDaily();
users = plugin.topVoterDaily.entrySet();
} else {
topVoter = Config.getInstance().getFormatTopVoterAllTime();
users = plugin.topVoterAllTime.entrySet();
}
inv = new BInventory(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteTopName(), "topvoter", topVoter));
int pos = 1;
for (Entry<User, Integer> entry : users) {
inv.addButton(new BInventoryButton(new ItemBuilder(MiscUtils.getInstance().setSkullOwner(entry.getKey().getOfflinePlayer())).setName(Config.getInstance().getGUIVoteTopItemName()).addLoreLine(Config.getInstance().getGUIVoteTopItemLore()).addPlaceholder("position", "" + pos).addPlaceholder("player", entry.getKey().getPlayerName()).addPlaceholder("votes", "" + entry.getValue())) {
@Override
public void onClick(ClickEvent clickEvent) {
// ItemBuilder item = new ItemBuilder(clickEvent.getClickedItem());
// String name = ChatColor.stripColor(item.getName()).split(":")[1].trim();
String name = (String) clickEvent.getButton().getData("player");
User user = UserManager.getInstance().getVotingPluginUser(name);
openVoteGUI(player, user);
}
}.addData("player", entry.getKey().getPlayerName()));
pos++;
}
final TopVoter cur = top;
inv.getPageButtons().add(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteTopSwitchItem()).addPlaceholder("Top", topVoter)) {
@Override
public void onClick(ClickEvent clickEvent) {
if (!clickEvent.getClick().equals(ClickType.RIGHT)) {
openVoteTop(player, cur.next());
} else {
openVoteTop(player, cur.prev());
}
}
});
if (Config.getInstance().getGUIVoteTopBackButton()) {
inv.getPageButtons().add(new BInventoryButton(getBackButton().setSlot(1)) {
@Override
public void onClick(ClickEvent event) {
openVoteGUI(event.getPlayer(), getSelectedPlayer(event.getPlayer()));
}
});
}
inv.setPages(true);
inv.setMaxInvSize(Config.getInstance().getGUIVoteTopSize());
inv.openInventory(player);
}
use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.
the class PlayerGUIs method openVoteURL.
/**
* Vote URL.
*
* @param player
* the player
*/
public void openVoteURL(Player player) {
setSelectedPlayer(player, null);
BInventory inv = new BInventory(Config.getInstance().getGUIVoteURLName());
User user = UserManager.getInstance().getVotingPluginUser(player);
int count = 0;
if (Config.getInstance().getVoteURLViewAllUrlsButtonEnabled()) {
ItemBuilder builderAll = new ItemBuilder(Config.getInstance().getVoteURLAlreadyVotedAllUrlsButtonItemSection());
if (user.canVoteAll()) {
builderAll = new ItemBuilder(Config.getInstance().getVoteURLCanVoteAllUrlsButtonItemSection());
}
if (!builderAll.hasCustomDisplayName()) {
builderAll.setName("&4All Voting Sites");
}
if (!builderAll.hasCustomLore()) {
builderAll.setLore("&cClick Me");
}
inv.addButton(count, new BInventoryButton(builderAll) {
@Override
public void onClick(ClickEvent event) {
User user = UserManager.getInstance().getVotingPluginUser(event.getPlayer());
Player player = event.getWhoClicked();
player.closeInventory();
user.sendMessage(Commands.getInstance().voteURLs(user));
}
});
count++;
}
for (VoteSite voteSite : plugin.getVoteSites()) {
ItemBuilder builder = new ItemBuilder(Config.getInstance().getVoteURLAlreadyVotedItemSection());
if (user.canVoteSite(voteSite)) {
builder = new ItemBuilder(Config.getInstance().getVoteURLCanVoteItemSection());
} else {
builder.addLoreLine(Config.getInstance().getVoteURLNextVote().replace("%Info%", Commands.getInstance().voteCommandNextInfo(user, voteSite)));
}
builder.setName(Config.getInstance().getVoteURLSiteName().replace("%Name%", voteSite.getDisplayName()));
inv.addButton(count, new BInventoryButton(builder) {
@Override
public void onClick(ClickEvent event) {
Player player = event.getWhoClicked();
if (player != null) {
player.closeInventory();
User user = UserManager.getInstance().getVotingPluginUser(player);
user.sendMessage(StringUtils.getInstance().replacePlaceHolder(StringUtils.getInstance().replacePlaceHolder(StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getGUIVoteURLURLText(), "voteurl", voteSite.getVoteURL()), "sitename", voteSite.getDisplayName()), "player", player.getName()));
}
}
});
count++;
}
if (Config.getInstance().getGUIVoteURLBackButton()) {
inv.addButton(new BInventoryButton(getBackButton()) {
@Override
public void onClick(ClickEvent event) {
openVoteGUI(event.getPlayer(), getSelectedPlayer(event.getPlayer()));
}
});
}
inv.openInventory(player);
}
use of com.Ben12345rocks.VotingPlugin.Objects.User 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.User in project VotingPlugin by Ben12345rocks.
the class TopVoterHandler method storeWeeklyTopVoters.
public void storeWeeklyTopVoters() {
LocalDateTime time = LocalDateTime.now().minusHours(10);
String month = time.getMonth().toString();
int year = time.getYear();
int week = time.getDayOfYear();
YMLFileHandler file = new YMLFileHandler(new File(plugin.getDataFolder(), "TopVoter" + File.separator + "Weekly" + File.separator + year + "_" + month + "_" + week + ".yml"));
file.setup();
ArrayList<String> topVoters = new ArrayList<String>();
int count = 1;
for (Entry<User, Integer> entry : plugin.topVoterWeekly.entrySet()) {
topVoters.add(count + ": " + entry.getKey().getPlayerName() + ": " + entry.getValue());
count++;
}
file.getData().set("Week", topVoters);
file.saveData();
}
use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.
the class TopVoterHandler method onWeekChange.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWeekChange(WeekChangeEvent event) {
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
if (user.getWeeklyTotal() == 0 && user.getWeekVoteStreak() != 0) {
user.setWeekVoteStreak(0);
} else {
user.addWeekVoteStreak();
OtherVoteReward.getInstance().checkVoteStreak(user, "Week");
}
if (user.getHighestWeeklyTotal() < user.getWeeklyTotal()) {
user.setHighestWeeklyTotal(user.getWeeklyTotal());
}
}
if (Config.getInstance().getStoreTopVotersWeekly()) {
plugin.debug("Storing TopVoters Weekly");
storeWeeklyTopVoters();
}
if (Config.getInstance().getWeeklyAwardsEnabled()) {
HashMap<Integer, String> places = handlePlaces(Config.getInstance().getWeeklyPossibleRewardPlaces());
int i = 0;
int lastTotal = -1;
for (User user : plugin.topVoterWeekly.keySet()) {
if (!Config.getInstance().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
if (Config.getInstance().getTopVoterAwardsTies()) {
if (user.getWeeklyTotal() != lastTotal) {
i++;
}
} else {
i++;
}
if (places.containsKey(i)) {
user.giveWeeklyTopVoterAward(i, places.get(i));
}
}
lastTotal = user.getWeeklyTotal();
}
}
resetWeeklyTotals();
}
Aggregations