Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueTree242 committed Dec 24, 2021
2 parents b972c7e + 7692b33 commit 4a418d7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ public void loadGroups() {
public void performStartUpdateCheck() {
ProxyServer.getInstance().getScheduler().runAsync(this, () -> {
UpdateCheckResult result = Impl.get().updateCheck();
if (result == null) getLogger().severe("Could not check for updates");
String msg = result.getVersionsBehind() == 0 ?
if (result == null) {
getLogger().severe("Could not check for updates");
return;
} String msg = result.getVersionsBehind() == 0 ?
ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_UP_TO_DATE) :
ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "")
.replace("{download}", result.getUpdateUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ public boolean isLegacy() {
public void performStartUpdateCheck() {
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
UpdateCheckResult result = Impl.get().updateCheck();
if (result == null) getLogger().severe("Could not check for updates");
String msg = result.getVersionsBehind() == 0 ?
if (result == null) {
getLogger().severe("Could not check for updates");
return;
} String msg = result.getVersionsBehind() == 0 ?
ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_UP_TO_DATE) :
ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "")
.replace("{download}", result.getUpdateUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ public Config getConfig() {

public void performStartUpdateCheck() {
UpdateCheckResult result = updateCheck();
if (result == null) getLogger().error("Could not check for updates");
if (result == null) {
getLogger().error("Could not check for updates");
return;
}
String msg = result.getVersionsBehind() == 0 ?
LegacyComponentSerializer.legacy('&').deserialize(Constants.DEFAULT_UP_TO_DATE).content() :
LegacyComponentSerializer.legacy('&').deserialize(Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "")
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ subprojects {
filter ReplaceTokens, tokens: [version : version,
build : buildNumber,
commit : commit,
description: description,
buildDate: System.currentTimeMillis() + ""
]
}
Expand Down
4 changes: 4 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ rootProject.allprojects {
relocate 'space.arim.dazzleconf', "tk.bluetree242.advancedplhide.dependencies.dazzleconf"
relocate 'org.yaml.snakeyaml', "tk.bluetree242.advancedplhide.dependencies.yaml"
relocate 'org.json', "tk.bluetree242.advancedplhide.dependencies.json"
relocate 'okio', "tk.bluetree242.advancedplhide.dependencies.okio"
relocate 'okhttp3', "tk.bluetree242.advancedplhide.dependencies.okhttp"
}
}

Expand All @@ -50,6 +52,8 @@ dependencies {
implementation 'space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.0-M2'
compileOnly 'com.mojang:brigadier:1.0.18'
implementation group: 'org.json', name: 'json', version: '20210307'
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
implementation("com.squareup.okhttp3:okhttp")
}


Expand Down
21 changes: 13 additions & 8 deletions core/src/main/java/tk/bluetree242/advancedplhide/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@

package tk.bluetree242.advancedplhide;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.json.JSONObject;
import tk.bluetree242.advancedplhide.config.Config;
import tk.bluetree242.advancedplhide.exceptions.ConfigurationLoadException;
import tk.bluetree242.advancedplhide.impl.version.UpdateCheckResult;
import tk.bluetree242.advancedplhide.utils.HttpPostMultipart;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -92,16 +95,18 @@ public String getBuildDate() {

public UpdateCheckResult updateCheck() {
try {
OkHttpClient client = new OkHttpClient();
Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", "APH/Java");
HttpPostMultipart req = new HttpPostMultipart("https://advancedplhide.ml/updatecheck", "utf-8", headers);
req.addFormField("version", getCurrentVersion());
req.addFormField("buildNumber", getCurrentBuild());
req.addFormField("buildDate", getBuildDate());
req.addFormField("devUpdatechecker", getConfig().dev_updatechecker() + "");
String response = req.finish();
MultipartBody form = new MultipartBody.Builder().setType(MediaType.get("multipart/form-data"))
.addFormDataPart("version", getCurrentVersion())
.addFormDataPart("buildNumber", getCurrentBuild())
.addFormDataPart("buildDate", getCurrentBuild())
.addFormDataPart("devUpdatechecker", getConfig().dev_updatechecker() + "").build();
Request req = new Request.Builder().url("https://advancedplhide.ml/updatecheck").post(form).build();
String response = client.newCall(req).execute().body().string();
JSONObject json = new JSONObject(response);
return new UpdateCheckResult(json.getInt("versions_behind"), json.isNull("versions_behind") ? null : json.getString("message"), json.isNull("type") ? "INFO" : json.getString("type"), json.getString("downloadUrl"));
return new UpdateCheckResult(json.getInt("versions_behind"), json.isNull("versions_behind") ? null : json.isNull("message") ? null : json.getString("message"), json.isNull("type") ? "INFO" : json.getString("type"), json.getString("downloadUrl"));
} catch (Exception e) {
return null;
}
Expand Down

0 comments on commit 4a418d7

Please sign in to comment.