- All rights reserved.
+ * © Stijn Bannink [stijnbannink23@gmail.com] - All rights reserved.
*/
public class UpdateManager {
private static final String SPIGOT_API = "https://api.spigotmc.org/legacy/update.php?resource=%d";
private static final String SPIGOT_DOWNLOAD = "http://api.spiget.org/v2/resources/%s/download";
- /* Port 4000 is now legacy, 4443 has a SSL cert */
- /* As of 24-05-2020, using the legacy port because of SSL errors */
- private static final String SBDPLUGINS_API = "http://updates.sbdplugins.nl:4000/api/resources/%d";
- private static final String SBDPLUGINS_DOWNLOAD = "http://updates.sbdplugins.nl:4000/api/download/%d";
+ private static final String SBDPLUGINS_API = "https://updates.sbdplugins.nl/api/v2/plugins/%d";
+ private static final String SBDPLUGINS_DOWNLOAD = "https://updates.sbdplugins.nl/api/v2/download/%d";
private final Plugin plugin;
private final Version currentVersion;
private final int resourceID;
private final CheckType type;
+ private final String license;
+
private BiConsumer versionResponse;
private BiConsumer downloadResponse;
/**
- * Construct a new UpdateManager
+ * Construct a new UpdateManager for Spigot
*
* @param plugin The javaplugin (Main class)
* @param resourceID The resourceID on spigot/sbdplugins
- * @param type The check type
*/
- public UpdateManager(@NotNull Plugin plugin, int resourceID, CheckType type) {
+ public UpdateManager(@NotNull Plugin plugin, int resourceID) {
this.plugin = plugin;
this.currentVersion = new Version(plugin.getDescription().getVersion());
this.resourceID = resourceID;
- this.type = type;
+ this.type = CheckType.SPIGOT;
+ this.license = null;
+ }
+
+ /**
+ * Construct a new UpdateManager for SBDPlugins
+ *
+ * @param plugin The javaplugin (Main class)
+ * @param resourceID The resourceID on spigot/sbdplugins
+ * @param license The license for the download
+ */
+ public UpdateManager(@NotNull Plugin plugin, int resourceID, String license) {
+ this.plugin = plugin;
+ this.currentVersion = new Version(plugin.getDescription().getVersion());
+ this.resourceID = resourceID;
+ this.type = CheckType.SBDPLUGINS;
+ this.license = license;
}
/**
@@ -89,7 +103,7 @@ public class UpdateManager {
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else if (type == CheckType.SBDPLUGINS) {
- HttpURLConnection con = (HttpURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection();
+ HttpsURLConnection con = (HttpsURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
@@ -98,7 +112,7 @@ public class UpdateManager {
if (in == null) return;
- String version = null;
+ String version;
String inputLine;
StringBuilder response = new StringBuilder();
@@ -113,10 +127,10 @@ public class UpdateManager {
JsonArray array = parser.parse(response.toString()).getAsJsonArray();
version = array.get(0).getAsJsonObject().get("name").getAsString();
- } else if (type == CheckType.SBDPLUGINS) {
+ } else {
JsonObject object = parser.parse(response.toString()).getAsJsonObject();
- version = object.get("data").getAsJsonObject().get("version").getAsString();
+ version = object.get("version").getAsString();
}
if (version == null) return;
@@ -134,7 +148,7 @@ public class UpdateManager {
}
public void runUpdate() {
- File pluginFile = getPluginFile();// /plugins/XXX.jar
+ File pluginFile = getPluginFile(); // /plugins/XXX.jar
if (pluginFile == null) {
this.downloadResponse.accept(DownloadResponse.ERROR, null);
Bukkit.getLogger().info("Pluginfile is null");
@@ -154,11 +168,12 @@ public class UpdateManager {
ReadableByteChannel channel;
try {
//https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java
- HttpURLConnection connection;
+ int response;
+ InputStream stream;
if (type == CheckType.SBDPLUGINS) {
- connection = (HttpURLConnection) new URL(String.format(SBDPLUGINS_DOWNLOAD, this.resourceID)).openConnection();
+ HttpURLConnection connection = (HttpURLConnection) new URL(String.format(SBDPLUGINS_DOWNLOAD, this.resourceID)).openConnection();
- String urlParameters = "license=" + ThemeParkPlus.getSConfig().getFile().getString("License") + "&port=" + Bukkit.getPort();
+ String urlParameters = "license=" + license + "&port=" + Bukkit.getPort();
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
@@ -172,27 +187,31 @@ public class UpdateManager {
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.write(postData);
wr.close();
+
+ response = connection.getResponseCode();
+ stream = connection.getInputStream();
} else {
- connection = (HttpURLConnection) new URL(String.format(SPIGOT_DOWNLOAD, this.resourceID)).openConnection();
+ HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format(SPIGOT_DOWNLOAD, this.resourceID)).openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
+
+ response = connection.getResponseCode();
+ stream = connection.getInputStream();
}
- if (connection.getResponseCode() != 200) {
- BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ if (response != 200) {
+ BufferedReader in = new BufferedReader(new InputStreamReader(stream));
String inputLine;
- StringBuilder response = new StringBuilder();
+ StringBuilder responsestr = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
- response.append(inputLine);
+ responsestr.append(inputLine);
}
in.close();
- Bukkit.getLogger().info(response.toString());
-
- throw new RuntimeException("Download returned status #" + connection.getResponseCode());
+ throw new RuntimeException("Download returned status #" + response, new Throwable(responsestr.toString()));
}
- channel = Channels.newChannel(connection.getInputStream());
+ channel = Channels.newChannel(stream);
} catch (IOException e) {
Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.ERROR, null));
e.printStackTrace();
@@ -243,7 +262,7 @@ public class UpdateManager {
}
}
- public enum CheckType {
+ private enum CheckType {
SPIGOT, SBDPLUGINS
}
@@ -260,13 +279,13 @@ public class UpdateManager {
public static class Version {
- private String version;
+ private final String version;
public final String get() {
return this.version;
}
- public Version(String version) {
+ private Version(String version) {
if(version == null)
throw new IllegalArgumentException("Version can not be null");
if(!version.matches("[0-9]+(\\.[0-9]+)*"))
@@ -274,7 +293,7 @@ public class UpdateManager {
this.version = version;
}
- public VersionResponse check(@NotNull Version that) {
+ private VersionResponse check(@NotNull Version that) {
String[] thisParts = this.get().split("\\.");
String[] thatParts = that.get().split("\\.");
diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java
index 601b554..e1b2305 100644
--- a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java
+++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/License.java
@@ -88,12 +88,12 @@ public class License implements Listener {
try {
response = sendGETRequestJSON(url);
} catch (IOException e) {
- disable("Couldn't send the request.");
+ disable("Something went wrong while sending the request.");
return;
}
if (response == null) {
- disable("Couldn't send the request.");
+ disable("Something went wrong while sending the request. Did you even fill out a license?");
return;
}
@@ -175,12 +175,12 @@ public class License implements Listener {
try {
response = sendGETRequestJSON(url);
} catch (IOException e) {
- disable("Couldn't send the activate request.");
+ disable("Something went wrong while sending the request.");
return;
}
if (response == null) {
- disable("Couldn't send the activate request.");
+ disable("Something went wrong while sending the request. Did you even fill out a license?");
return;
}
@@ -241,7 +241,6 @@ public class License implements Listener {
con.setRequestProperty("Authorization", "Basic " + authStringEnc);
int code = con.getResponseCode();
if (code == 404) {
- disable("404_error");
return null;
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index a94c745..ec7f48f 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -1,4 +1,4 @@
-License: 'TPABCD-1234-ABCD-1234SBD'
+License: ''
AntiFreerun:
Enabled: false
UpdateChecker:
@@ -8,8 +8,41 @@ MessageInConsole: true
WaitingRow:
MinutesPerPlayer: 1.5
Sign:
- Row1: "&8[&6ThemeParkPlus&8]"
- Row2: "&bWaitingRow"
+ Row1: '&8[&6ThemeParkPlus&8]'
+ Row2: '&bWaitingRow'
+Malfunction:
+ AllowCommandReport: true
+ AllowCommandFix: false
+ Sign:
+ Row1: '&8[&6ThemeParkPlus&8]'
+ Row2: '&bMalfunction'
+ GUI:
+ Title: '&3Report Malfunction for %ridename%'
+ Buttons:
+ Report:
+ Slot: 2
+ Material: GREEN_WOOL
+ Name: '&2&lReport Malfunction'
+ Lores:
+ - '&fClick here to report malfunction for %ridename%.'
+ - '&r'
+ - '&cAbuse of this function is not allowed!'
+ Fix:
+ Slot: 4
+ Material: STONE_PICKAXE
+ Name: '&e&lFix Ride'
+ Lores:
+ - '&fClick here to fix %ridename%!'
+ - '&r'
+ - '&fReporter: &7%reporter%'
+ - '&fDate: &7%date%'
+ - '&fReason: &7%reason%'
+ Cancel:
+ Slot: 6
+ Material: RED_WOOL
+ Name: '&4&lCancel Report'
+ Lores:
+ - '&fClick here to cancel.'
Fastpass:
Item:
DisplayName: '&6Fastpass Ticket'
diff --git a/src/main/resources/messages_en.yml b/src/main/resources/messages_en.yml
index a92bd97..76e6c6a 100644
--- a/src/main/resources/messages_en.yml
+++ b/src/main/resources/messages_en.yml
@@ -3,6 +3,7 @@ General:
NoPlayer: '&cYou have to be a player to do this.'
IncorrectAmount: '&cThis amount is incorrect.'
IncorrectSign: '&cThis sign is incorrect. Please read the wiki for more information.'
+ RequiresThemePark: '&cThis function requires ThemePark to work. Install it to use this function.'
Gates:
WrongDir: '&cYou can''t walk through this gate in that direction.'
UnknownDir: '&cThis direction is unknown. Choose between: NORTH, SOUTH, EAST, WEST'
@@ -39,3 +40,10 @@ WaitingRow:
WrongLocation: '&cA waitingrow sign (from the attraction %ridename%) couldn''t be found! It will be deleted.'
RedstoneTimer:
Started: '&aThe timer successfully started. It will go off in &f%sec1% &asecond(s), and will turn off in &f%sec2% &asecond(s) after that.'
+Malfunction:
+ NoCommand: '&cYou can''t report or fix a ride using the command. Please use this Malfunction Sign at the ride.'
+ Reported: '&aSuccessfully reported a malfunction for &f%ride%&a.'
+ AlreadyReported: '&cThere is already a malfunction reported for &f%ride%&c.'
+ Fixed: '&aThe ride &f%ride%&a is now successfully fixed.'
+ AlreadyFixed: '&cThe ride &f%ride%&a &chas no malfunction report, and therefore cannot be fixed.'
+ ThisRide: 'this ride'
\ No newline at end of file