Skip to content

Commit

Permalink
0.8.5 - Fixed some API issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
noahbclarkson committed Aug 26, 2020
1 parent 63b2757 commit c4688ba
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 33 deletions.
31 changes: 3 additions & 28 deletions Auto-Tune/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>unprotesting.com.github</groupId>
<artifactId>Auto-Tune</artifactId>
<name>Auto-Tune</name>
<version>0.8.4</version>
<version>0.8.5</version>
<description>The automatic pricing plugin for minecraft</description>
<url>https://github.com/Unprotesting/Auto-Tune</url>
<issueManagement>
Expand Down Expand Up @@ -46,7 +46,7 @@
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -96,42 +96,17 @@
<artifactId>spigot-api</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<mainClass>${project.groupId}.${project.artifactId}</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

4 changes: 2 additions & 2 deletions Auto-Tune/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- Project information -->
<groupId>unprotesting.com.github</groupId>
<artifactId>Auto-Tune</artifactId>
<version>0.8.4</version>
<version>0.8.5</version>
<packaging>jar</packaging>
<!-- Info -->
<name>Auto-Tune</name>
Expand Down Expand Up @@ -125,7 +125,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<version>3.2.4</version>
<configuration>
<filters>
<filter>
Expand Down
12 changes: 12 additions & 0 deletions Auto-Tune/src/unprotesting/com/github/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
57 changes: 54 additions & 3 deletions Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() == "[email protected]"){
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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public static JSONObject returnJSONFromParams(String model, String algorithm, Do
obj.put("minVolatility", minVolatility);
return obj;
}

}

0 comments on commit c4688ba

Please sign in to comment.