Skip to content

Commit

Permalink
Fixed some critical bugs and added favicon.io image to web folder
Browse files Browse the repository at this point in the history
+ Fixed max-buys/sells not working properly
+ Fixed HTTP requests not sending properly
+ Fixed some null errors when tasks concurrently edited the map such as price calculation and inflation
+ Updated to 0.12.1
  • Loading branch information
noahbclarkson committed Dec 27, 2020
1 parent 91a02bb commit 2dbde4b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
3 changes: 2 additions & 1 deletion 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.12.0</version>
<version>0.12.1</version>
<description>The automatic pricing plugin for minecraft</description>
<url>https://github.com/Unprotesting/Auto-Tune</url>
<issueManagement>
Expand All @@ -29,6 +29,7 @@
<include>enchantments.yml</include>
<include>web/trade.html</include>
<include>web/trade-short.html</include>
<include>web/favicon.ico</include>
</includes>
</resource>
</resources>
Expand Down
3 changes: 2 additions & 1 deletion Auto-Tune/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Project information -->
<groupId>unprotesting.com.github</groupId>
<artifactId>Auto-Tune</artifactId>
<version>0.12.0</version>
<version>0.12.1</version>
<!-- Info -->
<name>Auto-Tune</name>
<url>https://github.com/Unprotesting/Auto-Tune</url>
Expand Down Expand Up @@ -116,6 +116,7 @@
<include>enchantments.yml</include>
<include>web/trade.html</include>
<include>web/trade-short.html</include>
<include>web/favicon.ico</include>
</includes>
</resource>
</resources>
Expand Down
Binary file added Auto-Tune/src/resources/web/favicon.ico
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
Expand All @@ -30,7 +29,6 @@
import net.md_5.bungee.api.ChatColor;
import unprotesting.com.github.Main;
import unprotesting.com.github.util.Config;
import unprotesting.com.github.util.InventoryHandler;
import unprotesting.com.github.util.Section;
import unprotesting.com.github.util.TextHandler;

Expand Down Expand Up @@ -461,9 +459,26 @@ public double getSellPriceDifference(String item) {

public static Double getItemPrice(String item, boolean sell) {
if (!sell) {
return Main.getItemPrices().get(item).price;
Double output = Main.getItemPrices().get(item).price;
if (output != null){
return output;
}
else{
ConcurrentHashMap<Integer, Double[]> map = Main.map.get(item);
output = map.get(map.size()-1)[0];
return output;
}
} else {
return Main.getItemPrices().get(item).sellPrice;
Double output = Main.getItemPrices().get(item).sellPrice;
if (output != null){
return output;
}
else{
ConcurrentHashMap<Integer, Double[]> map = Main.map.get(item);
output = map.get(map.size()-1)[0];
output = output - output*0.01*getSellDifference(item);
return output;
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion Auto-Tune/src/unprotesting/com/github/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public final class Main extends JavaPlugin implements Listener {
private File configf;

@Getter
public static File shopf, tradef, tradeShortf, enchf;
public static File shopf, tradef, tradeShortf, enchf, faviconf;

public static String basicVolatilityAlgorithim;
public static String priceModel;
Expand Down Expand Up @@ -223,6 +223,8 @@ public void onEnable() {
e.printStackTrace();
}
}
Main.log("Please leave a positive review for Auto-Tune on our spigot page: https://spigotmc.org/resources/auto-tune.85715");
Main.log("Please donate here if you enjoy the plugin: https://www.patreon.com/Unprotesting");
int pluginId = 9687;
Metrics metrics = new Metrics(getINSTANCE(), pluginId);
setupDataFiles();
Expand Down Expand Up @@ -379,6 +381,7 @@ public void createFiles() {
enchf = new File(getDataFolder(), "enchantments.yml");
tradef = new File("plugins/Auto-Tune/web/", "trade.html");
tradeShortf = new File("plugins/Auto-Tune/web/", "trade-short.html");
faviconf = new File("plugins/Auto-Tune/web/", "favicon.ico");

if (!configf.exists()) {
configf.getParentFile().mkdirs();
Expand All @@ -405,6 +408,10 @@ public void createFiles() {
saveResource("enchantments.yml", false);
}

if (!faviconf.exists()) {
faviconf.getParentFile().mkdirs();
saveResource("web/favicon.ico", false);
}

mainConfig = new YamlConfiguration();
shopConfig = new YamlConfiguration();
Expand Down
33 changes: 26 additions & 7 deletions Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package unprotesting.com.github.util;

import java.io.IOException;
import java.net.SocketException;
import java.util.concurrent.ConcurrentHashMap;

import com.google.gson.JsonArray;
Expand All @@ -22,39 +23,57 @@

public class HttpPostRequestor {

public static CloseableHttpClient client = HttpClients.createDefault();

public static void updatePricesforItems(JSONObject json) throws ClientProtocolException, IOException {
HttpEntity entityResponse = sendPostRequest(json);
if (entityResponse != null) {
JsonParser parser = new JsonParser();
String result = EntityUtils.toString(entityResponse);
String result = null;
try {
result = EntityUtils.toString(entityResponse);
} catch (SocketException ex) {
Main.debugLog("Socket Exception: Socket Closed. Reloading HttpClient..");
client = HttpClients.createDefault();
entityResponse = sendPostRequest(json);
}
if (result == null) {
return;
}
JsonElement jsonElement = parser.parse(result);
JsonObject jsonObject = jsonElement.getAsJsonObject();
JsonElement jsonArrayElement = jsonObject.get("returnData");
JsonArray jsonArray = jsonArrayElement.getAsJsonArray();
for (JsonElement element : jsonArray){
for (JsonElement element : jsonArray) {
JsonObject obj = element.getAsJsonObject();
JsonElement priceElement = obj.get("newPrice");
JsonElement nameElement = obj.get("itemName");
String priceString = priceElement.getAsString();
String name = nameElement.getAsString();
Double price = Double.parseDouble(priceString);
ConcurrentHashMap<Integer, Double[]> map = Main.map.get(name);
Double[] arr = {price, 0.0, 0.0};
Double[] arr = { price, 0.0, 0.0 };
map.put((map.size()), arr);
Main.map.put(name, map);
Main.map.put(name, map);
}
}
}

public static HttpEntity sendPostRequest(JSONObject json) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://economy-api.herokuapp.com/");
StringEntity entity = new StringEntity(json.toJSONString());
httpPost.setEntity(entity);
httpPost.setHeader("content-type", "application/json");
httpPost.setHeader("apikey", Config.getApiKey());
httpPost.setHeader("email", Config.getEmail());
CloseableHttpResponse response = client.execute(httpPost);
httpPost.setHeader("email", Config.getEmail());
CloseableHttpResponse response = null;
try{
response = client.execute(httpPost);
}
catch (IllegalStateException ex){
client = HttpClients.createDefault();
response = client.execute(httpPost);
}
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entityResponse = null;
if (statusCode == 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static void loadItemPriceData() {
public static void loadItemPricesAndCalculate() throws ParseException, ClientProtocolException, IOException {
Integer playerCount = Bukkit.getServer().getOnlinePlayers().size();
if (Config.isUpdatePricesWhenInactive() || (!Config.isUpdatePricesWhenInactive() && playerCount > 0)){
Main.setupMaxBuySell();
Main.log("Loading Item Price Update Algorithm");
JSONObject obj = new JSONObject();
JSONArray itemData = new JSONArray();
Expand Down

0 comments on commit 2dbde4b

Please sign in to comment.