From 72aadee3e1214579ecab8a1bedc3c03e2b65aa79 Mon Sep 17 00:00:00 2001 From: Symt Date: Wed, 22 Jul 2020 00:52:10 -0500 Subject: [PATCH 1/3] Formula changed for determining best items --- build.gradle | 2 +- discord-bot/src/bazaar/bazaar.js | 6 +++--- discord-bot/src/bazaar/performance.js | 3 +-- src/main/java/dev/meyi/bn/BazaarNotifier.java | 8 ++++++-- src/main/java/dev/meyi/bn/handlers/EventHandler.java | 7 ++++--- src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java | 4 ++-- src/main/java/dev/meyi/bn/utilities/Suggester.java | 8 ++++---- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 03a0f12..5038af5 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ compileJava { sourceCompatibility = '1.8' targetCompatibility = '1.8' } -version = "1.2.1" +version = "1.2.2" group = "dev.meyi.bn" archivesBaseName = "BazaarNotifier" diff --git a/discord-bot/src/bazaar/bazaar.js b/discord-bot/src/bazaar/bazaar.js index 689a1a3..b5bdc4c 100644 --- a/discord-bot/src/bazaar/bazaar.js +++ b/discord-bot/src/bazaar/bazaar.js @@ -43,7 +43,7 @@ const Bazaar = (discordClient, text) => { Math.round( (data.sellOrderPrice * 0.99 - data.buyOrderPrice) * 100 ) / 100 - }\n**Max Profit Possible (coins/minute)**: ${ + }\n**Estimated Profit (coins/minute)**: ${ Math.round(data.profitFlowPerMinute * 100) / 100 }` ) @@ -103,7 +103,7 @@ const Bazaar = (discordClient, text) => { bazaarData.forEach((data) => { fields.push({ name: `${i++}. ${data.productId}`, - value: `MPP: ${Math.round(data.profitFlowPerMinute * 100) / 100}`, + value: `EP: ${Math.round(data.profitFlowPerMinute * 100) / 100}`, inline: true, }); if (i % 2 == 0) { @@ -114,7 +114,7 @@ const Bazaar = (discordClient, text) => { .setTitle("Bazaar") .setColor(Math.floor(Math.random() * 16777215)) .addFields(...fields) - .setFooter("MPP is Max Profit Possible (in coins/minute). It shows roughly how much money is flowing through an item every minute"); + .setFooter("EP is about how much money you'd make while flipping an item per minute of flipping. It assumes you miss no instants."); client.channels.cache.get(channel).send(embed); inRequest = false; } diff --git a/discord-bot/src/bazaar/performance.js b/discord-bot/src/bazaar/performance.js index 3886cf3..dfebee3 100644 --- a/discord-bot/src/bazaar/performance.js +++ b/discord-bot/src/bazaar/performance.js @@ -3,8 +3,7 @@ module.exports = bazaarData => { bazaarData.forEach(product => { let diff = product.sellOrderPrice * 0.99 - product.buyOrderPrice; - let profitFlowPerMinute = diff * Math.min(product.sellCount, product.buyCount) / (7 * 24 * 60); - product.profitFlowPerMinute = profitFlowPerMinute; + product.profitFlowPerMinute = (product.sellCount * product.buyCount)/(10080 * (product.sellCount + product.buyCount)) * diff; }); bazaarData.sort((a, b) => { diff --git a/src/main/java/dev/meyi/bn/BazaarNotifier.java b/src/main/java/dev/meyi/bn/BazaarNotifier.java index e668eee..c0a5281 100644 --- a/src/main/java/dev/meyi/bn/BazaarNotifier.java +++ b/src/main/java/dev/meyi/bn/BazaarNotifier.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.DecimalFormat; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; @@ -23,11 +24,13 @@ public class BazaarNotifier { public static final String MODID = "BazaarNotifier"; - public static final String VERSION = "1.2.1"; + public static final String VERSION = "1.2.2"; public static final String prefix = EnumChatFormatting.GOLD + "[BazaarNotifier] " + EnumChatFormatting.RESET; public static String apiKey = ""; + public static DecimalFormat df = new DecimalFormat("#,###.00"); + public static int X_POS = 5; public static int Y_POS = 5; public static int currentBoundsX; @@ -80,6 +83,7 @@ public void init(FMLInitializationEvent event) { ScheduledEvents.create(); Runtime.getRuntime() - .addShutdownHook(new Thread(() -> Utils.saveConfigFile(configFile, apiKey + "," + X_POS + "," + Y_POS))); + .addShutdownHook( + new Thread(() -> Utils.saveConfigFile(configFile, apiKey + "," + X_POS + "," + Y_POS))); } } diff --git a/src/main/java/dev/meyi/bn/handlers/EventHandler.java b/src/main/java/dev/meyi/bn/handlers/EventHandler.java index c012c25..660af74 100644 --- a/src/main/java/dev/meyi/bn/handlers/EventHandler.java +++ b/src/main/java/dev/meyi/bn/handlers/EventHandler.java @@ -166,9 +166,10 @@ public void renderBazaarEvent(BackgroundDrawnEvent e) { message.put(BazaarNotifier.bazaarDataFormatted.getJSONObject(i).getString("productId"), Color.CYAN); message.put(" - ", Color.GRAY); - message.put("" + (Math.round( - BazaarNotifier.bazaarDataFormatted.getJSONObject(i).getDouble("profitFlowPerMinute") - * 100) / 100), Color.ORANGE); + message.put("EP: ", Color.RED); + message.put("" + BazaarNotifier.df.format( + BazaarNotifier.bazaarDataFormatted.getJSONObject(i) + .getDouble("profitFlowPerMinute")), Color.ORANGE); items.add(message); } diff --git a/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java b/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java index 1a8cc32..f5cbb24 100644 --- a/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java +++ b/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java @@ -61,7 +61,7 @@ public void outdatedNotification() { + BazaarNotifier.bazaarConversions.get(key) + EnumChatFormatting.YELLOW + " OUTDATED " + EnumChatFormatting.GRAY + "(" - + EnumChatFormatting.DARK_PURPLE + price + + EnumChatFormatting.DARK_PURPLE + BazaarNotifier.df.format(price) + EnumChatFormatting.GRAY + ")" )); BazaarNotifier.orders.getJSONArray(key).remove(i); @@ -83,7 +83,7 @@ public void outdatedNotification() { + BazaarNotifier.bazaarConversions.get(key) + EnumChatFormatting.YELLOW + " OUTDATED " + EnumChatFormatting.GRAY + "(" - + EnumChatFormatting.BLUE + price + + EnumChatFormatting.BLUE + BazaarNotifier.df.format(price) + EnumChatFormatting.GRAY + ")" )); BazaarNotifier.orders.getJSONArray(key).remove(i); diff --git a/src/main/java/dev/meyi/bn/utilities/Suggester.java b/src/main/java/dev/meyi/bn/utilities/Suggester.java index 13a867b..4480a41 100644 --- a/src/main/java/dev/meyi/bn/utilities/Suggester.java +++ b/src/main/java/dev/meyi/bn/utilities/Suggester.java @@ -34,11 +34,11 @@ public static void basic() { bazaarData.getJSONObject(key).getJSONObject("quick_status") .getLong("sellMovingWeek")); - double diff = currentProduct.getDouble("sellOfferPrice") * .99 - currentProduct + double diff = currentProduct.getDouble("sellOfferPrice") * .99d - currentProduct .getDouble("buyOrderPrice"); double profitFlowPerMinute = - diff * Math.min(currentProduct.getLong("sellCount"), currentProduct.getLong("buyCount")) - / 10080; + ((currentProduct.getLong("sellCount") * currentProduct.getLong("buyCount")) / (10080d * ( + currentProduct.getLong("sellCount") + currentProduct.getLong("buyCount")))) * diff; bazaarDataFormatted.put(currentProduct.put("profitFlowPerMinute", profitFlowPerMinute)); } @@ -46,7 +46,7 @@ public static void basic() { JSONObject bazaarCache = new JSONObject(); bazaarDataFormatted.forEach((data) -> { - JSONObject jsonData = (JSONObject)data; + JSONObject jsonData = (JSONObject) data; bazaarCache.put(jsonData.getString("productId").toLowerCase(), data); }); From c4abcd7d9d7396ee0ab4840096fc46f0cd41c72e Mon Sep 17 00:00:00 2001 From: Symt Date: Wed, 22 Jul 2020 01:14:44 -0500 Subject: [PATCH 2/3] Fixed NaN bug in sort method --- discord-bot/src/bazaar/performance.js | 4 ++-- .../java/dev/meyi/bn/commands/BazaarNotifierCommand.java | 2 +- src/main/java/dev/meyi/bn/handlers/EventHandler.java | 2 +- src/main/java/dev/meyi/bn/utilities/Suggester.java | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/discord-bot/src/bazaar/performance.js b/discord-bot/src/bazaar/performance.js index dfebee3..1089316 100644 --- a/discord-bot/src/bazaar/performance.js +++ b/discord-bot/src/bazaar/performance.js @@ -3,9 +3,9 @@ module.exports = bazaarData => { bazaarData.forEach(product => { let diff = product.sellOrderPrice * 0.99 - product.buyOrderPrice; - product.profitFlowPerMinute = (product.sellCount * product.buyCount)/(10080 * (product.sellCount + product.buyCount)) * diff; + product.profitFlowPerMinute = ((product.sellCount + product.buyCount) === 0) ? 0 : (product.sellCount * product.buyCount)/(10080 * (product.sellCount + product.buyCount)) * diff; }); - + bazaarData.sort((a, b) => { return (b.profitFlowPerMinute - a.profitFlowPerMinute); }); diff --git a/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java b/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java index 3db3c31..c88432d 100644 --- a/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java +++ b/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java @@ -64,7 +64,7 @@ public void processCommand(ICommandSender ics, String[] args) { BazaarNotifier.render ^= true; player.addChatMessage(new ChatComponentText( BazaarNotifier.prefix + EnumChatFormatting.RED + "Suggestions have been turned " - + EnumChatFormatting.DARK_RED + (BazaarNotifier.activeBazaar ? "on" : "off"))); + + EnumChatFormatting.DARK_RED + (BazaarNotifier.render ? "on" : "off"))); } else if (args.length > 0) { player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED + "The command you just tried to do doesn't work")); diff --git a/src/main/java/dev/meyi/bn/handlers/EventHandler.java b/src/main/java/dev/meyi/bn/handlers/EventHandler.java index 660af74..e639a68 100644 --- a/src/main/java/dev/meyi/bn/handlers/EventHandler.java +++ b/src/main/java/dev/meyi/bn/handlers/EventHandler.java @@ -150,7 +150,7 @@ public void run() { @SubscribeEvent public void renderBazaarEvent(BackgroundDrawnEvent e) { - if (e.gui instanceof GuiChest && BazaarNotifier.render) { + if (e.gui instanceof GuiChest && BazaarNotifier.render && BazaarNotifier.bazaarDataFormatted.length() != 0) { IInventory chestInventory = ((GuiChest) e.gui).lowerChestInventory; if (chestInventory.hasCustomName()) { if (Utils.stripString(chestInventory.getDisplayName().getUnformattedText()) diff --git a/src/main/java/dev/meyi/bn/utilities/Suggester.java b/src/main/java/dev/meyi/bn/utilities/Suggester.java index 4480a41..28e5748 100644 --- a/src/main/java/dev/meyi/bn/utilities/Suggester.java +++ b/src/main/java/dev/meyi/bn/utilities/Suggester.java @@ -37,8 +37,10 @@ public static void basic() { double diff = currentProduct.getDouble("sellOfferPrice") * .99d - currentProduct .getDouble("buyOrderPrice"); double profitFlowPerMinute = - ((currentProduct.getLong("sellCount") * currentProduct.getLong("buyCount")) / (10080d * ( - currentProduct.getLong("sellCount") + currentProduct.getLong("buyCount")))) * diff; + (currentProduct.getLong("sellCount") + currentProduct.getLong("buyCount") == 0) ? 0 : + ((currentProduct.getLong("sellCount") * currentProduct.getLong("buyCount")) / (10080d + * (currentProduct.getLong("sellCount") + currentProduct.getLong("buyCount")))) + * diff; bazaarDataFormatted.put(currentProduct.put("profitFlowPerMinute", profitFlowPerMinute)); } From f3d714283bbbdee878dbf0b4a7a1326cb7106cb0 Mon Sep 17 00:00:00 2001 From: Symt Date: Wed, 22 Jul 2020 16:42:20 -0500 Subject: [PATCH 3/3] Rest of 1.2.2 --- src/main/java/dev/meyi/bn/BazaarNotifier.java | 24 ++++-- .../bn/commands/BazaarNotifierCommand.java | 34 ++++++++- .../dev/meyi/bn/handlers/EventHandler.java | 9 ++- .../dev/meyi/bn/handlers/MouseHandler.java | 8 +- .../dev/meyi/bn/handlers/UpdateHandler.java | 69 ++++++++++++++++++ .../java/dev/meyi/bn/utilities/Defaults.java | 9 +++ .../meyi/bn/utilities/ScheduledEvents.java | 73 +++++++++++-------- .../java/dev/meyi/bn/utilities/Utils.java | 6 ++ .../resources/bazaarConversionsReversed.json | 2 +- 9 files changed, 183 insertions(+), 51 deletions(-) create mode 100644 src/main/java/dev/meyi/bn/handlers/UpdateHandler.java create mode 100644 src/main/java/dev/meyi/bn/utilities/Defaults.java diff --git a/src/main/java/dev/meyi/bn/BazaarNotifier.java b/src/main/java/dev/meyi/bn/BazaarNotifier.java index c0a5281..db22f33 100644 --- a/src/main/java/dev/meyi/bn/BazaarNotifier.java +++ b/src/main/java/dev/meyi/bn/BazaarNotifier.java @@ -3,6 +3,8 @@ import dev.meyi.bn.commands.BazaarNotifierCommand; import dev.meyi.bn.handlers.EventHandler; import dev.meyi.bn.handlers.MouseHandler; +import dev.meyi.bn.handlers.UpdateHandler; +import dev.meyi.bn.utilities.Defaults; import dev.meyi.bn.utilities.ScheduledEvents; import dev.meyi.bn.utilities.Utils; import java.io.File; @@ -29,10 +31,10 @@ public class BazaarNotifier { EnumChatFormatting.GOLD + "[BazaarNotifier] " + EnumChatFormatting.RESET; public static String apiKey = ""; - public static DecimalFormat df = new DecimalFormat("#,###.00"); + public static DecimalFormat df = new DecimalFormat("#,###.0"); - public static int X_POS = 5; - public static int Y_POS = 5; + public static int suggestionModuleX = Defaults.DEFAULT_SUGGESTION_MODULE_X; + public static int suggestionModuleY = Defaults.DEFAULT_SUGGESTION_MODULE_Y; public static int currentBoundsX; public static int currentBoundsY; @@ -53,6 +55,15 @@ public class BazaarNotifier { public static File configFile; + /** + * Resets the location of all of the modules and clears all stored user preferences or orders + */ + public static void resetMod() { + suggestionModuleX = Defaults.DEFAULT_SUGGESTION_MODULE_X; + suggestionModuleY = Defaults.DEFAULT_SUGGESTION_MODULE_Y; + orders = Defaults.DEFAULT_ORDERS_LAYOUT; + } + @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { configFile = event.getSuggestedConfigurationFile(); @@ -65,8 +76,8 @@ public void preInit(FMLPreInitializationEvent event) { apiKey = splitConfig[0]; } else if (splitConfig.length == 3) { apiKey = splitConfig[0]; - X_POS = Integer.parseInt(splitConfig[1]); - Y_POS = Integer.parseInt(splitConfig[2]); + suggestionModuleX = Integer.parseInt(splitConfig[1]); + suggestionModuleY = Integer.parseInt(splitConfig[2]); } } catch (IOException e) { e.printStackTrace(); @@ -79,11 +90,12 @@ public void preInit(FMLPreInitializationEvent event) { public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new EventHandler()); MinecraftForge.EVENT_BUS.register(new MouseHandler()); + MinecraftForge.EVENT_BUS.register(new UpdateHandler()); ClientCommandHandler.instance.registerCommand(new BazaarNotifierCommand()); ScheduledEvents.create(); Runtime.getRuntime() .addShutdownHook( - new Thread(() -> Utils.saveConfigFile(configFile, apiKey + "," + X_POS + "," + Y_POS))); + new Thread(() -> Utils.saveConfigFile(configFile, apiKey + "," + suggestionModuleX + "," + suggestionModuleY))); } } diff --git a/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java b/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java index c88432d..6f1a1e3 100644 --- a/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java +++ b/src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java @@ -8,6 +8,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import org.apache.commons.lang3.text.WordUtils; import org.json.JSONObject; public class BazaarNotifierCommand extends CommandBase { @@ -56,21 +57,46 @@ public void processCommand(ICommandSender ics, String[] args) { System.out.println(BazaarNotifier.orders); player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED + "Orders dumped to the log file")); - } else if (args.length == 1 && args[0].equalsIgnoreCase("empty")) { - BazaarNotifier.orders = new JSONObject(); + } else if (args.length == 1 && args[0].equalsIgnoreCase("reset")) { + BazaarNotifier.resetMod(); player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED - + "Order list was emptied")); + + "All module locations have been reset and the order list has been emptied")); } else if (args.length == 1 && args[0].equalsIgnoreCase("suggest")) { BazaarNotifier.render ^= true; player.addChatMessage(new ChatComponentText( BazaarNotifier.prefix + EnumChatFormatting.RED + "Suggestions have been turned " + EnumChatFormatting.DARK_RED + (BazaarNotifier.render ? "on" : "off"))); + } else if (args.length >= 1 && args[0].equalsIgnoreCase("find")) { + if (args.length == 1) { + player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED + "Use the following format: /bn find (item)")); + } else { + String item = String.join(" ", args).substring(5).toLowerCase(); + if (BazaarNotifier.bazaarCache.has(item)) { + JSONObject data = BazaarNotifier.bazaarCache.getJSONObject(item); + player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + "\n" + + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + WordUtils.capitalize(item) + "\n" + + EnumChatFormatting.DARK_RED + "Buy Order: " + EnumChatFormatting.RED + + BazaarNotifier.df.format(data.getDouble("buyOrderPrice")) + "\n" + + EnumChatFormatting.DARK_RED + "Sell Offer: " + + EnumChatFormatting.RED + + BazaarNotifier.df.format(data.getDouble("sellOfferPrice")) + "\n" + + EnumChatFormatting.DARK_RED + + "Estimated Profit: " + EnumChatFormatting.RED + + BazaarNotifier.df.format(data.getDouble("profitFlowPerMinute")) + "\n" + + BazaarNotifier.prefix + )); + } else { + player.addChatMessage(new ChatComponentText( + BazaarNotifier.prefix + EnumChatFormatting.RED + + "Please provide a valid item to find.")); + } + } } else if (args.length > 0) { player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED + "The command you just tried to do doesn't work")); } else { player.addChatMessage(new ChatComponentText(BazaarNotifier.prefix + "\n" + - EnumChatFormatting.RED + "/bn dump\n" + EnumChatFormatting.RED + "/bn empty\n" + EnumChatFormatting.RED + "/bn dump\n" + EnumChatFormatting.RED + "/bn reset\n" + EnumChatFormatting.RED + "/bn api (key)\n\n" + EnumChatFormatting.RED + "/bn toggle\n" + EnumChatFormatting.RED + "/bn suggest\n" + BazaarNotifier.prefix diff --git a/src/main/java/dev/meyi/bn/handlers/EventHandler.java b/src/main/java/dev/meyi/bn/handlers/EventHandler.java index e639a68..bbdbc0d 100644 --- a/src/main/java/dev/meyi/bn/handlers/EventHandler.java +++ b/src/main/java/dev/meyi/bn/handlers/EventHandler.java @@ -150,7 +150,8 @@ public void run() { @SubscribeEvent public void renderBazaarEvent(BackgroundDrawnEvent e) { - if (e.gui instanceof GuiChest && BazaarNotifier.render && BazaarNotifier.bazaarDataFormatted.length() != 0) { + if (e.gui instanceof GuiChest && BazaarNotifier.render + && BazaarNotifier.bazaarDataFormatted.length() != 0) { IInventory chestInventory = ((GuiChest) e.gui).lowerChestInventory; if (chestInventory.hasCustomName()) { if (Utils.stripString(chestInventory.getDisplayName().getUnformattedText()) @@ -177,7 +178,7 @@ public void renderBazaarEvent(BackgroundDrawnEvent e) { for (int i = 0; i < items.size(); i++) { int length = ColorUtils .drawMulticoloredString(Minecraft.getMinecraft().fontRendererObj, - BazaarNotifier.X_POS, BazaarNotifier.Y_POS + BazaarNotifier.suggestionModuleX, BazaarNotifier.suggestionModuleY + (Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT + 2) * i, items.get(i), false); @@ -185,8 +186,8 @@ public void renderBazaarEvent(BackgroundDrawnEvent e) { longestXString = length; } } - BazaarNotifier.currentBoundsX = BazaarNotifier.X_POS + longestXString; - BazaarNotifier.currentBoundsY = BazaarNotifier.Y_POS + BazaarNotifier.currentBoundsX = BazaarNotifier.suggestionModuleX + longestXString; + BazaarNotifier.currentBoundsY = BazaarNotifier.suggestionModuleY + (Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT) * (items.size()) + 2 * ( items.size() - 1); } diff --git a/src/main/java/dev/meyi/bn/handlers/MouseHandler.java b/src/main/java/dev/meyi/bn/handlers/MouseHandler.java index ba84df4..85ccfb7 100644 --- a/src/main/java/dev/meyi/bn/handlers/MouseHandler.java +++ b/src/main/java/dev/meyi/bn/handlers/MouseHandler.java @@ -27,8 +27,8 @@ public void mouseActionCheck(TickEvent e) { int shiftedX = getMouseCoordinateX() - x; int shiftedY = getMouseCoordinateY() - y; - BazaarNotifier.X_POS += shiftedX; - BazaarNotifier.Y_POS += shiftedY; + BazaarNotifier.suggestionModuleX += shiftedX; + BazaarNotifier.suggestionModuleY += shiftedY; } x = getMouseCoordinateX(); y = getMouseCoordinateY(); @@ -48,8 +48,8 @@ private int getMouseCoordinateY() { } private boolean inMovementBox() { - return (getMouseCoordinateX() >= BazaarNotifier.X_POS - && getMouseCoordinateY() >= BazaarNotifier.Y_POS + return (getMouseCoordinateX() >= BazaarNotifier.suggestionModuleX + && getMouseCoordinateY() >= BazaarNotifier.suggestionModuleY && getMouseCoordinateX() <= BazaarNotifier.currentBoundsX && getMouseCoordinateY() <= BazaarNotifier.currentBoundsY); } diff --git a/src/main/java/dev/meyi/bn/handlers/UpdateHandler.java b/src/main/java/dev/meyi/bn/handlers/UpdateHandler.java new file mode 100644 index 0000000..d5da4e1 --- /dev/null +++ b/src/main/java/dev/meyi/bn/handlers/UpdateHandler.java @@ -0,0 +1,69 @@ +package dev.meyi.bn.handlers; + +import dev.meyi.bn.BazaarNotifier; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import net.minecraft.client.Minecraft; +import net.minecraft.event.ClickEvent; +import net.minecraft.event.ClickEvent.Action; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.network.FMLNetworkEvent; +import org.apache.commons.io.IOUtils; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.HttpClientBuilder; +import org.json.JSONObject; + +public class UpdateHandler { + + boolean firstJoin = true; + + @SubscribeEvent + public void onPlayerJoinEvent(FMLNetworkEvent.ClientConnectedToServerEvent event) { + if (firstJoin) { + firstJoin = false; + new ScheduledThreadPoolExecutor(1).schedule(() -> { + try { + JSONObject json = new JSONObject(IOUtils.toString(new BufferedReader + (new InputStreamReader( + HttpClientBuilder.create().build().execute(new HttpGet( + "https://api.github.com/repos/symt/BazaarNotifier/releases/latest")) + .getEntity().getContent())))); + String[] latestTag = json.getString("tag_name").split("\\."); + String[] currentTag = BazaarNotifier.VERSION.split("\\."); + + if (latestTag.length == 3 && currentTag.length == 3) { + for (int i = 0; i < latestTag.length; i++) { + if (latestTag[i].compareTo(currentTag[i]) != 0) { + if (latestTag[i].compareTo(currentTag[i]) <= -1) { + Minecraft.getMinecraft().thePlayer.addChatMessage( + new ChatComponentText(BazaarNotifier.prefix + EnumChatFormatting.RED + + "This version hasn't been released yet. Please report any bugs that you come across.")); + } else if (latestTag[i].compareTo(currentTag[i]) >= 1) { + ChatComponentText updateLink = new ChatComponentText( + EnumChatFormatting.DARK_RED + "" + EnumChatFormatting.BOLD + + "[UPDATE LINK]"); + updateLink + .setChatStyle(updateLink.getChatStyle().setChatClickEvent(new ClickEvent( + Action.OPEN_URL, + "https://github.com/symt/BazaarNotifier/releases/latest"))); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + BazaarNotifier.prefix + EnumChatFormatting.RED + + "The mod version that you're on is outdated. Please update for the best profits: ") + .appendSibling(updateLink)); + } + break; + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + }, 3, TimeUnit.SECONDS); + } + } +} diff --git a/src/main/java/dev/meyi/bn/utilities/Defaults.java b/src/main/java/dev/meyi/bn/utilities/Defaults.java new file mode 100644 index 0000000..3a05be0 --- /dev/null +++ b/src/main/java/dev/meyi/bn/utilities/Defaults.java @@ -0,0 +1,9 @@ +package dev.meyi.bn.utilities; + +import org.json.JSONObject; + +public class Defaults { + public static final int DEFAULT_SUGGESTION_MODULE_X = 5; + public static final int DEFAULT_SUGGESTION_MODULE_Y = 10; + public static final JSONObject DEFAULT_ORDERS_LAYOUT = new JSONObject(); +} diff --git a/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java b/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java index f5cbb24..b6e31c2 100644 --- a/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java +++ b/src/main/java/dev/meyi/bn/utilities/ScheduledEvents.java @@ -26,7 +26,8 @@ public static void create() { } public void suggestionLoop() { - Executors.newScheduledThreadPool(1).scheduleAtFixedRate(Suggester::basic, 5, 5, TimeUnit.SECONDS); + Executors.newScheduledThreadPool(1) + .scheduleAtFixedRate(Suggester::basic, 5, 5, TimeUnit.SECONDS); } public void outdatedNotification() { @@ -46,46 +47,36 @@ public void outdatedNotification() { .getDouble("price"); if (BazaarNotifier.orders.getJSONArray(key).getJSONObject(i).getString("type") .equals("buy")) { - // Buy if (BazaarNotifier.bazaarDataRaw.getJSONObject(key).getJSONArray("sell_summary") - .getJSONObject(0) - .getDouble("pricePerUnit") - price > 0) { + .getJSONObject(0).getInt("orders") != 1 && + BazaarNotifier.bazaarDataRaw.getJSONObject(key).getJSONArray("sell_summary") + .getJSONObject(0) + .getDouble("pricePerUnit") == price) { + Minecraft.getMinecraft().thePlayer + .addChatMessage(chatNotification(key, price, i, "Buy Order", "MATCHED")); + } else if ( + BazaarNotifier.bazaarDataRaw.getJSONObject(key).getJSONArray("sell_summary") + .getJSONObject(0) + .getDouble("pricePerUnit") - price > 0) { Minecraft.getMinecraft().thePlayer - .addChatMessage(new ChatComponentText( - EnumChatFormatting.DARK_PURPLE + "Buy Order" - + EnumChatFormatting.GRAY + " for " - + EnumChatFormatting.DARK_PURPLE + BazaarNotifier.orders - .getJSONArray(key) - .getJSONObject(i).getString("product").split("x")[0] - + EnumChatFormatting.GRAY + "x " + EnumChatFormatting.DARK_PURPLE - + BazaarNotifier.bazaarConversions.get(key) - + EnumChatFormatting.YELLOW - + " OUTDATED " + EnumChatFormatting.GRAY + "(" - + EnumChatFormatting.DARK_PURPLE + BazaarNotifier.df.format(price) - + EnumChatFormatting.GRAY + ")" - )); + .addChatMessage(chatNotification(key, price, i, "Buy Order", "OUTDATED")); BazaarNotifier.orders.getJSONArray(key).remove(i); } } else { - // Sell - if (price - BazaarNotifier.bazaarDataRaw.getJSONObject(key) + if (BazaarNotifier.bazaarDataRaw.getJSONObject(key).getJSONArray("buy_summary") + .getJSONObject(0).getInt("orders") != 1 && + BazaarNotifier.bazaarDataRaw.getJSONObject(key).getJSONArray("buy_summary") + .getJSONObject(0) + .getDouble("pricePerUnit") == price) { + Minecraft.getMinecraft().thePlayer + .addChatMessage(chatNotification(key, price, i, "Sell Offer", "MATCHED")); + } else if (price - BazaarNotifier.bazaarDataRaw.getJSONObject(key) .getJSONArray("buy_summary") .getJSONObject(0) .getDouble("pricePerUnit") > 0) { Minecraft.getMinecraft().thePlayer - .addChatMessage(new ChatComponentText( - EnumChatFormatting.BLUE + "Sell Offer" - + EnumChatFormatting.GRAY + " of " - + EnumChatFormatting.BLUE + BazaarNotifier.orders - .getJSONArray(key) - .getJSONObject(i).getString("product").split("x")[0] - + EnumChatFormatting.GRAY + "x " + EnumChatFormatting.BLUE - + BazaarNotifier.bazaarConversions.get(key) - + EnumChatFormatting.YELLOW - + " OUTDATED " + EnumChatFormatting.GRAY + "(" - + EnumChatFormatting.BLUE + BazaarNotifier.df.format(price) - + EnumChatFormatting.GRAY + ")" - )); + .addChatMessage( + chatNotification(key, price, i, "Sell Offer", "OUTDATED")); BazaarNotifier.orders.getJSONArray(key).remove(i); } } @@ -103,4 +94,22 @@ public void outdatedNotification() { } }, 0, 2, TimeUnit.SECONDS); } + + + private ChatComponentText chatNotification(String key, double price, int i, String type, + String notification) { + return new ChatComponentText( + EnumChatFormatting.DARK_PURPLE + type + + EnumChatFormatting.GRAY + " for " + + EnumChatFormatting.DARK_PURPLE + BazaarNotifier.orders + .getJSONArray(key) + .getJSONObject(i).getString("product").split("x")[0] + + EnumChatFormatting.GRAY + "x " + EnumChatFormatting.DARK_PURPLE + + BazaarNotifier.bazaarConversions.get(key) + + EnumChatFormatting.YELLOW + + " " + notification + " " + EnumChatFormatting.GRAY + "(" + + EnumChatFormatting.DARK_PURPLE + BazaarNotifier.df.format(price) + + EnumChatFormatting.GRAY + ")" + ); + } } diff --git a/src/main/java/dev/meyi/bn/utilities/Utils.java b/src/main/java/dev/meyi/bn/utilities/Utils.java index 076a466..60753eb 100644 --- a/src/main/java/dev/meyi/bn/utilities/Utils.java +++ b/src/main/java/dev/meyi/bn/utilities/Utils.java @@ -106,4 +106,10 @@ public static JSONArray sortJSONArray(JSONArray jsonArr, String key) { } return sortedJsonArray; } + + public static boolean updateChecker() { + + + return false; + } } diff --git a/src/main/resources/bazaarConversionsReversed.json b/src/main/resources/bazaarConversionsReversed.json index 26eb973..8415903 100644 --- a/src/main/resources/bazaarConversionsReversed.json +++ b/src/main/resources/bazaarConversionsReversed.json @@ -60,7 +60,7 @@ "Enchanted Brown Mushroom Block": "ENCHANTED_HUGE_MUSHROOM_1", "Super Compactor 3000": "SUPER_COMPACTOR_3000", "Enchanted Iron": "ENCHANTED_IRON", - "Super Egg": "SUPER_EGG", + "Super Enchanted Egg": "SUPER_EGG", "Stock Of Stonks": "STOCK_OF_STONKS", "Enchanted Cobblestone": "ENCHANTED_COBBLESTONE", "Enchanted Bone": "ENCHANTED_BONE",