diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java index 3de022cfd..e4bd89656 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java @@ -18,6 +18,7 @@ import java.time.ZoneId; import java.time.ZoneOffset; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -50,6 +51,9 @@ import com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler; import com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver; import com.bencodez.advancedcore.bungeeapi.time.BungeeTimeChecker; +import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyHandler; +import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyServerSocketConfiguration; +import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyServerSocketConfigurationBungee; import com.bencodez.votingplugin.timequeue.VoteTimeQueue; import com.bencodez.votingplugin.topvoter.TopVoter; import com.google.gson.JsonElement; @@ -79,10 +83,6 @@ public class VotingPluginBungee extends Plugin implements Listener { private HashMap clientHandles; - private HashMap multiproxyClientHandles; - - private SocketHandler multiproxySocketHandler; - @Getter private Config config; @@ -178,7 +178,7 @@ public synchronized void checkOnlineVotes(ProxiedPlayer player, String uuid, Str } cachedOnlineVotes.put(uuid, new ArrayList()); if (getConfig().getMultiProxySupport() && getConfig().getMultiProxyOneGlobalReward()) { - sendMultiProxyServerMessage("ClearVote", player.getName(), uuid); + multiProxyHandler.sendMultiProxyServerMessage("ClearVote", player.getName(), uuid); } } } @@ -375,6 +375,7 @@ public void onTimeChangedFinished(TimeType type) { } processQueue(); + } @@ -557,6 +558,9 @@ public void onDisable() { private VoteEventBungee voteEventBungee; + @Getter + private MultiProxyHandler multiProxyHandler; + @Override public void onEnable() { enabled = true; @@ -899,9 +903,9 @@ public void run() { currentVotePartyVotesRequired = getConfig().getVotePartyVotesRequired() + voteCacheFile.getVotePartyInreaseVotesRequired(); votePartyVotes = voteCacheFile.getVotePartyCurrentVotes(); - } - loadMultiProxySupport(); + loadMultiProxySupport(); + } if (!votifierEnabled) { if (!(getConfig().getMultiProxySupport() && !getConfig().getPrimaryServer())) { @@ -954,70 +958,98 @@ public void run() { } - public void sendServerNameMessage() { - if (method.equals(BungeeMethod.PLUGINMESSAGING)) { - for (String s : getAvailableAllServers()) { - sendPluginMessageServer(s, "ServerName", s); - } + private void loadMultiProxySupport() { + if (multiProxyHandler != null) { + multiProxyHandler.close(); } + multiProxyHandler = new MultiProxyHandler() { - } + @Override + public void triggerVote(String player, String service, boolean realVote, boolean timeQueue, long queueTime, + BungeeMessageData text, String uuid) { + vote(player, service, realVote, timeQueue, queueTime, text, uuid); + } - public void loadMultiProxySupport() { - if (getConfig().getMultiProxySupport()) { - if (encryptionHandler == null) { - encryptionHandler = new EncryptionHandler(new File(getDataFolder(), "secretkey.key")); + @Override + public void setEncryptionHandler(EncryptionHandler encryptionHandler1) { + encryptionHandler = encryptionHandler1; } - if (multiproxySocketHandler != null) { - multiproxySocketHandler.closeConnection(); - multiproxySocketHandler = null; + @Override + public void logInfo(String msg) { + getLogger().info(msg); } - multiproxySocketHandler = new SocketHandler(getDescription().getVersion(), - config.getMultiProxySocketHostHost(), config.getMultiProxySocketHostPort(), encryptionHandler, - config.getDebug()) { - @Override - public void log(String str) { - getLogger().info(str); - } - }; + @Override + public String getVersion() { + return getDescription().getVersion(); + } - multiproxySocketHandler.add(new SocketReceiver() { + @Override + public boolean getMultiProxySupportEnabled() { + return config.getMultiProxySupport(); + } - @Override - public void onReceive(String[] data) { - if (data.length > 0) { - if (data[0].equalsIgnoreCase("Status")) { - getLogger().info("Multi-proxy status message received"); - } else if (data[0].equalsIgnoreCase("ClearVote")) { - cachedOnlineVotes.remove(data[2]); - } else if (data[0].equalsIgnoreCase("login")) { - nonVotedPlayersCache.addPlayer(data[1], data[2]); - } - } - if (data.length > 8) { - if (data[0].equalsIgnoreCase("Vote")) { - vote(data[2], data[3], Boolean.valueOf(data[7]), true, 0, new BungeeMessageData(data[8]), - data[1]); - } else if (data[0].equalsIgnoreCase("VoteOnline")) { - vote(data[2], data[3], Boolean.valueOf(data[7]), true, 0, new BungeeMessageData(data[8]), - data[1]); - } - } + @Override + protected int getMultiProxySocketHostPort() { + return config.getMultiProxySocketHostPort(); + } - } - }); + @Override + protected String getMultiProxySocketHostHost() { + return config.getMultiProxySocketHostHost(); + } + + @Override + protected MultiProxyServerSocketConfiguration getMultiProxyServersConfiguration(String s) { + return new MultiProxyServerSocketConfigurationBungee(s, config.getMultiProxyServersConfiguration(s)); + } - multiproxyClientHandles = new HashMap(); - for (String s : config.getMultiProxyServers()) { - Configuration d = config.getMultiProxyServersConfiguration(s); - multiproxyClientHandles.put(s, new ClientHandler(d.getString("Host", ""), d.getInt("Port", 1234), - encryptionHandler, config.getDebug())); + @Override + protected Collection getMultiProxyServers() { + return config.getMultiProxyServers(); + } + + @Override + public EncryptionHandler getEncryptionHandler() { + return encryptionHandler; + } + + @Override + public boolean getDebug() { + return config.getDebug(); + } + + @Override + public File getPluginDataFolder() { + return getDataFolder(); } - getLogger().info("Loaded multi-proxy support"); + @Override + protected void clearVote(String string) { + cachedOnlineVotes.remove(string); + } + + @Override + protected void addNonVotedPlayerCache(String uuid, String player) { + nonVotedPlayersCache.addPlayer(uuid, player); + } + + @Override + public boolean getPrimaryServer() { + return config.getPrimaryServer(); + } + }; + multiProxyHandler.loadMultiProxySupport(); + } + + public void sendServerNameMessage() { + if (method.equals(BungeeMethod.PLUGINMESSAGING)) { + for (String s : getAvailableAllServers()) { + sendPluginMessageServer(s, "ServerName", s); + } } + } @EventHandler @@ -1053,7 +1085,7 @@ public void run() { if (isOnline(p)) { checkCachedVotes(server); checkOnlineVotes(proxiedPlayer, proxiedPlayer.getUniqueId().toString(), server); - multiProxyLogin(proxiedPlayer); + multiProxyHandler.login(proxiedPlayer.getUniqueId().toString(), proxiedPlayer.getName()); } } }, 1, TimeUnit.SECONDS); @@ -1061,16 +1093,6 @@ public void run() { } - public void multiProxyLogin(ProxiedPlayer p) { - if (!config.getMultiProxySupport()) { - return; - } - if (config.getPrimaryServer()) { - return; - } - sendMultiProxyServerMessage("Login", p.getUniqueId().toString(), p.getName()); - } - @EventHandler public void onPluginMessage(PluginMessageEvent ev) { if (!ev.getTag().equals("vp:vp".toLowerCase())) { @@ -1206,12 +1228,6 @@ public void sendServerMessage(String... messageData) { } } - public void sendMultiProxyServerMessage(String... messageData) { - for (ClientHandler h : multiproxyClientHandles.values()) { - h.sendMessage(messageData); - } - } - public void sendServerMessageServer(String server, String... messageData) { if (clientHandles.containsKey(server)) { clientHandles.get(server).sendMessage(messageData); @@ -1414,7 +1430,7 @@ public synchronized void vote(String player, String service, boolean realVote, b "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast(), "1", "1"); if (getConfig().getMultiProxySupport() && getConfig().getMultiProxyOneGlobalReward()) { - sendMultiProxyServerMessage("ClearVote", player, uuid); + multiProxyHandler.sendMultiProxyServerMessage("ClearVote", player, uuid); } } else { if (!cachedOnlineVotes.containsKey(uuid)) { @@ -1443,14 +1459,15 @@ public synchronized void vote(String player, String service, boolean realVote, b if (getConfig().getMultiProxySupport() && getConfig().getPrimaryServer()) { if (!getConfig().getMultiProxyOneGlobalReward()) { debug("Seending global proxy vote message"); - sendMultiProxyServerMessage("Vote", uuid, player, service, "" + votePartyVotes, + multiProxyHandler.sendMultiProxyServerMessage("Vote", uuid, player, service, "" + votePartyVotes, "" + currentVotePartyVotesRequired, "" + time, "" + realVote, text.toString()); } else { // check if reward should've already been given if (!(isOnline(p) && !config.getBlockedServers().contains(p.getServer().getInfo().getName()))) { debug("Sending global proxy voteonline message"); - sendMultiProxyServerMessage("VoteOnline", uuid, player, service, "" + votePartyVotes, - "" + currentVotePartyVotesRequired, "" + time, "" + realVote, text.toString()); + multiProxyHandler.sendMultiProxyServerMessage("VoteOnline", uuid, player, service, + "" + votePartyVotes, "" + currentVotePartyVotesRequired, "" + time, "" + realVote, + text.toString()); } else { debug("Not sending global proxy message for voteonline, player already got reward"); } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungeeCommand.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungeeCommand.java index e9edc579e..38547ccd1 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungeeCommand.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungeeCommand.java @@ -61,7 +61,7 @@ public void execute(CommandSender sender, String[] args) { } } if (args[0].equalsIgnoreCase("multiproxystatus")) { - bungee.sendMultiProxyServerMessage("Status"); + bungee.getMultiProxyHandler().sendMultiProxyServerMessage("Status"); sender.sendMessage(new TextComponent("&aSending status message")); } if (args[0].equalsIgnoreCase("help")) { diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyHandler.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyHandler.java new file mode 100644 index 000000000..6996ae67d --- /dev/null +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyHandler.java @@ -0,0 +1,133 @@ +package com.bencodez.votingplugin.bungee.global.multiproxy; + +import java.io.File; +import java.util.Collection; +import java.util.HashMap; + +import com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler; +import com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler; +import com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler; +import com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver; +import com.bencodez.votingplugin.bungee.BungeeMessageData; + +public abstract class MultiProxyHandler { + public abstract boolean getMultiProxySupportEnabled(); + + public abstract EncryptionHandler getEncryptionHandler(); + + public abstract File getPluginDataFolder(); + + public abstract void setEncryptionHandler(EncryptionHandler encryptionHandler); + + public abstract void logInfo(String msg); + + public abstract boolean getDebug(); + + public abstract String getVersion(); + + private HashMap multiproxyClientHandles; + + private SocketHandler multiproxySocketHandler; + + public MultiProxyHandler() { + + } + + public void sendMultiProxyServerMessage(String... messageData) { + for (ClientHandler h : multiproxyClientHandles.values()) { + h.sendMessage(messageData); + } + } + + public void close() { + if (multiproxySocketHandler != null) { + multiproxySocketHandler.closeConnection(); + multiproxySocketHandler = null; + } + } + + public void loadMultiProxySupport() { + if (getMultiProxySupportEnabled()) { + if (getEncryptionHandler() == null) { + setEncryptionHandler(new EncryptionHandler(new File(getPluginDataFolder(), "secretkey.key"))); + } + + if (multiproxySocketHandler != null) { + multiproxySocketHandler.closeConnection(); + multiproxySocketHandler = null; + } + multiproxySocketHandler = new SocketHandler(getVersion(), getMultiProxySocketHostHost(), + getMultiProxySocketHostPort(), getEncryptionHandler(), getDebug()) { + + @Override + public void log(String str) { + logInfo(str); + } + }; + + multiproxySocketHandler.add(new SocketReceiver() { + + @Override + public void onReceive(String[] data) { + if (data.length > 0) { + if (data[0].equalsIgnoreCase("Status")) { + logInfo("Multi-proxy status message received"); + } else if (data[0].equalsIgnoreCase("ClearVote")) { + clearVote(data[2]); + // cachedOnlineVotes.remove(data[2]); + } else if (data[0].equalsIgnoreCase("login")) { + addNonVotedPlayerCache(data[1], data[2]); + // nonVotedPlayersCache.addPlayer(data[1], data[2]); + } + } + if (data.length > 8) { + if (data[0].equalsIgnoreCase("Vote")) { + triggerVote(data[2], data[3], Boolean.valueOf(data[7]), true, 0, + new BungeeMessageData(data[8]), data[1]); + } else if (data[0].equalsIgnoreCase("VoteOnline")) { + triggerVote(data[2], data[3], Boolean.valueOf(data[7]), true, 0, + new BungeeMessageData(data[8]), data[1]); + } + } + + } + }); + + multiproxyClientHandles = new HashMap(); + for (String s : getMultiProxyServers()) { + MultiProxyServerSocketConfiguration d = getMultiProxyServersConfiguration(s); + multiproxyClientHandles.put(s, + new ClientHandler(d.getHost(), d.getPort(), getEncryptionHandler(), getDebug())); + } + + logInfo("Loaded multi-proxy support"); + } + } + + public abstract boolean getPrimaryServer(); + + public void login(String uuid, String playerName) { + if (!getMultiProxySupportEnabled()) { + return; + } + if (getPrimaryServer()) { + return; + } + sendMultiProxyServerMessage("Login", uuid, playerName); + } + + protected abstract int getMultiProxySocketHostPort(); + + protected abstract String getMultiProxySocketHostHost(); + + protected abstract MultiProxyServerSocketConfiguration getMultiProxyServersConfiguration(String s); + + protected abstract Collection getMultiProxyServers(); + + protected abstract void triggerVote(String player, String service, boolean realVote, boolean timeQueue, + long queueTime, BungeeMessageData text, String uuid); + + protected abstract void addNonVotedPlayerCache(String string, String string2); + + protected abstract void clearVote(String string); +} diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfiguration.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfiguration.java new file mode 100644 index 000000000..c2921f79c --- /dev/null +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfiguration.java @@ -0,0 +1,9 @@ +package com.bencodez.votingplugin.bungee.global.multiproxy; + +public interface MultiProxyServerSocketConfiguration { + String getServerName(); + + String getHost(); + + int getPort(); +} diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfigurationBungee.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfigurationBungee.java new file mode 100644 index 000000000..0106eb164 --- /dev/null +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfigurationBungee.java @@ -0,0 +1,31 @@ +package com.bencodez.votingplugin.bungee.global.multiproxy; + +import net.md_5.bungee.config.Configuration; + +public class MultiProxyServerSocketConfigurationBungee implements MultiProxyServerSocketConfiguration { + private String server; + private String host; + private int port; + + public MultiProxyServerSocketConfigurationBungee(String s, Configuration config) { + server = s; + host = config.getString("Host", ""); + port = config.getInt("Port", 1234); + } + + @Override + public String getServerName() { + return server; + } + + @Override + public String getHost() { + return host; + } + + @Override + public int getPort() { + return port; + } + +} diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfigurationVelocity.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfigurationVelocity.java new file mode 100644 index 000000000..5eb2f013f --- /dev/null +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/global/multiproxy/MultiProxyServerSocketConfigurationVelocity.java @@ -0,0 +1,33 @@ +package com.bencodez.votingplugin.bungee.global.multiproxy; + +import ninja.leaping.configurate.ConfigurationNode; + +public class MultiProxyServerSocketConfigurationVelocity implements MultiProxyServerSocketConfiguration { + + private String server; + private String host; + private int port; + + public MultiProxyServerSocketConfigurationVelocity(String s, ConfigurationNode config) { + server = s; + host = config.getNode("Host").getString("0.0.0.0"); + port = config.getNode("Port").getInt(1298); + + } + + @Override + public String getServerName() { + return server; + } + + @Override + public String getHost() { + return host; + } + + @Override + public int getPort() { + return port; + } + +} diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java index c715d0d9a..f3daaaf62 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java @@ -66,6 +66,9 @@ import com.bencodez.votingplugin.bungee.BungeeMethod; import com.bencodez.votingplugin.bungee.BungeeVersion; import com.bencodez.votingplugin.bungee.OfflineBungeeVote; +import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyHandler; +import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyServerSocketConfiguration; +import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyServerSocketConfigurationVelocity; import com.bencodez.votingplugin.timequeue.VoteTimeQueue; import com.bencodez.votingplugin.topvoter.TopVoter; import com.google.gson.JsonElement; @@ -136,10 +139,6 @@ public class VotingPluginVelocity { @Getter private GlobalDataHandlerProxy globalDataHandler; - private HashMap multiproxyClientHandles; - - private SocketHandler multiproxySocketHandler; - @Getter private RedisHandler redisHandler; @@ -218,7 +217,7 @@ public synchronized void checkOnlineVotes(Player player, String uuid, Registered } cachedOnlineVotes.put(uuid, new ArrayList()); if (getConfig().getMultiProxySupport() && getConfig().getMultiProxyOneGlobalReward()) { - sendMultiProxyServerMessage("ClearVote", player.getUsername(), uuid); + getMultiProxyHandler().sendMultiProxyServerMessage("ClearVote", player.getUsername(), uuid); } } } @@ -512,7 +511,7 @@ public void onPluginMessagingReceived(PluginMessageEvent event) { public void run() { checkCachedVotes(server); checkOnlineVotes(p1, p.getUniqueId().toString(), server); - multiProxyLogin(p1); + getMultiProxyHandler().login(p1.getUniqueId().toString(), p1.getUsername()); } }); @@ -967,7 +966,8 @@ protected void onMessage(String channel, String[] message) { public void run() { checkCachedVotes(server); checkOnlineVotes(p1, p.getUniqueId().toString(), server); - multiProxyLogin(p1); + getMultiProxyHandler().login(p1.getUniqueId().toString(), + p1.getUsername()); } }); @@ -1050,73 +1050,105 @@ public void debug(String message) { sendServerNameMessage(); } - public void sendServerNameMessage() { - if (method.equals(BungeeMethod.PLUGINMESSAGING)) { - for (RegisteredServer s : getAvailableAllServers()) { - sendPluginMessageServer(s, "ServerName", s.getServerInfo().getName()); - } + private void loadMultiProxySupport() { + if (multiProxyHandler != null) { + multiProxyHandler.close(); } + multiProxyHandler = new MultiProxyHandler() { - } + @Override + public void triggerVote(String player, String service, boolean realVote, boolean timeQueue, long queueTime, + BungeeMessageData text, String uuid) { + vote(player, service, realVote, timeQueue, queueTime, text, uuid); + } - public void loadMultiProxySupport() { - if (getConfig().getMultiProxySupport()) { - if (encryptionHandler == null) { - encryptionHandler = new EncryptionHandler(new File(dataDirectory.toFile(), "secretkey.key")); + @Override + public void setEncryptionHandler(EncryptionHandler encryptionHandler1) { + encryptionHandler = encryptionHandler1; } - if (multiproxySocketHandler != null) { - multiproxySocketHandler.closeConnection(); - multiproxySocketHandler = null; + @Override + public void logInfo(String msg) { + getLogger().info(msg); } - multiproxySocketHandler = new SocketHandler( - server.getPluginManager().getPlugin("votingplugin").get().getDescription().getVersion().get(), - config.getMultiProxySocketHostHost(), config.getMultiProxySocketHostPort(), encryptionHandler, - config.getDebug()) { - @Override - public void log(String str) { - getLogger().info(str); - } - }; - - multiproxySocketHandler.add(new SocketReceiver() { - - @Override - public void onReceive(String[] data) { - if (data.length > 0) { - if (data[0].equalsIgnoreCase("Status")) { - getLogger().info("Multi-proxy status message received"); - } else if (data[0].equalsIgnoreCase("ClearVote")) { - cachedOnlineVotes.remove(data[2]); - } else if (data[0].equalsIgnoreCase("login")) { - nonVotedPlayersCache.addPlayer(data[1], data[2]); - } - } - if (data.length > 8) { - if (data[0].equalsIgnoreCase("Vote")) { - vote(data[2], data[3], Boolean.valueOf(data[7]), true, 0, new BungeeMessageData(data[8]), - data[1]); - } else if (data[0].equalsIgnoreCase("VoteOnline")) { - vote(data[2], data[3], Boolean.valueOf(data[7]), true, 0, new BungeeMessageData(data[8]), - data[1]); - } - } + @Override + public String getVersion() { + return server.getPluginManager().getPlugin("votingplugin").get().getDescription().getVersion().get(); + } + + @Override + public boolean getMultiProxySupportEnabled() { + return config.getMultiProxySupport(); + } + + @Override + protected int getMultiProxySocketHostPort() { + return config.getMultiProxySocketHostPort(); + } + @Override + protected String getMultiProxySocketHostHost() { + return config.getMultiProxySocketHostHost(); + } + + @Override + protected MultiProxyServerSocketConfiguration getMultiProxyServersConfiguration(String s) { + return new MultiProxyServerSocketConfigurationVelocity(s, config.getMultiProxyServers(s)); + } + + @Override + protected Collection getMultiProxyServers() { + ArrayList servers = new ArrayList(); + for (ConfigurationNode s : config.getMultiProxyServers()) { + servers.add(s.getKey().toString()); } - }); + return servers; + } - multiproxyClientHandles = new HashMap(); + @Override + public EncryptionHandler getEncryptionHandler() { + return encryptionHandler; + } + + @Override + public boolean getDebug() { + return config.getDebug(); + } - for (ConfigurationNode s : config.getMultiProxyServers()) { - ConfigurationNode d = config.getMultiProxyServers(s.getKey().toString()); - multiproxyClientHandles.put(s.getKey().toString(), - new ClientHandler(d.getNode("Host").getString("0.0.0.0"), d.getNode("Port").getInt(1298), - encryptionHandler, config.getDebug())); + @Override + public File getPluginDataFolder() { + return dataDirectory.toFile(); + } + + @Override + protected void clearVote(String string) { + cachedOnlineVotes.remove(string); } - getLogger().info("Loaded multi-proxy support"); + @Override + protected void addNonVotedPlayerCache(String uuid, String player) { + nonVotedPlayersCache.addPlayer(uuid, player); + } + + @Override + public boolean getPrimaryServer() { + return config.getPrimaryServer(); + } + }; + multiProxyHandler.loadMultiProxySupport(); + } + + @Getter + private MultiProxyHandler multiProxyHandler; + + public void sendServerNameMessage() { + if (method.equals(BungeeMethod.PLUGINMESSAGING)) { + for (RegisteredServer s : getAvailableAllServers()) { + sendPluginMessageServer(s, "ServerName", s.getServerInfo().getName()); + } } + } private String version = ""; @@ -1458,7 +1490,7 @@ public synchronized void vote(String player, String service, boolean realVote, b "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast(), "1", "1"); if (getConfig().getMultiProxySupport() && getConfig().getMultiProxyOneGlobalReward()) { - sendMultiProxyServerMessage("ClearVote", player, uuid); + getMultiProxyHandler().sendMultiProxyServerMessage("ClearVote", player, uuid); } } else { if (!cachedOnlineVotes.containsKey(uuid)) { @@ -1488,15 +1520,17 @@ public synchronized void vote(String player, String service, boolean realVote, b if (getConfig().getMultiProxySupport() && getConfig().getPrimaryServer()) { if (!getConfig().getMultiProxyOneGlobalReward()) { debug("Sending global proxy vote message"); - sendMultiProxyServerMessage("Vote", uuid, player, service, "" + votePartyVotes, - "" + currentVotePartyVotesRequired, "" + time, "" + realVote, text.toString()); + getMultiProxyHandler().sendMultiProxyServerMessage("Vote", uuid, player, service, + "" + votePartyVotes, "" + currentVotePartyVotesRequired, "" + time, "" + realVote, + text.toString()); } else { // check if reward should've already been given if (!(isOnline(p) && !config.getBlockedServers() .contains(p.getCurrentServer().get().getServerInfo().getName()))) { debug("Seending global proxy voteonline message"); - sendMultiProxyServerMessage("VoteOnline", uuid, player, service, "" + votePartyVotes, - "" + currentVotePartyVotesRequired, "" + time, "" + realVote, text.toString()); + getMultiProxyHandler().sendMultiProxyServerMessage("VoteOnline", uuid, player, service, + "" + votePartyVotes, "" + currentVotePartyVotesRequired, "" + time, "" + realVote, + text.toString()); } else { debug("Not sending global proxy message for voteonline, player already got reward"); } @@ -1508,17 +1542,6 @@ public synchronized void vote(String player, String service, boolean realVote, b } } - public void multiProxyLogin(Player p) { - if (!config.getMultiProxySupport()) { - return; - } - if (config.getPrimaryServer()) { - return; - } - sendMultiProxyServerMessage("Login", p.getUniqueId().toString(), p.getUsername()); - - } - public boolean isInAvailableServers(String server) { for (RegisteredServer s : getAvailableAllServers()) { if (s.getServerInfo().getName().equalsIgnoreCase(server)) { @@ -1555,12 +1578,6 @@ public boolean isOnline(Player p) { return false; } - public void sendMultiProxyServerMessage(String... messageData) { - for (ClientHandler h : multiproxyClientHandles.values()) { - h.sendMessage(messageData); - } - } - @Getter private int votePartyVotes = 0; @Getter diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocityCommand.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocityCommand.java index 421481b64..6e87392bf 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocityCommand.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocityCommand.java @@ -68,7 +68,7 @@ public void execute(final Invocation invocation) { } } if (args[0].equalsIgnoreCase("multiproxystatus")) { - plugin.sendMultiProxyServerMessage("Status"); + plugin.getMultiProxyHandler().sendMultiProxyServerMessage("Status"); source.sendMessage(Component.text("Sending status message").color(NamedTextColor.AQUA)); }