Remove auto updater
- Removed the auto updater because Spiget is too unreliable these days.
This commit is contained in:
parent
2f57f0df59
commit
bd57ea0728
@ -82,7 +82,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
updateManager = new UpdateManager(this, 47136);
|
||||
|
||||
// Check if the user allows checking for updates.
|
||||
updateManager.setEnabled(config.checkForUpdates(), config.autoDLUpdate());
|
||||
updateManager.setEnabled(config.checkForUpdates());
|
||||
|
||||
if (config.allowStats())
|
||||
{
|
||||
|
@ -24,7 +24,6 @@ public class ConfigLoader
|
||||
private int IRON_TO_FULL;
|
||||
private boolean uninstallMode;
|
||||
private boolean checkForUpdates;
|
||||
private boolean autoDLUpdate;
|
||||
private int LEATHER_TO_FULL;
|
||||
private int DIAMONDS_TO_FULL;
|
||||
private int NETHERITE_TO_FULL;
|
||||
@ -75,12 +74,7 @@ public class ConfigLoader
|
||||
};
|
||||
String[] updateComment =
|
||||
{
|
||||
"Allow this plugin to check for updates on startup. It will not download new versions unless \"auto-update is enabled\'!"
|
||||
};
|
||||
String[] autoDLUpdateComment =
|
||||
{
|
||||
"Allow this plugin to automatically download new updates. They will be applied on restart.",
|
||||
"This option has no effect if \"checkForUpdates\" is disabled."
|
||||
"Allow this plugin to check for updates on startup. It will not download new versions on its own!"
|
||||
};
|
||||
String[] bStatsComment =
|
||||
{
|
||||
@ -144,7 +138,6 @@ public class ConfigLoader
|
||||
allowMultipleProtectionEnchantments = addNewConfigOption(config, "allowMultipleProtectionEnchantments", false,
|
||||
allowMultipleProtectionEnchantmentsComment);
|
||||
checkForUpdates = addNewConfigOption(config, "checkForUpdates", true, updateComment);
|
||||
autoDLUpdate = addNewConfigOption(config, "auto-update", true, autoDLUpdateComment);
|
||||
allowStats = addNewConfigOption(config, "allowStats", true, bStatsComment);
|
||||
enableDebug = addNewConfigOption(config, "enableDebug", false, debugComment);
|
||||
uninstallMode = addNewConfigOption(config, "uninstallMode", false, uninstallComment);
|
||||
@ -271,11 +264,6 @@ public class ConfigLoader
|
||||
return checkForUpdates;
|
||||
}
|
||||
|
||||
public boolean autoDLUpdate()
|
||||
{
|
||||
return autoDLUpdate;
|
||||
}
|
||||
|
||||
public boolean noFlightDurability()
|
||||
{
|
||||
return noFlightDurability;
|
||||
|
@ -7,13 +7,8 @@ import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
@ -63,7 +58,6 @@ public final class UpdateChecker
|
||||
private static final String USER_AGENT = "ArmoredElytra-update-checker";
|
||||
private static final String UPDATE_URL = "https://api.spiget.org/v2/resources/%d/versions?size=1&sort=-releaseDate";
|
||||
private static final Pattern DECIMAL_SCHEME_PATTERN = Pattern.compile("\\d+(?:\\.\\d+)*");
|
||||
private final String downloadURL;
|
||||
|
||||
private static UpdateChecker instance;
|
||||
|
||||
@ -78,7 +72,6 @@ public final class UpdateChecker
|
||||
this.plugin = plugin;
|
||||
this.pluginID = pluginID;
|
||||
this.versionScheme = versionScheme;
|
||||
downloadURL = "https://api.spiget.org/v2/resources/" + pluginID + "/download";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +85,7 @@ public final class UpdateChecker
|
||||
return CompletableFuture.supplyAsync(
|
||||
() ->
|
||||
{
|
||||
int responseCode = -1;
|
||||
int responseCode;
|
||||
try
|
||||
{
|
||||
URL url = new URL(String.format(UPDATE_URL, pluginID));
|
||||
@ -181,89 +174,6 @@ public final class UpdateChecker
|
||||
return matcher.group().split("\\.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the url to download the latest version from.
|
||||
*
|
||||
* @return The url to download the latest version from.
|
||||
*/
|
||||
public String getDownloadUrl()
|
||||
{
|
||||
return downloadURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the latest update.
|
||||
*
|
||||
* @return True if the download was successful.
|
||||
*/
|
||||
public boolean downloadUpdate()
|
||||
{
|
||||
boolean downloadSuccessfull = false;
|
||||
try
|
||||
{
|
||||
File updateFolder = Bukkit.getUpdateFolderFile();
|
||||
if (!updateFolder.exists())
|
||||
if (!updateFolder.mkdirs())
|
||||
throw new RuntimeException("Failed to create update folder!");
|
||||
|
||||
String fileName = plugin.getName() + ".jar";
|
||||
File updateFile = new File(updateFolder + "/" + fileName);
|
||||
|
||||
// Follow any and all redirects until we've finally found the actual file.
|
||||
String location = downloadURL;
|
||||
HttpURLConnection httpConnection = null;
|
||||
for (; ; )
|
||||
{
|
||||
URL url = new URL(location);
|
||||
httpConnection = (HttpURLConnection) url.openConnection();
|
||||
httpConnection.setInstanceFollowRedirects(false);
|
||||
httpConnection.setRequestProperty("User-Agent", "ArmoredElytraUpdater");
|
||||
String redirectLocation = httpConnection.getHeaderField("Location");
|
||||
if (redirectLocation == null)
|
||||
break;
|
||||
location = redirectLocation;
|
||||
httpConnection.disconnect();
|
||||
}
|
||||
|
||||
if (httpConnection == null)
|
||||
{
|
||||
plugin.myLogger(Level.WARNING, "Failed to construct connection: " + location);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (httpConnection.getResponseCode() != 200)
|
||||
{
|
||||
plugin.myLogger(Level.WARNING,
|
||||
Util.exceptionToString(new RuntimeException("Download returned status #"
|
||||
+ httpConnection
|
||||
.getResponseCode() + "\n for URL: " + downloadURL)));
|
||||
return false;
|
||||
}
|
||||
|
||||
int grabSize = 4096;
|
||||
BufferedInputStream in = new BufferedInputStream(httpConnection.getInputStream());
|
||||
FileOutputStream fos = new FileOutputStream(updateFile);
|
||||
BufferedOutputStream bout = new BufferedOutputStream(fos, grabSize);
|
||||
|
||||
byte[] data = new byte[grabSize];
|
||||
int grab;
|
||||
while ((grab = in.read(data, 0, grabSize)) >= 0)
|
||||
bout.write(data, 0, grab);
|
||||
|
||||
bout.flush();
|
||||
bout.close();
|
||||
in.close();
|
||||
fos.flush();
|
||||
fos.close();
|
||||
downloadSuccessfull = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return downloadSuccessfull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this update checker with the specified values and return its instance. If an instance of
|
||||
* UpdateChecker has already been initialized, this method will act similarly to {@link #get()} (which is
|
||||
@ -327,7 +237,7 @@ public final class UpdateChecker
|
||||
* A functional interface to compare two version Strings with similar version schemes.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public static interface VersionScheme
|
||||
public interface VersionScheme
|
||||
{
|
||||
|
||||
/**
|
||||
@ -338,14 +248,14 @@ public final class UpdateChecker
|
||||
* @param second the second version to check
|
||||
* @return the greater of the two versions. null if unsupported version schemes
|
||||
*/
|
||||
public String compareVersions(String first, String second);
|
||||
String compareVersions(String first, String second);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A constant reason for the result of {@link UpdateResult}.
|
||||
*/
|
||||
public static enum UpdateReason
|
||||
public enum UpdateReason
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -13,10 +13,8 @@ public final class UpdateManager
|
||||
{
|
||||
private final ArmoredElytra plugin;
|
||||
private boolean checkForUpdates = false;
|
||||
private boolean downloadUpdates = false;
|
||||
private boolean updateDownloaded = false;
|
||||
|
||||
private UpdateChecker updater;
|
||||
private final UpdateChecker updater;
|
||||
private BukkitTask updateRunner = null;
|
||||
|
||||
public UpdateManager(final ArmoredElytra plugin, final int pluginID)
|
||||
@ -25,18 +23,12 @@ public final class UpdateManager
|
||||
updater = UpdateChecker.init(plugin, pluginID);
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean newCheckForUpdates, final boolean newDownloadUpdates)
|
||||
public void setEnabled(final boolean newCheckForUpdates)
|
||||
{
|
||||
checkForUpdates = newCheckForUpdates;
|
||||
downloadUpdates = newDownloadUpdates;
|
||||
initUpdater();
|
||||
}
|
||||
|
||||
public boolean hasUpdateBeenDownloaded()
|
||||
{
|
||||
return updateDownloaded;
|
||||
}
|
||||
|
||||
public String getNewestVersion()
|
||||
{
|
||||
if (!checkForUpdates || updater.getLastResult() == null)
|
||||
@ -62,19 +54,6 @@ public final class UpdateManager
|
||||
if (updateAvailable)
|
||||
plugin.myLogger(Level.INFO,
|
||||
"A new update is available: " + plugin.getUpdateManager().getNewestVersion());
|
||||
|
||||
if (downloadUpdates && updateAvailable)
|
||||
{
|
||||
updateDownloaded = updater.downloadUpdate();
|
||||
if (updateDownloaded)
|
||||
plugin.myLogger(Level.INFO, "Update downloaded! Restart to apply it! " +
|
||||
"New version is " + updater.getLastResult().getNewestVersion() +
|
||||
", Currently running " + plugin.getDescription().getVersion());
|
||||
else
|
||||
plugin.myLogger(Level.INFO,
|
||||
"Failed to download latest version! You can download it manually at: " +
|
||||
updater.getDownloadUrl());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -91,7 +70,7 @@ public final class UpdateManager
|
||||
{
|
||||
checkForUpdates();
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 288000L); // Run immediately, then every 4 hours.
|
||||
}.runTaskTimer(plugin, 0L, 864000L); // Run immediately, then every 12 hours.
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user