Skip to content

Commit de8bb2b

Browse files
committed
Switch to HTTPS for Spigot update checking
Should fix the 403 errors
1 parent 83c2943 commit de8bb2b

File tree

4 files changed

+43
-31
lines changed

4 files changed

+43
-31
lines changed

ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,4 +754,8 @@ public static void log(String message, Object... args) {
754754
public static Logger getStaticLogger() {
755755
return logger;
756756
}
757+
758+
public static void disableUpdates() {
759+
UPDATES_DISABLED = true;
760+
}
757761
}

ProtocolLib/src/main/java/com/comphenix/protocol/updater/BukkitUpdater.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.zip.ZipFile;
2323

2424
import org.bukkit.configuration.file.YamlConfiguration;
25-
import org.bukkit.plugin.Plugin;
2625
import org.json.simple.JSONArray;
2726
import org.json.simple.JSONObject;
2827
import org.json.simple.JSONValue;
@@ -79,7 +78,7 @@ public class BukkitUpdater extends Updater {
7978
* @param type Specify the type of update this will be. See {@link UpdateType}
8079
* @param announce True if the program should announce the progress of new updates in console
8180
*/
82-
public BukkitUpdater(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
81+
public BukkitUpdater(ProtocolLibrary plugin, int id, File file, UpdateType type, boolean announce) {
8382
super(plugin, type, announce);
8483

8584
this.file = file;

ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,22 @@
2121
import java.io.InputStreamReader;
2222
import java.net.HttpURLConnection;
2323
import java.net.URL;
24-
25-
import org.bukkit.plugin.Plugin;
24+
import java.util.logging.Level;
2625

2726
import com.comphenix.protocol.ProtocolLibrary;
2827
import com.comphenix.protocol.error.Report;
28+
import com.comphenix.protocol.utility.Closer;
2929
import com.google.common.base.Charsets;
3030

3131
/**
3232
* Adapted version of the Bukkit updater for use with Spigot resources
33-
*
3433
* @author dmulloy2
3534
*/
3635

3736
public final class SpigotUpdater extends Updater {
3837
private String remoteVersion;
3938

40-
public SpigotUpdater(Plugin plugin, UpdateType type, boolean announce) {
39+
public SpigotUpdater(ProtocolLibrary plugin, UpdateType type, boolean announce) {
4140
super(plugin, type, announce);
4241
}
4342

@@ -70,34 +69,45 @@ public void run() {
7069
result = UpdateResult.NO_UPDATE;
7170
}
7271
} catch (Throwable ex) {
73-
ProtocolLibrary.getErrorReporter().reportDetailed(
74-
SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this));
75-
} finally {
76-
// Invoke the listeners on the main thread
77-
for (Runnable listener : listeners) {
78-
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener);
79-
}
80-
}
72+
if (ProtocolLibrary.getConfiguration().isDebug()) {
73+
ProtocolLibrary.getErrorReporter().reportDetailed(
74+
SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this));
75+
} else {
76+
plugin.getLogger().log(Level.WARNING, "Failed to check for updates: " + ex);
77+
}
78+
79+
ProtocolLibrary.disableUpdates();
80+
} finally {
81+
// Invoke the listeners on the main thread
82+
for (Runnable listener : listeners) {
83+
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener);
84+
}
85+
}
8186
}
8287
}
8388

84-
private static final String RESOURCE_URL = "https://www.spigotmc.org/resources/protocollib.1997/";
85-
private static final String API_URL = "http://www.spigotmc.org/api/general.php";
89+
private static final String PROTOCOL = "https://";
90+
private static final String RESOURCE_URL = PROTOCOL + "www.spigotmc.org/resources/protocollib.1997/";
91+
private static final String API_URL = PROTOCOL + "www.spigotmc.org/api/general.php";
8692
private static final String ACTION = "POST";
8793

8894
private static final int ID = 1997;
8995
private static final byte[] API_KEY = ("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=" + ID).getBytes(Charsets.UTF_8);
9096

91-
private String getSpigotVersion() throws IOException {
92-
HttpURLConnection con = (HttpURLConnection) new URL(API_URL).openConnection();
93-
con.setDoOutput(true);
94-
con.setRequestMethod(ACTION);
95-
con.getOutputStream().write(API_KEY);
96-
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
97-
if (version.length() <= 7) {
98-
return version;
99-
}
97+
public String getSpigotVersion() throws IOException {
98+
Closer closer = Closer.create();
10099

101-
return null;
100+
try {
101+
HttpURLConnection con = (HttpURLConnection) new URL(API_URL).openConnection();
102+
con.setDoOutput(true);
103+
con.setRequestMethod(ACTION);
104+
con.getOutputStream().write(API_KEY);
105+
106+
InputStreamReader isr = closer.register(new InputStreamReader(con.getInputStream()));
107+
BufferedReader br = closer.register(new BufferedReader(isr));
108+
return br.readLine();
109+
} finally {
110+
closer.close();
111+
}
102112
}
103113
}

ProtocolLib/src/main/java/com/comphenix/protocol/updater/Updater.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
import java.util.List;
2121
import java.util.concurrent.CopyOnWriteArrayList;
2222

23-
import org.bukkit.plugin.Plugin;
24-
23+
import com.comphenix.protocol.ProtocolLibrary;
2524
import com.comphenix.protocol.error.ReportType;
2625
import com.comphenix.protocol.utility.MinecraftVersion;
2726
import com.comphenix.protocol.utility.Util;
@@ -32,7 +31,7 @@
3231
*/
3332

3433
public abstract class Updater {
35-
protected Plugin plugin;
34+
protected ProtocolLibrary plugin;
3635

3736
protected String versionName;
3837
protected String versionLink;
@@ -49,7 +48,7 @@ public abstract class Updater {
4948

5049
public static final ReportType REPORT_CANNOT_UPDATE_PLUGIN = new ReportType("Cannot update ProtocolLib.");
5150

52-
protected Updater(Plugin plugin, UpdateType type, boolean announce) {
51+
protected Updater(ProtocolLibrary plugin, UpdateType type, boolean announce) {
5352
this.plugin = plugin;
5453
this.type = type;
5554
this.announce = announce;
@@ -266,7 +265,7 @@ public String toString() {
266265
}
267266
}
268267

269-
public static Updater create(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
268+
public static Updater create(ProtocolLibrary plugin, int id, File file, UpdateType type, boolean announce) {
270269
if (Util.isUsingSpigot()) {
271270
return new SpigotUpdater(plugin, type, announce);
272271
} else {

0 commit comments

Comments
 (0)