From 24e544d471253c6ba5862cedb5e6f837db5c38c1 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 27 Apr 2019 19:38:46 -0400 Subject: [PATCH] Added Songoda Updater. --- EpicFarming-Plugin/pom.xml | 45 ++++++++++++------- .../epicfarming/EpicFarmingPlugin.java | 43 +++--------------- .../epicfarming/utils/SettingsManager.java | 1 - .../utils/updateModules/LocaleModule.java | 32 +++++++++++++ 4 files changed, 69 insertions(+), 52 deletions(-) create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/updateModules/LocaleModule.java diff --git a/EpicFarming-Plugin/pom.xml b/EpicFarming-Plugin/pom.xml index a52c426..84b1196 100644 --- a/EpicFarming-Plugin/pom.xml +++ b/EpicFarming-Plugin/pom.xml @@ -17,6 +17,11 @@ + + com.songoda + songodaupdater + 1 + com.songoda EpicFarming-API @@ -168,27 +173,37 @@ EpicFarming-${project.version} - com.google.code.maven-replacer-plugin - replacer - 1.5.3 + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 - prepare-package + shaded + package - replace + shade + + false + false + + + com.songoda:songodaupdater + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + - - ${project.build.directory}/classes/plugin.yml - ${project.basedir}/../.gitlab-ci.yml - - - maven-version-number - ${project.version} - - - org.apache.maven.plugins diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java index a7fdbad..b5306d0 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java @@ -23,6 +23,9 @@ import com.songoda.epicfarming.tasks.FarmTask; import com.songoda.epicfarming.tasks.GrowthTask; import com.songoda.epicfarming.tasks.HopperTask; import com.songoda.epicfarming.utils.*; +import com.songoda.epicfarming.utils.updateModules.LocaleModule; +import com.songoda.update.Plugin; +import com.songoda.update.SongodaUpdate; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -112,9 +115,10 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { Locale.saveDefaultLocale("en_US"); this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode)); - if (getConfig().getBoolean("System.Download Needed Data Files")) { - this.update(); - } + //Running Songoda Updater + Plugin plugin = new Plugin(this, 21); + plugin.addModule(new LocaleModule()); + SongodaUpdate.load(plugin); dataFile.createNewFile("Loading Data File", "EpicFarming Data File"); this.loadDataFile(); @@ -240,39 +244,6 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { storage.doSave(); } - private void update() { - try { - URL url = new URL("http://update.songoda.com/index.php?plugin=" + getDescription().getName() + "&version=" + getDescription().getVersion()); - URLConnection urlConnection = url.openConnection(); - InputStream is = urlConnection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - - int numCharsRead; - char[] charArray = new char[1024]; - StringBuffer sb = new StringBuffer(); - while ((numCharsRead = isr.read(charArray)) > 0) { - sb.append(charArray, 0, numCharsRead); - } - String jsonString = sb.toString(); - JSONObject json = (JSONObject) new JSONParser().parse(jsonString); - - JSONArray files = (JSONArray) json.get("neededFiles"); - for (Object o : files) { - JSONObject file = (JSONObject) o; - - switch ((String)file.get("type")) { - case "locale": - InputStream in = new URL((String) file.get("link")).openStream(); - Locale.saveDefaultLocale(in, (String) file.get("name")); - break; - } - } - } catch (Exception e) { - System.out.println("Failed to update."); - //e.printStackTrace(); - } - } - public void reload() { locale.reloadMessages(); references = new References(); diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java index e909c14..7a4c1b2 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java @@ -197,7 +197,6 @@ public class SettingsManager implements Listener { o15("Interfaces.Glass Type 2", 11), o16("Interfaces.Glass Type 3", 3), - DOWNLOAD_FILES("System.Download Needed Data Files", true), LANGUGE_MODE("System.Language Mode", "en_US"), o17("System.Debugger Enabled", false); diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/updateModules/LocaleModule.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/updateModules/LocaleModule.java new file mode 100644 index 0000000..dae8202 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/updateModules/LocaleModule.java @@ -0,0 +1,32 @@ +package com.songoda.epicfarming.utils.updateModules; + +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.update.Module; +import com.songoda.update.Plugin; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public class LocaleModule implements Module { + + @Override + public void run(Plugin plugin) { + JSONObject json = plugin.getJson(); + try { + JSONArray files = (JSONArray) json.get("neededFiles"); + for (Object o : files) { + JSONObject file = (JSONObject) o; + + if (file.get("type").equals("locale")) { + InputStream in = new URL((String) file.get("link")).openStream(); + EpicFarmingPlugin.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name")); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } +}