mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-25 03:55:35 +01:00
auto updater
This commit is contained in:
parent
0df745c399
commit
fd539a9412
@ -350,7 +350,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
|
||||
@Override
|
||||
public String getPlatform() {
|
||||
return Bukkit.getVersion();
|
||||
return "bukkit";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@ import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MemUtil;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.boydti.fawe.util.Updater;
|
||||
import com.boydti.fawe.util.WEManager;
|
||||
import com.boydti.fawe.util.WESubscriber;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
@ -244,6 +245,14 @@ public class Fawe {
|
||||
*/
|
||||
this.setupInjector();
|
||||
this.setupMemoryListener();
|
||||
|
||||
// Update
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Updater.update(implementation.getPlatform(), getVersion());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isJava8 = MainUtil.getJavaVersion() >= 1.8;
|
||||
@ -295,7 +304,7 @@ public class Fawe {
|
||||
scanner.close();
|
||||
this.version = new FaweVersion(versionString);
|
||||
Settings.DATE = new Date(100 + version.year, version.month, version.day).toGMTString();
|
||||
Settings.BUILD = "http://ci.athion.net/job/FastAsyncWorldEdit/" + version.build;
|
||||
Settings.BUILD = "https://ci.athion.net/job/FastAsyncWorldEdit/" + version.build;
|
||||
Settings.COMMIT = "https://github.com/boy0001/FastAsyncWorldedit/commit/" + Integer.toHexString(version.hash);
|
||||
} catch (Throwable ignore) {}
|
||||
Settings.load(file);
|
||||
|
@ -21,4 +21,8 @@ public class FaweVersion {
|
||||
public String toString() {
|
||||
return "FastAsyncWorldEdit-" + year + "." + month + "." + day + "-" + Integer.toHexString(hash) + "-" + build;
|
||||
}
|
||||
|
||||
public boolean isNewer(FaweVersion other) {
|
||||
return other.build < this.build && (this.major > other.major || (this.major == other.major && this.minor > other.minor) || (this.major == other.major && this.minor == other.minor && this.patch > other.patch));
|
||||
}
|
||||
}
|
||||
|
42
core/src/main/java/com/boydti/fawe/util/Updater.java
Normal file
42
core/src/main/java/com/boydti/fawe/util/Updater.java
Normal file
@ -0,0 +1,42 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweVersion;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Updater {
|
||||
public static void update(String platform, FaweVersion currentVersion) {
|
||||
if (currentVersion == null || platform == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String downloadUrl = "http://ci.athion.net/job/FastAsyncWorldEdit/lastSuccessfulBuild/artifact/target/FastAsyncWorldEdit-%platform%-%version%.jar";
|
||||
String versionUrl = "http://empcraft.com/fawe/version.php?%platform%";
|
||||
URL url = new URL(versionUrl.replace("%platform%", platform));
|
||||
try (Scanner reader = new Scanner(url.openStream())) {
|
||||
String versionString = reader.next();
|
||||
FaweVersion version = new FaweVersion(versionString);
|
||||
if (currentVersion == null || version.isNewer(currentVersion)) {
|
||||
URL download = new URL(downloadUrl.replaceAll("%platform%", platform).replaceAll("%version%", versionString));
|
||||
try (ReadableByteChannel rbc = Channels.newChannel(download.openStream())) {
|
||||
File jarFile = MainUtil.getJarFile();
|
||||
File outFile = new File(jarFile.getParent(), "update" + File.separator + jarFile.getName());
|
||||
File outFileParent = outFile.getParentFile();
|
||||
if (!outFileParent.exists()) {
|
||||
outFileParent.mkdirs();
|
||||
}
|
||||
try (FileOutputStream fos = new FileOutputStream(outFile)) {
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
}
|
||||
Fawe.debug("Updated FAWE to " + versionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignore) {}
|
||||
}
|
||||
}
|
@ -125,7 +125,7 @@ public class FaweNukkit implements IFawe, Listener {
|
||||
|
||||
@Override
|
||||
public String getPlatform() {
|
||||
return "Nukkit-" + plugin.getServer().getNukkitVersion();
|
||||
return "nukkit";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user