Switch to HTTPS for Spigot update checking

Should fix the 403 errors
This commit is contained in:
Dan Mulloy 2016-01-29 23:28:10 -05:00
parent 83c2943b48
commit de8bb2bd66
4 changed files with 43 additions and 31 deletions

View File

@ -754,4 +754,8 @@ public class ProtocolLibrary extends JavaPlugin {
public static Logger getStaticLogger() {
return logger;
}
public static void disableUpdates() {
UPDATES_DISABLED = true;
}
}

View File

@ -22,7 +22,6 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
@ -79,7 +78,7 @@ public class BukkitUpdater extends Updater {
* @param type Specify the type of update this will be. See {@link UpdateType}
* @param announce True if the program should announce the progress of new updates in console
*/
public BukkitUpdater(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
public BukkitUpdater(ProtocolLibrary plugin, int id, File file, UpdateType type, boolean announce) {
super(plugin, type, announce);
this.file = file;

View File

@ -21,23 +21,22 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.bukkit.plugin.Plugin;
import java.util.logging.Level;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.utility.Closer;
import com.google.common.base.Charsets;
/**
* Adapted version of the Bukkit updater for use with Spigot resources
*
* @author dmulloy2
*/
public final class SpigotUpdater extends Updater {
private String remoteVersion;
public SpigotUpdater(Plugin plugin, UpdateType type, boolean announce) {
public SpigotUpdater(ProtocolLibrary plugin, UpdateType type, boolean announce) {
super(plugin, type, announce);
}
@ -70,34 +69,45 @@ public final class SpigotUpdater extends Updater {
result = UpdateResult.NO_UPDATE;
}
} catch (Throwable ex) {
ProtocolLibrary.getErrorReporter().reportDetailed(
SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this));
} finally {
// Invoke the listeners on the main thread
for (Runnable listener : listeners) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener);
}
}
if (ProtocolLibrary.getConfiguration().isDebug()) {
ProtocolLibrary.getErrorReporter().reportDetailed(
SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this));
} else {
plugin.getLogger().log(Level.WARNING, "Failed to check for updates: " + ex);
}
ProtocolLibrary.disableUpdates();
} finally {
// Invoke the listeners on the main thread
for (Runnable listener : listeners) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener);
}
}
}
}
private static final String RESOURCE_URL = "https://www.spigotmc.org/resources/protocollib.1997/";
private static final String API_URL = "http://www.spigotmc.org/api/general.php";
private static final String PROTOCOL = "https://";
private static final String RESOURCE_URL = PROTOCOL + "www.spigotmc.org/resources/protocollib.1997/";
private static final String API_URL = PROTOCOL + "www.spigotmc.org/api/general.php";
private static final String ACTION = "POST";
private static final int ID = 1997;
private static final byte[] API_KEY = ("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=" + ID).getBytes(Charsets.UTF_8);
private String getSpigotVersion() throws IOException {
HttpURLConnection con = (HttpURLConnection) new URL(API_URL).openConnection();
con.setDoOutput(true);
con.setRequestMethod(ACTION);
con.getOutputStream().write(API_KEY);
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 7) {
return version;
}
public String getSpigotVersion() throws IOException {
Closer closer = Closer.create();
return null;
try {
HttpURLConnection con = (HttpURLConnection) new URL(API_URL).openConnection();
con.setDoOutput(true);
con.setRequestMethod(ACTION);
con.getOutputStream().write(API_KEY);
InputStreamReader isr = closer.register(new InputStreamReader(con.getInputStream()));
BufferedReader br = closer.register(new BufferedReader(isr));
return br.readLine();
} finally {
closer.close();
}
}
}

View File

@ -20,8 +20,7 @@ import java.io.File;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.error.ReportType;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.utility.Util;
@ -32,7 +31,7 @@ import com.google.common.base.Preconditions;
*/
public abstract class Updater {
protected Plugin plugin;
protected ProtocolLibrary plugin;
protected String versionName;
protected String versionLink;
@ -49,7 +48,7 @@ public abstract class Updater {
public static final ReportType REPORT_CANNOT_UPDATE_PLUGIN = new ReportType("Cannot update ProtocolLib.");
protected Updater(Plugin plugin, UpdateType type, boolean announce) {
protected Updater(ProtocolLibrary plugin, UpdateType type, boolean announce) {
this.plugin = plugin;
this.type = type;
this.announce = announce;
@ -266,7 +265,7 @@ public abstract class Updater {
}
}
public static Updater create(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
public static Updater create(ProtocolLibrary plugin, int id, File file, UpdateType type, boolean announce) {
if (Util.isUsingSpigot()) {
return new SpigotUpdater(plugin, type, announce);
} else {