Add untested update system, add delay config option for tablist
This commit is contained in:
@@ -2,8 +2,12 @@ package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -21,11 +25,92 @@ public class UpdateChecker {
|
||||
@Getter
|
||||
private int latestSnapshot;
|
||||
private final long started = System.currentTimeMillis();
|
||||
private int lastDownload;
|
||||
|
||||
public UpdateChecker(String resourceID) {
|
||||
this.resourceID = resourceID;
|
||||
}
|
||||
|
||||
public boolean grabSnapshotBuild() {
|
||||
if (getLatestSnapshot() == 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
if (lastDownload == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getLatestSnapshot() == lastDownload) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return grabSnapshotBuild(getLatestSnapshot());
|
||||
}
|
||||
|
||||
public boolean grabSnapshotBuild(int buildNo) {
|
||||
boolean result = grabSnapshotBuild(
|
||||
"https://ci.md-5.net/job/LibsDisguises/" + buildNo + "/artifact/target/LibsDisguises.jar");
|
||||
|
||||
if (result) {
|
||||
lastDownload = buildNo;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean grabLatestSnapshot() {
|
||||
boolean result = grabSnapshotBuild(
|
||||
"https://ci.md-5.net/job/LibsDisguises/lastSuccessfulBuild/artifact/target/LibsDisguises.jar");
|
||||
|
||||
if (result) {
|
||||
lastDownload = LibsDisguises.getInstance().getBuildNumber();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isDownloading() {
|
||||
return lastDownload == -1;
|
||||
}
|
||||
|
||||
public int getLastDownload() {
|
||||
return lastDownload;
|
||||
}
|
||||
|
||||
public boolean grabSnapshotBuild(String urlString) {
|
||||
DisguiseUtilities.getLogger().info("Now downloading latest build of Lib's Disguises from " + urlString);
|
||||
lastDownload = -1;
|
||||
|
||||
File dest = new File(Bukkit.getUpdateFolderFile(), "LibsDisguises.jar");
|
||||
|
||||
if (!dest.exists()) {
|
||||
dest.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
// We're connecting to spigot's API
|
||||
URL url = new URL(urlString);
|
||||
// Creating a connection
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
|
||||
// Get the input stream, what we receive
|
||||
try (InputStream input = con.getInputStream()) {
|
||||
FileUtils.copyInputStreamToFile(input, dest);
|
||||
}
|
||||
|
||||
DisguiseUtilities.getLogger().info("Download success!");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Failed, set the last download back to previous build
|
||||
dest.delete();
|
||||
DisguiseUtilities.getLogger().warning("Failed to download snapshot build.");
|
||||
lastDownload = 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkSnapshotUpdate(int buildNumber) {
|
||||
Map<String, Object> lastBuild = fetchLastSnapshotBuild();
|
||||
|
||||
|
@@ -181,7 +181,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
|
||||
if (LibsPremium.getPaidInformation() == null ||
|
||||
LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
|
||||
packets.addDelayedPacket(deleteTab, 2);
|
||||
packets.addDelayedPacket(deleteTab, DisguiseConfig.getTablistRemoveDelay());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -137,6 +137,11 @@ public enum LibsMsg {
|
||||
NO_MODS(ChatColor.RED + "%s is not using any mods!"),
|
||||
MODS_LIST(ChatColor.DARK_GREEN + "%s has the mods:" + ChatColor.AQUA + " %s"),
|
||||
NO_PERM(ChatColor.RED + "You are forbidden to use this command."),
|
||||
UPDATE_NOT_READY(ChatColor.RED + "Lib's Disguises doesn't know what's the latest update!"),
|
||||
UPDATE_ON_LATEST(ChatColor.RED + "You are already on the latest version of LibsDisguises!"),
|
||||
UPDATE_FAILED(ChatColor.RED + "LibsDisguises update failed! Check console for errors."),
|
||||
UPDATE_SUCCESS(ChatColor.DARK_GREEN + "LibsDisguises update success! Restart server to update!"),
|
||||
UPDATE_IN_PROGRESS(ChatColor.DARK_GREEN + "LibsDisguises is now downloading an update..."),
|
||||
NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"),
|
||||
NO_MODS_LISTENING(ChatColor.RED + "This server is not listening for mods!"),
|
||||
NO_PERMS_USE_OPTIONS(ChatColor.RED +
|
||||
|
Reference in New Issue
Block a user