mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-09-02 19:09:44 +02:00
Switch to HTTPS for Spigot update checking
Should fix the 403 errors
This commit is contained in:
parent
83c2943b48
commit
de8bb2bd66
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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,8 +69,14 @@ public final class SpigotUpdater extends Updater {
|
||||||
result = UpdateResult.NO_UPDATE;
|
result = UpdateResult.NO_UPDATE;
|
||||||
}
|
}
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
if (ProtocolLibrary.getConfiguration().isDebug()) {
|
||||||
ProtocolLibrary.getErrorReporter().reportDetailed(
|
ProtocolLibrary.getErrorReporter().reportDetailed(
|
||||||
SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this));
|
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 {
|
} finally {
|
||||||
// Invoke the listeners on the main thread
|
// Invoke the listeners on the main thread
|
||||||
for (Runnable listener : listeners) {
|
for (Runnable listener : listeners) {
|
||||||
|
@ -81,23 +86,28 @@ public final class SpigotUpdater extends Updater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
Closer closer = Closer.create();
|
||||||
|
|
||||||
|
try {
|
||||||
HttpURLConnection con = (HttpURLConnection) new URL(API_URL).openConnection();
|
HttpURLConnection con = (HttpURLConnection) new URL(API_URL).openConnection();
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
con.setRequestMethod(ACTION);
|
con.setRequestMethod(ACTION);
|
||||||
con.getOutputStream().write(API_KEY);
|
con.getOutputStream().write(API_KEY);
|
||||||
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
|
||||||
if (version.length() <= 7) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
InputStreamReader isr = closer.register(new InputStreamReader(con.getInputStream()));
|
||||||
|
BufferedReader br = closer.register(new BufferedReader(isr));
|
||||||
|
return br.readLine();
|
||||||
|
} finally {
|
||||||
|
closer.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user