diff --git a/VotingPlugin/Resources/Config.yml b/VotingPlugin/Resources/Config.yml index cac2c753c..5f4812a19 100644 --- a/VotingPlugin/Resources/Config.yml +++ b/VotingPlugin/Resources/Config.yml @@ -517,6 +517,12 @@ QueueVotesDuringTimeChange: false # Most cases this will work all the time AutoCreateVoteSites: true +# Experiemtental feature +# Uses https://github.com/BenCodez/VotingPlugin/wiki/Minecraft-Server-Lists +# Not all voting sites use the domain name as the service sites +# This feature is an attempt to ease setup for new users by matching domain name to actual service site +AdvancedServiceSiteHandling: false + # Set this to false to disable the plugin adding totals # Not really recommended AddTotals: true diff --git a/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java b/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java index ed753190f..d9b810c56 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java @@ -82,6 +82,7 @@ import com.bencodez.votingplugin.placeholders.MVdWPlaceholders; import com.bencodez.votingplugin.placeholders.PlaceHolders; import com.bencodez.votingplugin.placeholders.VotingPluginExpansion; +import com.bencodez.votingplugin.servicesites.ServiceSiteHandler; import com.bencodez.votingplugin.signs.Signs; import com.bencodez.votingplugin.specialrewards.SpecialRewards; import com.bencodez.votingplugin.test.VoteTester; @@ -354,26 +355,29 @@ public ArrayList getVoteSitesEnabled() { public String getVoteSiteName(boolean checkEnabled, String... urls) { ArrayList sites = getConfigVoteSites().getVoteSitesNames(checkEnabled); + for (String url : urls) { if (url == null) { return null; } - if (sites != null) { - for (String siteName : sites) { - String URL = getConfigVoteSites().getServiceSite(siteName); - if (URL != null) { - if (URL.equalsIgnoreCase(url)) { + if (!url.isEmpty()) { + if (sites != null) { + for (String siteName : sites) { + String URL = getConfigVoteSites().getServiceSite(siteName); + if (URL != null) { + if (URL.equalsIgnoreCase(url)) { + return siteName; + } + } + if (siteName.equalsIgnoreCase(url)) { return siteName; } - } - if (siteName.equalsIgnoreCase(url)) { - return siteName; - } + } } } - return url; } + for (String url : urls) { return url; } @@ -1241,10 +1245,21 @@ public void run() { "Detected an issue with voting sites, check the server startup log for more details: https://github.com/BenCodez/VotingPlugin/wiki/Votifier-Troubleshooting"); } }, 5); + + plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { + + @Override + public void run() { + serviceSiteHandler = new ServiceSiteHandler(plugin); + } + }, 10); } } + @Getter + private ServiceSiteHandler serviceSiteHandler; + /* * (non-Javadoc) * diff --git a/VotingPlugin/src/com/bencodez/votingplugin/config/Config.java b/VotingPlugin/src/com/bencodez/votingplugin/config/Config.java index 13268fa4b..3318fcfd7 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/config/Config.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/config/Config.java @@ -47,6 +47,10 @@ public class Config extends YMLFile { @Getter private boolean queueVotesDuringTimeChange = false; + @ConfigDataBoolean(path = "AdvancedServiceSiteHandling") + @Getter + private boolean advancedServiceSiteHandling = false; + @ConfigDataBoolean(path = "AllowUnjoined") @Getter private boolean allowUnjoined = false; diff --git a/VotingPlugin/src/com/bencodez/votingplugin/listeners/VotiferEvent.java b/VotingPlugin/src/com/bencodez/votingplugin/listeners/VotiferEvent.java index b841f9119..106490bb7 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/listeners/VotiferEvent.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/listeners/VotiferEvent.java @@ -77,7 +77,14 @@ public void run() { "Ignoring vote from votifier since pluginmessaging or socket bungee method is enabled, this means you aren't setup correctly for those methods, please check: https://github.com/BenCodez/VotingPlugin/wiki/Bungeecord-Setups"); return; } - String voteSiteNameStr = plugin.getVoteSiteName(false, voteSite); + String matchSite = ""; + if (plugin.getConfigFile().isAdvancedServiceSiteHandling()) { + if (plugin.getServiceSiteHandler() != null) { + matchSite = plugin.getServiceSiteHandler().match(voteSite); + } + } + + String voteSiteNameStr = plugin.getVoteSiteName(false, voteSite, matchSite); ArrayList sites = plugin.getConfigVoteSites().getVoteSitesNames(false); boolean createSite = false; @@ -89,6 +96,8 @@ public void run() { createSite = true; } + String serviceSite = voteSite; + if (plugin.getConfigFile().isAutoCreateVoteSites() && createSite) { plugin.getLogger().warning("VoteSite with service site '" + voteSiteNameStr + "' does not exist, attempting to generate..."); @@ -107,7 +116,7 @@ public void run() { return; } - String voteSiteName = plugin.getVoteSiteName(true, voteSite); + String voteSiteName = plugin.getVoteSiteName(true, serviceSite, matchSite); PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(voteSiteName, true), voteUsername, voteSite, true); diff --git a/VotingPlugin/src/com/bencodez/votingplugin/servicesites/ServiceSiteHandler.java b/VotingPlugin/src/com/bencodez/votingplugin/servicesites/ServiceSiteHandler.java new file mode 100644 index 000000000..60724cc2d --- /dev/null +++ b/VotingPlugin/src/com/bencodez/votingplugin/servicesites/ServiceSiteHandler.java @@ -0,0 +1,74 @@ +package com.bencodez.votingplugin.servicesites; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map.Entry; + +import com.bencodez.votingplugin.VotingPluginMain; + +import lombok.Getter; + +public class ServiceSiteHandler { + @Getter + private HashMap serviceSites = new HashMap(); + + public String match(String service) { + for (Entry entry : serviceSites.entrySet()) { + if (entry.getValue().equalsIgnoreCase(service)) { + return entry.getKey(); + } + } + return service; + } + + public ServiceSiteHandler(VotingPluginMain plugin) { + loadFromGithub(); + for (Entry entry : serviceSites.entrySet()) { + plugin.getLogger().info(entry.getKey() + " - " + entry.getValue()); + } + } + + public void readFromWeb(String webURL) throws IOException { + serviceSites.clear(); + URL url = new URL(webURL); + InputStream is = url.openStream(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { + String line; + boolean rawFound = false; + while ((line = br.readLine()) != null) { + if (line.contains("
    ")) { + rawFound = true; + } else if (!line.contains(" - ")) { + rawFound = false; + } else if (rawFound) { + String data = line.replaceAll("
  • ", "").replaceAll("
  • ", ""); + String[] split = data.split(" - "); + if (split.length > 0) { + serviceSites.put(split[0], split[1]); + } + + } + } + } catch (MalformedURLException e) { + e.printStackTrace(); + throw new MalformedURLException("URL is malformed!!"); + } catch (IOException e) { + e.printStackTrace(); + throw new IOException(); + } + + } + + public void loadFromGithub() { + try { + readFromWeb("https://github.com/BenCodez/VotingPlugin/wiki/Minecraft-Server-Lists"); + } catch (IOException e) { + e.printStackTrace(); + } + } +}