From c4688ba6c6c67172b0b437010ddde3d72dec76d3 Mon Sep 17 00:00:00 2001 From: Unprotesting Date: Wed, 26 Aug 2020 12:23:42 +0100 Subject: [PATCH] 0.8.5 - Fixed some API issues Fixes: + Fixed Auto-Tune loading without a vaild API key and then breaking on price-calculation. + Fixed compilation errors when compiling manually on 1.15 due to maven-shade-plugin not being updated Features: + Added some more messages on startup surrounding API info + Added some more debug info surrounding API info Other + Updated to 0.8.5 --- Auto-Tune/dependency-reduced-pom.xml | 31 +--------- Auto-Tune/pom.xml | 4 +- .../src/unprotesting/com/github/Main.java | 12 ++++ .../com/github/util/HttpPostRequestor.java | 57 ++++++++++++++++++- .../com/github/util/JSONManager.java | 1 + 5 files changed, 72 insertions(+), 33 deletions(-) diff --git a/Auto-Tune/dependency-reduced-pom.xml b/Auto-Tune/dependency-reduced-pom.xml index f94f277..c2f670b 100644 --- a/Auto-Tune/dependency-reduced-pom.xml +++ b/Auto-Tune/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ unprotesting.com.github Auto-Tune Auto-Tune - 0.8.4 + 0.8.5 The automatic pricing plugin for minecraft https://github.com/Unprotesting/Auto-Tune @@ -46,7 +46,7 @@ maven-shade-plugin - 2.3 + 3.2.4 package @@ -96,42 +96,17 @@ spigot-api 1.16.2-R0.1-SNAPSHOT provided - - - commons-lang - commons-lang - - - gson - com.google.code.gson - - - bungeecord-chat - net.md-5 - - - snakeyaml - org.yaml - - com.github.MilkBowl VaultAPI 1.7 provided - - - bukkit - org.bukkit - - + 1.8 ${project.groupId}.${project.artifactId} UTF-8 - 1.8 - diff --git a/Auto-Tune/pom.xml b/Auto-Tune/pom.xml index c1f5b2b..2050d32 100644 --- a/Auto-Tune/pom.xml +++ b/Auto-Tune/pom.xml @@ -8,7 +8,7 @@ unprotesting.com.github Auto-Tune - 0.8.4 + 0.8.5 jar Auto-Tune @@ -125,7 +125,7 @@ org.apache.maven.plugins maven-shade-plugin - 2.3 + 3.2.4 diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java index f214d65..7ffb97c 100644 --- a/Auto-Tune/src/unprotesting/com/github/Main.java +++ b/Auto-Tune/src/unprotesting/com/github/Main.java @@ -107,6 +107,8 @@ public final class Main extends JavaPlugin implements Listener { public static String basicVolatilityAlgorithim; public static String priceModel; + public Boolean vaildAPIKey = false; + @Getter @Setter public static Gui gui; @@ -174,6 +176,16 @@ public void onEnable() { loadShopsFile(); loadShopData(); materialListSize = memMap.size(); + vaildAPIKey = HttpPostRequestor.checkAPIKey(); + if (!vaildAPIKey){ + log.severe(String.format("Disabled due to invalid API key", getDescription().getName())); + debugLog("Please check API key is vaild in config.yml"); + getServer().getPluginManager().disablePlugin(this); + return; + } + if (vaildAPIKey) { + log("API-Key found in database. Continuing to load Auto-Tune.."); + } this.getCommand("at").setExecutor(new AutoTuneCommand()); this.getCommand("shop").setExecutor(new AutoTuneGUIShopUserCommand()); this.getCommand("sell").setExecutor(new AutoTuneSellCommand()); diff --git a/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java b/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java index 70d238f..fdebd69 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java +++ b/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java @@ -42,12 +42,10 @@ public static Double sendPostRequestUsingHttpClient(String model, String algorit if (statusCode == 200) { client.close(); } - ; if (statusCode != 200) { client.close(); Main.log("Error on status code"); } - ; Main.debugLog(response.getStatusLine().getReasonPhrase()); HttpEntity entityResponse = response.getEntity(); if (entityResponse != null) { @@ -81,6 +79,59 @@ public static Double sendRequestForPrice(String model, String algorithm, String } return newPrice; } - + + + public static boolean ghostCheckAPIKey() throws ClientProtocolException, IOException { + if (Config.getApiKey() == "xyz"){ + Main.log("Please change your API key in the config.yml file"); + return false; + } + if (Config.getEmail() == "xyz@gmail.com"){ + Main.log("Please change your Email in the config.yml file"); + return false; + } + else{ + Main.debugLog("Api-Key has been changed in config"); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost("https://safe-refuge-09383.herokuapp.com"); + httpPost.setHeader("content-type", "application/json"); + httpPost.setHeader("apikey", Config.getApiKey()); + httpPost.setHeader("email", Config.getEmail()); + JSONObject json = new JSONObject(); + json.put("apikey", Config.getApiKey()); + StringEntity entity = new StringEntity(json.toJSONString()); + httpPost.setEntity(entity); + CloseableHttpResponse response = client.execute(httpPost); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode == 200) { + client.close(); + return true; + } + else if (statusCode != 200) { + client.close(); + Main.log("Error on status code"); + return false; + } + } + return false; + + } + + public static boolean checkAPIKey(){ + try { + boolean vaildKey = ghostCheckAPIKey(); + if (vaildKey == true){ + return true; + } + else if (vaildKey != true){ + return false; + } + } catch (IOException e) { + e.printStackTrace(); + return false; + } + return false; + } + } \ No newline at end of file diff --git a/Auto-Tune/src/unprotesting/com/github/util/JSONManager.java b/Auto-Tune/src/unprotesting/com/github/util/JSONManager.java index 975ab1d..0041a31 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/JSONManager.java +++ b/Auto-Tune/src/unprotesting/com/github/util/JSONManager.java @@ -15,4 +15,5 @@ public static JSONObject returnJSONFromParams(String model, String algorithm, Do obj.put("minVolatility", minVolatility); return obj; } + } \ No newline at end of file