mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-11-05 18:39:49 +01:00
Added Songoda Updater.
This commit is contained in:
parent
bb257a9b44
commit
24e544d471
@ -17,6 +17,11 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>songodaupdater</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming-API</artifactId>
|
||||
@ -168,27 +173,37 @@
|
||||
<finalName>EpicFarming-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||
<artifactId>replacer</artifactId>
|
||||
<version>1.5.3</version>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>prepare-package</phase>
|
||||
<id>shaded</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>replace</goal>
|
||||
<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>
|
||||
<configuration>
|
||||
<file>${project.build.directory}/classes/plugin.yml</file>
|
||||
<file>${project.basedir}/../.gitlab-ci.yml</file>
|
||||
<replacements>
|
||||
<replacement>
|
||||
<token>maven-version-number</token>
|
||||
<value>${project.version}</value>
|
||||
</replacement>
|
||||
</replacements>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user