use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class VotingPluginMain method update.
public void update() {
if (update || configFile.isAlwaysUpdate()) {
if (!updateStarted && plugin != null) {
if (!configFile.isUpdateWithPlayersOnlineOnly() || Bukkit.getOnlinePlayers().size() != 0) {
updateStarted = true;
update = false;
synchronized (plugin) {
if (plugin != null && plugin.isEnabled()) {
getUserManager().getDataManager().clearCacheBasic();
plugin.debug("Starting background task, current cached users: " + plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
placeholders.onUpdate();
int dataLoadLimit = getConfigFile().getPlayerDataLoadLimit();
try {
boolean extraBackgroundUpdate = configFile.isExtraBackgroundUpdate();
long startTime = System.currentTimeMillis();
LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>> voteToday = new LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>>();
LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>> tempTopVoter = new LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>>();
ArrayList<TopVoter> topVotersToCheck = new ArrayList<TopVoter>();
for (TopVoter top : TopVoter.values()) {
if (plugin.getConfigFile().getLoadTopVoter(top)) {
topVotersToCheck.add(top);
tempTopVoter.put(top, new LinkedHashMap<TopVoterPlayer, Integer>());
}
}
boolean topVoterIgnorePermissionUse = plugin.getConfigFile().getTopVoterIgnorePermission();
ArrayList<String> blackList = plugin.getConfigFile().getBlackList();
ArrayList<String> uuids = UserManager.getInstance().getAllUUIDs();
int currentDay = LocalDateTime.now().getDayOfMonth();
int currentDataLoad = 0;
for (String uuid : uuids) {
if (uuid != null && !uuid.isEmpty()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), false);
user.dontCache();
user.tempCache();
user.getUserData().updateCacheWithTemp();
if (!user.isBanned() && !blackList.contains(user.getPlayerName())) {
if (!topVoterIgnorePermissionUse || !user.isTopVoterIgnore()) {
for (TopVoter top : topVotersToCheck) {
int total = user.getTotal(top);
if (total > 0) {
tempTopVoter.get(top).put(user.getTopVoterPlayer(), total);
}
}
}
HashMap<VoteSite, LocalDateTime> times = new HashMap<VoteSite, LocalDateTime>();
for (Entry<VoteSite, Long> entry : user.getLastVotes().entrySet()) {
if (entry.getKey().isEnabled() && !entry.getKey().isHidden()) {
long time = entry.getValue();
if ((currentDay == MiscUtils.getInstance().getDayFromMili(time)) && (LocalDateTime.now().getMonthValue() == MiscUtils.getInstance().getMonthFromMili(time)) && (LocalDateTime.now().getYear() == MiscUtils.getInstance().getYearFromMili(time))) {
times.put(entry.getKey(), LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
}
}
}
if (times.keySet().size() > 0) {
voteToday.put(user.getTopVoterPlayer(), times);
}
}
if (!extraBackgroundUpdate) {
if (user.isOnline()) {
user.offVote();
}
}
plugin.getPlaceholders().onUpdate(user);
user.clearTempCache();
user = null;
if (dataLoadLimit > 0) {
currentDataLoad++;
if (currentDataLoad >= dataLoadLimit) {
currentDataLoad -= dataLoadLimit;
Thread.sleep(1000);
}
}
}
}
update = false;
long time1 = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Finished loading player data in " + time1 + " seconds, " + uuids.size() + " users, " + plugin.getStorageType().toString() + ", data load limit: " + dataLoadLimit);
time1 = System.currentTimeMillis();
topVoterHandler.updateTopVoters(tempTopVoter);
setVoteToday(voteToday);
serverData.updateValues();
getSigns().updateSigns();
tempTopVoter = null;
time1 = ((System.currentTimeMillis() - time1) / 1000);
long totalTime = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Background task finished. Final processing took " + time1 + " seconds. Total time: " + totalTime + " seconds");
plugin.extraDebug("Current cached users: " + plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
checkFirstTimeLoaded();
} catch (Exception ex) {
if (plugin != null) {
plugin.getLogger().info("Looks like something went wrong");
}
ex.printStackTrace();
}
}
}
updateStarted = false;
}
}
}
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class BungeeHandler method load.
public void load() {
plugin.debug("Loading bungee handler");
method = BungeeMethod.getByName(plugin.getBungeeSettings().getBungeeMethod());
plugin.getLogger().info("Using BungeeMethod: " + method.toString());
if (method.equals(BungeeMethod.MYSQL)) {
plugin.registerBungeeChannels("vp:vp");
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
plugin.registerBungeeChannels("vp:vp");
bungeeVotePartyCurrent = plugin.getServerData().getBungeeVotePartyCurrent();
bungeeVotePartyRequired = plugin.getServerData().getBungeeVotePartyRequired();
plugin.getPluginMessaging().setDebug(plugin.getBungeeSettings().isBungeeDebug());
plugin.getPluginMessaging().add(new PluginMessageHandler("Vote") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
if (args.size() > 8) {
int bungeeVersion = Integer.parseInt(args.get(8));
if (bungeeVersion != BungeeVersion.getPluginMessageVersion()) {
plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
return;
}
String player = args.get(0);
String uuid = args.get(1);
String service = args.get(2);
long time = Long.parseLong(args.get(3));
plugin.debug("pluginmessaging vote received from " + player + "/" + uuid + " on " + service);
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), player);
boolean wasOnline = Boolean.valueOf(args.get(4));
BungeeMessageData text = new BungeeMessageData(args.get(6));
bungeeVotePartyCurrent = text.getVotePartyCurrent();
bungeeVotePartyRequired = text.getVotePartyRequired();
plugin.getPlaceholders().onBungeeVotePartyUpdate();
boolean setTotals = Boolean.valueOf(args.get(7));
user.clearCache();
boolean broadcast = true;
boolean bungeeBroadcast = false;
if (args.size() > 9) {
bungeeBroadcast = Boolean.valueOf(args.get(9));
}
if (!bungeeBroadcast) {
if (!plugin.getBungeeSettings().isBungeeBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
if (wasOnline || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
VoteSite site = plugin.getVoteSite(service, true);
if (site != null) {
site.broadcastVote(user, false);
broadcast = false;
} else {
plugin.getLogger().warning("No votesite for " + service);
}
}
}
} else {
broadcast = false;
}
user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
if (plugin.getBungeeSettings().isPerServerPoints()) {
user.addPoints(plugin.getConfigFile().getPointsOnVote());
}
if (Boolean.valueOf(args.get(5))) {
plugin.getServerData().addServiceSite(service);
}
} else {
plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
}
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteOnline") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
if (args.size() > 8) {
int bungeeVersion = Integer.parseInt(args.get(8));
if (bungeeVersion != BungeeVersion.getPluginMessageVersion()) {
plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
return;
}
String player = args.get(0);
String uuid = args.get(1);
String service = args.get(2);
long time = Long.parseLong(args.get(3));
BungeeMessageData text = new BungeeMessageData(args.get(6));
bungeeVotePartyCurrent = text.getVotePartyCurrent();
bungeeVotePartyRequired = text.getVotePartyRequired();
plugin.getPlaceholders().onBungeeVotePartyUpdate();
plugin.debug("pluginmessaging voteonline received from " + player + "/" + uuid + " on " + service);
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), player);
user.clearCache();
if (plugin.getBungeeSettings().isPerServerPoints()) {
user.addPoints(plugin.getConfigFile().getPointsOnVote());
}
boolean setTotals = Boolean.valueOf(args.get(7));
boolean wasOnline = Boolean.valueOf(args.get(4));
boolean broadcast = true;
boolean bungeeBroadcast = false;
if (args.size() > 9) {
bungeeBroadcast = Boolean.valueOf(args.get(9));
}
if (!bungeeBroadcast) {
if (!plugin.getBungeeSettings().isBungeeBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
if (Boolean.valueOf(args.get(4)) || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
VoteSite site = plugin.getVoteSite(service, true);
if (site != null) {
site.broadcastVote(user, false);
broadcast = false;
} else {
plugin.getLogger().warning("No votesite for " + service);
}
}
}
} else {
broadcast = false;
}
user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
if (plugin.getBungeeSettings().isPerServerPoints()) {
user.addPoints(plugin.getConfigFile().getPointsOnVote());
}
if (Boolean.valueOf(args.get(5))) {
plugin.getServerData().addServiceSite(service);
}
} else {
plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
}
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteUpdate") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
String player = args.get(0);
plugin.debug("pluginmessaging voteupdate received for " + player);
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(player));
user.clearCache();
user.offVote();
if (args.size() > 2) {
bungeeVotePartyCurrent = Integer.parseInt(args.get(1));
bungeeVotePartyRequired = Integer.parseInt(args.get(2));
}
plugin.setUpdate(true);
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteBroadcast") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
if (args.size() > 2) {
String uuid = args.get(0);
String service = args.get(2);
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), args.get(1));
VoteSite site = plugin.getVoteSite(service, true);
if (site != null) {
site.broadcastVote(user, false);
} else {
plugin.getLogger().warning("No votesite for " + service);
}
}
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("Status") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
String server = args.get(0);
plugin.getPluginMessaging().sendPluginMessage("statusokay", server);
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBungee") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
for (Player p : Bukkit.getOnlinePlayers()) {
new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
}
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBroadcast") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
String broadcast = args.get(0);
MiscUtils.getInstance().broadcast(broadcast);
}
});
} else if (method.equals(BungeeMethod.SOCKETS)) {
encryptionHandler = new EncryptionHandler(new File(plugin.getDataFolder(), "secretkey.key"));
clientHandler = new ClientHandler(plugin.getBungeeSettings().getBungeeServerHost(), plugin.getBungeeSettings().getBungeeServerPort(), encryptionHandler, plugin.getBungeeSettings().isBungeeDebug());
socketHandler = new SocketHandler(plugin.getVersion(), plugin.getBungeeSettings().getSpigotServerHost(), plugin.getBungeeSettings().getSpigotServerPort(), encryptionHandler, plugin.getBungeeSettings().isBungeeDebug());
socketHandler.add(new SocketReceiver("bungeevote") {
@Override
public void onReceive(String[] data) {
if (data.length > 5) {
plugin.extraDebug("BungeeVote from " + data[2] + ", processing");
String uuid = data[1];
VotingPluginUser user = null;
if (!uuid.isEmpty()) {
user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
} else {
user = UserManager.getInstance().getVotingPluginUser(data[2]);
}
user.clearCache();
if (plugin.getBungeeSettings().isPerServerPoints()) {
user.addPoints(plugin.getConfigFile().getPointsOnVote());
}
user.bungeeVote(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
}
}
});
socketHandler.add(new SocketReceiver("bungeevoteonline") {
@Override
public void onReceive(String[] data) {
if (data.length > 5) {
plugin.extraDebug("BungeeVoteOnline from " + data[2] + ", processing");
String uuid = data[1];
VotingPluginUser user = null;
if (!uuid.isEmpty()) {
user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
} else {
user = UserManager.getInstance().getVotingPluginUser(data[2]);
}
user.clearCache();
if (plugin.getBungeeSettings().isPerServerPoints()) {
user.addPoints(plugin.getConfigFile().getPointsOnVote());
}
user.bungeeVoteOnline(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
}
}
});
socketHandler.add(new SocketReceiver("BungeeBroadcast") {
@Override
public void onReceive(String[] data) {
if (data.length > 2) {
VoteSite site = plugin.getVoteSite(data[1], true);
String p = data[3];
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
if (site != null) {
site.broadcastVote(user, false);
} else {
plugin.getLogger().warning("No votesite for " + data[1]);
}
}
}
});
socketHandler.add(new SocketReceiver("Status") {
@Override
public void onReceive(String[] data) {
if (data.length > 0) {
plugin.getLogger().info("Received status command, sending status back");
sendData("StatusOkay", plugin.getOptions().getServer());
}
}
});
socketHandler.add(new SocketReceiver("BungeeUpdate") {
@Override
public void onReceive(String[] data) {
plugin.setUpdate(true);
}
});
socketHandler.add(new SocketReceiver("VotePartyBungee") {
@Override
public void onReceive(String[] data) {
for (Player p : Bukkit.getOnlinePlayers()) {
new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
}
}
});
socketHandler.add(new SocketReceiver("VotePartyBroadcast") {
@Override
public void onReceive(String[] data) {
String broadcast = data[0];
MiscUtils.getInstance().broadcast(broadcast);
}
});
if (plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
}
}
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class AdminGUI method openAdminGUIVoteSites.
/**
* Open admin GUI vote sites.
*
* @param player the player
*/
public void openAdminGUIVoteSites(Player player) {
BInventory inv = new BInventory("VoteSites");
int count = 0;
for (VoteSite voteSite : plugin.getVoteSites()) {
ArrayList<String> lore = new ArrayList<String>();
lore.add("Priority: " + voteSite.getPriority());
lore.add("Name: " + voteSite.getDisplayName());
lore.add("ServiceSite: " + voteSite.getServiceSite());
lore.add("VoteURL: " + voteSite.getVoteURL());
lore.add("VoteDelay: " + voteSite.getVoteDelay());
lore.add("VoteDelayMin: " + voteSite.getVoteDelayMin());
inv.addButton(count, new BInventoryButton(voteSite.getKey(), ArrayUtils.getInstance().convert(lore), new ItemStack(Material.STONE)) {
@Override
public void onClick(ClickEvent event) {
Player player = event.getWhoClicked();
openAdminGUIVoteSiteSite(player, voteSite);
}
});
count++;
}
inv.openInventory(player);
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class VoteNext method onChest.
@Override
public void onChest(Player player) {
BInventory inv = new BInventory(plugin.getGui().getChestVoteNextName());
inv.addPlaceholder("player", user.getPlayerName());
for (VoteSite site : plugin.getVoteSites()) {
if (!site.isHidden()) {
inv.addButton(inv.getNextSlot(), new UpdatingBInventoryButton(site.getItem().setName(site.getDisplayName()).setLore(user.voteCommandNextInfo(site)).setAmountNone(1), 1000, 1000) {
@Override
public void onClick(ClickEvent clickEvent) {
}
@Override
public ItemBuilder onUpdate(Player player) {
return site.getItem().setName(site.getDisplayName()).setLore(user.voteCommandNextInfo(site)).setAmountNone(1).addPlaceholder("player", user.getPlayerName());
}
});
}
}
if (plugin.getGui().getChestVoteNextBackButton()) {
inv.addButton(plugin.getCommandLoader().getBackButton(user));
}
inv.openInventory(player);
}
use of com.bencodez.votingplugin.objects.VoteSite in project VotingPlugin by Ben12345rocks.
the class VoteNext method onBook.
@Override
public void onBook(Player player) {
BookWrapper book = new BookWrapper(plugin.getGui().getBookVoteURLBookGUITitle());
// add colors/config options
for (VoteSite site : plugin.getVoteSites()) {
if (!site.isHidden()) {
Layout nextLayout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
nextLayout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(book.colorize(site.getDisplayName())).onClick(BookUtil.ClickAction.openUrl(site.getVoteURLJsonStrip())).onHover(BookUtil.HoverAction.showText(user.voteCommandNextInfo(site))).build());
book.addLayout(nextLayout);
}
}
book.addLine();
book.open(player);
}
Aggregations