Archiviert
13
0

Switch to HTTPS for Spigot update checking

Should fix the 403 errors
Dieser Commit ist enthalten in:
Dan Mulloy 2016-01-29 23:28:10 -05:00
Ursprung 83c2943b48
Commit de8bb2bd66
4 geänderte Dateien mit 43 neuen und 31 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -22,7 +22,6 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; 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 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 * @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); super(plugin, type, announce);
this.file = file; this.file = file;

Datei anzeigen

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

Datei anzeigen

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