From a81017223069806164993ed7db047e1b77ccb72e Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Fri, 24 Dec 2021 14:56:01 +0200 Subject: [PATCH 1/4] fix possible startup error --- .../advancedplhide/bungee/AdvancedPlHideBungee.java | 6 ++++-- .../advancedplhide/spigot/AdvancedPlHideSpigot.java | 6 ++++-- .../advancedplhide/velocity/AdvancedPlHideVelocity.java | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Bungee/src/main/java/tk/bluetree242/advancedplhide/bungee/AdvancedPlHideBungee.java b/Bungee/src/main/java/tk/bluetree242/advancedplhide/bungee/AdvancedPlHideBungee.java index df651d1..aba8f08 100644 --- a/Bungee/src/main/java/tk/bluetree242/advancedplhide/bungee/AdvancedPlHideBungee.java +++ b/Bungee/src/main/java/tk/bluetree242/advancedplhide/bungee/AdvancedPlHideBungee.java @@ -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())); diff --git a/Spigot/src/main/java/tk/bluetree242/advancedplhide/spigot/AdvancedPlHideSpigot.java b/Spigot/src/main/java/tk/bluetree242/advancedplhide/spigot/AdvancedPlHideSpigot.java index 94b9a27..d73cf19 100644 --- a/Spigot/src/main/java/tk/bluetree242/advancedplhide/spigot/AdvancedPlHideSpigot.java +++ b/Spigot/src/main/java/tk/bluetree242/advancedplhide/spigot/AdvancedPlHideSpigot.java @@ -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())); diff --git a/Velocity/src/main/java/tk/bluetree242/advancedplhide/velocity/AdvancedPlHideVelocity.java b/Velocity/src/main/java/tk/bluetree242/advancedplhide/velocity/AdvancedPlHideVelocity.java index 3bcf12c..34e96ee 100644 --- a/Velocity/src/main/java/tk/bluetree242/advancedplhide/velocity/AdvancedPlHideVelocity.java +++ b/Velocity/src/main/java/tk/bluetree242/advancedplhide/velocity/AdvancedPlHideVelocity.java @@ -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() + "") From 12085f69461194b6768fc150b03893d91956b4b0 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Fri, 24 Dec 2021 15:00:41 +0200 Subject: [PATCH 2/4] bump version to 2.2 dev --- build.gradle | 1 + gradle.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f4e0de5..83641f7 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,7 @@ subprojects { filter ReplaceTokens, tokens: [version : version, build : buildNumber, commit : commit, + description: description, buildDate: System.currentTimeMillis() + "" ] } diff --git a/gradle.properties b/gradle.properties index 9f75c98..c3a301a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,5 +21,5 @@ # group=tk.bluetree242 name=AdvancedPlHide -version=2.0-DEV +version=2.2-DEV description=Remove Most ways of finding your plugins on your minecraft Server! \ No newline at end of file From 8710145ac41ff5ef5a058e80331abea8133a8d29 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Fri, 24 Dec 2021 15:02:03 +0200 Subject: [PATCH 3/4] reverse back version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c3a301a..9f75c98 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,5 +21,5 @@ # group=tk.bluetree242 name=AdvancedPlHide -version=2.2-DEV +version=2.0-DEV description=Remove Most ways of finding your plugins on your minecraft Server! \ No newline at end of file From 63267b59c6ca5b464ca37f1f1cf5b29dbbeee9b9 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Fri, 24 Dec 2021 15:21:32 +0200 Subject: [PATCH 4/4] use okhttp for updatechecker --- core/build.gradle | 4 ++++ .../bluetree242/advancedplhide/Platform.java | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 0120c91..a41a015 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -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" } } @@ -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") } diff --git a/core/src/main/java/tk/bluetree242/advancedplhide/Platform.java b/core/src/main/java/tk/bluetree242/advancedplhide/Platform.java index 9ac4372..ad14103 100644 --- a/core/src/main/java/tk/bluetree242/advancedplhide/Platform.java +++ b/core/src/main/java/tk/bluetree242/advancedplhide/Platform.java @@ -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; @@ -92,16 +95,18 @@ public String getBuildDate() { public UpdateCheckResult updateCheck() { try { + OkHttpClient client = new OkHttpClient(); Map 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; }