Added updater.

This commit is contained in:
Brianna 2019-04-29 16:21:52 -04:00
parent e2511d69d8
commit 2705c78753
3 changed files with 78 additions and 32 deletions

View File

@ -15,6 +15,9 @@ import com.songoda.epicbuckets.utils.Debugger;
import com.songoda.epicbuckets.utils.ServerVersion;
import com.songoda.epicbuckets.utils.hooks.ClaimableProtectionPluginHook;
import com.songoda.epicbuckets.utils.hooks.ProtectionPluginHook;
import com.songoda.epicbuckets.utils.updateModules.LocaleModule;
import com.songoda.update.Plugin;
import com.songoda.update.SongodaUpdate;
import net.milkbowl.vault.economy.Economy;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit;
@ -75,7 +78,10 @@ public class EpicBuckets extends JavaPlugin {
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(getConfig().getString("Locale", "en_US"));
this.update();
//Running Songoda Updater
Plugin plugin = new Plugin(this, 27);
plugin.addModule(new LocaleModule());
SongodaUpdate.load(plugin);
this.references = new References();
@ -137,36 +143,6 @@ public class EpicBuckets extends JavaPlugin {
this.getShopManager().reload();
}
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];
StringBuilder sb = new StringBuilder();
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;
if ("locale".equals(file.get("type"))) {
InputStream in = new URL((String) file.get("link")).openStream();
Locale.saveDefaultLocale(in, (String) file.get("name"));
}
}
} catch (Exception e) {
Bukkit.getLogger().warning("Failed to update.");
}
}
private ProtectionPluginHook register(Supplier<ProtectionPluginHook> hookSupplier) {
return this.registerProtectionHook(hookSupplier.get());
}

View File

@ -0,0 +1,32 @@
package com.songoda.epicbuckets.utils.updateModules;
import com.songoda.epicbuckets.EpicBuckets;
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();
EpicBuckets.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name"));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

40
pom.xml
View File

@ -16,9 +16,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.14-pre5-2</version>
<version>1.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>songodaupdater</artifactId>
<version>1</version>
</dependency>
</dependencies>
<build>
@ -33,6 +38,39 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>shaded</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>com.songoda:songodaupdater</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>