mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-17 03:51:27 +01:00
init
This commit is contained in:
parent
834cecd872
commit
a3310b56e3
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
target/
|
||||
.idea/
|
||||
songodaUpdater.iml
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
|
34
pom.xml
Normal file
34
pom.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaUpdater</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>SongodaUpdater-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>private</id>
|
||||
<url>http://repo.songoda.com/artifactory/private/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14-pre5-2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
7
src/main/java/com/songoda/update/Module.java
Normal file
7
src/main/java/com/songoda/update/Module.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.songoda.update;
|
||||
|
||||
public interface Module {
|
||||
|
||||
void run(Plugin plugin);
|
||||
|
||||
}
|
63
src/main/java/com/songoda/update/Plugin.java
Normal file
63
src/main/java/com/songoda/update/Plugin.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.songoda.update;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Plugin {
|
||||
|
||||
private JavaPlugin javaPlugin;
|
||||
private int songodaId;
|
||||
private List<Module> modules = new ArrayList<>();
|
||||
private String latestVersion;
|
||||
private String notification;
|
||||
private JSONObject json;
|
||||
|
||||
public Plugin(JavaPlugin javaPlugin, int songodaId) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
this.songodaId = songodaId;
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
public void setLatestVersion(String latestVersion) {
|
||||
this.latestVersion = latestVersion;
|
||||
}
|
||||
|
||||
public String getNotification() {
|
||||
return notification;
|
||||
}
|
||||
|
||||
public void setNotification(String notification) {
|
||||
this.notification = notification;
|
||||
}
|
||||
|
||||
public JSONObject getJson() {
|
||||
return json;
|
||||
}
|
||||
|
||||
public void setJson(JSONObject json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public Module addModule(Module module) {
|
||||
modules.add(module);
|
||||
return module;
|
||||
}
|
||||
|
||||
public List<Module> getModules() {
|
||||
return new ArrayList<>(modules);
|
||||
}
|
||||
|
||||
public JavaPlugin getJavaPlugin() {
|
||||
return javaPlugin;
|
||||
}
|
||||
|
||||
public int getSongodaId() {
|
||||
return songodaId;
|
||||
}
|
||||
}
|
80
src/main/java/com/songoda/update/SongodaUpdate.java
Normal file
80
src/main/java/com/songoda/update/SongodaUpdate.java
Normal file
@ -0,0 +1,80 @@
|
||||
package com.songoda.update;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SongodaUpdate {
|
||||
|
||||
private static int version = 1;
|
||||
|
||||
private static List<Plugin> registeredPlugins = new ArrayList<>();
|
||||
|
||||
private static SongodaUpdate INSTANCE;
|
||||
|
||||
public SongodaUpdate() {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(registeredPlugins.get(0).getJavaPlugin(), this::update, 20L);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
for (Plugin plugin : registeredPlugins) {
|
||||
try {
|
||||
JavaPlugin javaPlugin = plugin.getJavaPlugin();
|
||||
System.out.println("Establishing connection with the Songoda update server.");
|
||||
URL url = new URL("http://update.songoda.com/index.php?plugin=" + javaPlugin.getName() +
|
||||
"&version=" + javaPlugin.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);
|
||||
|
||||
plugin.setLatestVersion((String) json.get("latestVersion"));
|
||||
plugin.setNotification((String) json.get("notification"));
|
||||
|
||||
plugin.setJson(json);
|
||||
|
||||
for (Module module : plugin.getModules()) {
|
||||
module.run(plugin);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Connection failed...");
|
||||
e.printStackTrace(); //ToDo: This cannot be here in final.
|
||||
} catch (ParseException e) {
|
||||
System.out.println("Failed to parse json.");
|
||||
e.printStackTrace(); //ToDo: This cannot be here in final.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void load(Plugin plugin) {
|
||||
registeredPlugins.add(plugin);
|
||||
System.out.println("Hooked " + plugin.getJavaPlugin().getName() + ".");
|
||||
if (INSTANCE == null) INSTANCE = new SongodaUpdate();
|
||||
}
|
||||
|
||||
public static int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static SongodaUpdate getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user