use of com.bencodez.votingplugin.bungee.BungeeMessageData 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();
}
}
use of com.bencodez.votingplugin.bungee.BungeeMessageData 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");
}
}
}
Aggregations