use of com.bencodez.advancedcore.api.user.usercache.value.DataValueInt in project VotingPlugin by Ben12345rocks.
the class VotingPluginBungee method vote.
public synchronized void vote(String player, String service, boolean realVote) {
try {
if (player == null || player.isEmpty()) {
getLogger().info("No name from vote on " + service);
return;
}
String uuid = getUUID(player);
if (uuid.isEmpty()) {
if (config.getAllowUnJoined()) {
debug("Fetching UUID online, since allowunjoined is enabled");
UUID u = null;
try {
u = fetchUUID(player);
} catch (Exception e) {
if (getConfig().getDebug()) {
e.printStackTrace();
}
}
if (u == null) {
debug("Failed to get uuid for " + player);
return;
}
uuid = u.toString();
} else {
getLogger().info("Ignoring vote from " + player + " since player hasn't joined before");
return;
}
}
player = getProperName(uuid, player);
BungeeMessageData text = null;
addVoteParty();
if (getConfig().getBungeeManageTotals()) {
if (mysql == null) {
getLogger().severe("Mysql is not loaded correctly, stopping vote processing");
return;
}
// one time query to insert player
if (!mysql.getUuids().contains(uuid)) {
mysql.update(uuid, "PlayerName", new DataValueString(player));
}
ArrayList<Column> data = mysql.getExactQuery(new Column("uuid", new DataValueString(uuid)));
int allTimeTotal = getValue(data, "AllTimeTotal", 1);
int monthTotal = getValue(data, "MonthTotal", 1);
int weeklyTotal = getValue(data, "WeeklyTotal", 1);
int dailyTotal = getValue(data, "DailyTotal", 1);
int points = getValue(data, "Points", getConfig().getPointsOnVote());
int milestoneCount = getValue(data, "MilestoneCount", 1);
text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount, votePartyVotes, currentVotePartyVotesRequired);
ArrayList<Column> update = new ArrayList<Column>();
update.add(new Column("AllTimeTotal", new DataValueInt(allTimeTotal)));
update.add(new Column("MonthTotal", new DataValueInt(monthTotal)));
update.add(new Column("WeeklyTotal", new DataValueInt(weeklyTotal)));
update.add(new Column("DailyTotal", new DataValueInt(dailyTotal)));
update.add(new Column("Points", new DataValueInt(points)));
update.add(new Column("MilestoneCount", new DataValueInt(milestoneCount)));
debug("Setting totals " + text.toString());
mysql.update(uuid, update);
} else {
text = new BungeeMessageData(0, 0, 0, 0, 0, 0, votePartyVotes, currentVotePartyVotesRequired);
}
long time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
if (config.getSendVotesToAllServers()) {
for (String s : getProxy().getServers().keySet()) {
if (!config.getBlockedServers().contains(s)) {
ServerInfo info = getProxy().getServerInfo(s);
boolean forceCache = false;
ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(uuid));
if (!isOnline(p) && getConfig().getWaitForUserOnline()) {
forceCache = true;
debug("Forcing vote to cache");
}
if (info.getPlayers().isEmpty() || forceCache) {
// cache
if (!cachedVotes.containsKey(s)) {
cachedVotes.put(s, new ArrayList<OfflineBungeeVote>());
}
ArrayList<OfflineBungeeVote> list = cachedVotes.get(s);
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
cachedVotes.put(s, list);
debug("Caching vote for " + player + " on " + service + " for " + s);
} else {
// send
sendPluginMessageServer(s, "Vote", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
}
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
}
}
}
} else {
ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(uuid));
if (isOnline(p) && !config.getBlockedServers().contains(p.getServer().getInfo().getName())) {
sendPluginMessageServer(p.getServer().getInfo().getName(), "VoteOnline", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
} else {
if (!cachedOnlineVotes.containsKey(uuid)) {
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
}
ArrayList<OfflineBungeeVote> list = cachedOnlineVotes.get(uuid);
if (list == null) {
list = new ArrayList<OfflineBungeeVote>();
}
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
cachedOnlineVotes.put(uuid, list);
debug("Caching online vote for " + player + " on " + service);
}
for (String s : getProxy().getServers().keySet()) {
sendPluginMessageServer(s, "VoteUpdate", uuid, "" + votePartyVotes, "" + currentVotePartyVotesRequired);
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
}
}
}
} else if (method.equals(BungeeMethod.SOCKETS)) {
sendSocketVote(player, service, text);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.bencodez.advancedcore.api.user.usercache.value.DataValueInt in project VotingPlugin by Ben12345rocks.
the class VotingPluginVelocity method vote.
public synchronized void vote(String player, String service, boolean realVote) {
try {
if (player == null || player.isEmpty()) {
logger.info("No name from vote on " + service);
return;
}
String uuid = getUUID(player);
if (uuid.isEmpty()) {
if (config.getAllowUnJoined()) {
debug("Fetching UUID online, since allowunjoined is enabled");
UUID u = null;
try {
u = fetchUUID(player);
} catch (Exception e) {
if (getConfig().getDebug()) {
e.printStackTrace();
}
}
if (u == null) {
debug("Failed to get uuid for " + player);
return;
}
uuid = u.toString();
} else {
logger.info("Ignoring vote from " + player + " since player hasn't joined before");
return;
}
}
player = getProperName(uuid, player);
BungeeMessageData text = null;
addVoteParty();
if (getConfig().getBungeeManageTotals()) {
if (mysql == null) {
logger.error("Mysql is not loaded correctly, stopping vote processing");
return;
}
if (!mysql.getUuids().contains(uuid)) {
mysql.update(uuid, "PlayerName", new DataValueString(player));
}
ArrayList<Column> data = mysql.getExactQuery(new Column("uuid", new DataValueString(uuid)));
int allTimeTotal = getValue(data, "AllTimeTotal", 1);
int monthTotal = getValue(data, "MonthTotal", 1);
int weeklyTotal = getValue(data, "WeeklyTotal", 1);
int dailyTotal = getValue(data, "DailyTotal", 1);
int points = getValue(data, "Points", getConfig().getPointsOnVote());
int milestoneCount = getValue(data, "MilestoneCount", 1);
text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount, votePartyVotes, currentVotePartyVotesRequired);
ArrayList<Column> update = new ArrayList<Column>();
update.add(new Column("AllTimeTotal", new DataValueInt(allTimeTotal)));
update.add(new Column("MonthTotal", new DataValueInt(monthTotal)));
update.add(new Column("WeeklyTotal", new DataValueInt(weeklyTotal)));
update.add(new Column("DailyTotal", new DataValueInt(dailyTotal)));
update.add(new Column("Points", new DataValueInt(points)));
update.add(new Column("MilestoneCount", new DataValueInt(milestoneCount)));
debug("Setting totals " + text.toString());
mysql.update(uuid, update);
} else {
text = new BungeeMessageData(0, 0, 0, 0, 0, 0, votePartyVotes, currentVotePartyVotesRequired);
}
/*
* String text = mysqlUpdate(data, uuid, "AllTimeTotal", 1) + "//" +
* mysqlUpdate(data, uuid, "MonthTotal", 1) + "//" + mysqlUpdate(data, uuid,
* "WeeklyTotal", 1) + "//" + mysqlUpdate(data, uuid, "DailyTotal", 1) + "//" +
* mysqlUpdate(data, uuid, "Points", 1) + "//" + mysqlUpdate(data, uuid,
* "MilestoneCount", 1);
*/
long time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
if (config.getSendVotesToAllServers()) {
for (RegisteredServer s : server.getAllServers()) {
if (!config.getBlockedServers().contains(s.getServerInfo().getName())) {
boolean forceCache = false;
Player p = null;
if (server.getPlayer(UUID.fromString(uuid)).isPresent()) {
p = server.getPlayer(UUID.fromString(uuid)).get();
}
if ((p == null || !p.isActive()) && getConfig().getWaitForUserOnline()) {
forceCache = true;
debug("Forcing vote to cache");
}
if (s.getPlayersConnected().isEmpty() || forceCache) {
// cache
if (!cachedVotes.containsKey(s)) {
cachedVotes.put(s, new ArrayList<OfflineBungeeVote>());
}
ArrayList<OfflineBungeeVote> list = cachedVotes.get(s);
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
cachedVotes.put(s, list);
debug("Caching vote for " + player + " on " + service + " for " + s);
} else {
// send
sendPluginMessageServer(s, "Vote", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
}
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
}
}
}
} else {
Player p = null;
if (server.getPlayer(UUID.fromString(uuid)).isPresent()) {
p = server.getPlayer(UUID.fromString(uuid)).get();
}
if (p != null && p.isActive() && !config.getBlockedServers().contains(p.getCurrentServer().get().getServerInfo().getName())) {
sendPluginMessageServer(p.getCurrentServer().get().getServer(), "VoteOnline", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
} else {
if (!cachedOnlineVotes.containsKey(uuid)) {
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
}
ArrayList<OfflineBungeeVote> list = cachedOnlineVotes.get(uuid);
if (list == null) {
list = new ArrayList<OfflineBungeeVote>();
}
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
cachedOnlineVotes.put(uuid, list);
debug("Caching online vote for " + player + " on " + service);
}
for (RegisteredServer s : server.getAllServers()) {
sendPluginMessageServer(s, "VoteUpdate", uuid, "" + votePartyVotes, "" + currentVotePartyVotesRequired);
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
}
}
}
} else if (method.equals(BungeeMethod.SOCKETS)) {
sendSocketVote(player, service, text);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations