Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.2.2: Find & Better Function Profit #9

Merged
merged 3 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions discord-bot/src/bazaar/bazaar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}`
)
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions discord-bot/src/bazaar/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
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) === 0) ? 0 : (product.sellCount * product.buyCount)/(10080 * (product.sellCount + product.buyCount)) * diff;
});

bazaarData.sort((a, b) => {
return (b.profitFlowPerMinute - a.profitFlowPerMinute);
});
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/dev/meyi/bn/BazaarNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
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;
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;
Expand All @@ -23,13 +26,15 @@
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 int X_POS = 5;
public static int Y_POS = 5;
public static DecimalFormat df = new DecimalFormat("#,###.0");

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;

Expand All @@ -50,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();
Expand All @@ -62,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();
Expand All @@ -76,10 +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)));
.addShutdownHook(
new Thread(() -> Utils.saveConfigFile(configFile, apiKey + "," + suggestionModuleX + "," + suggestionModuleY)));
}
}
36 changes: 31 additions & 5 deletions src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.activeBazaar ? "on" : "off")));
+ 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
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/dev/meyi/bn/handlers/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ 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())
Expand All @@ -166,26 +167,27 @@ 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);
}

int longestXString = 0;
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);

if (length > longestXString) {
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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/meyi/bn/handlers/MouseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/dev/meyi/bn/handlers/UpdateHandler.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/dev/meyi/bn/utilities/Defaults.java
Original file line number Diff line number Diff line change
@@ -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();
}
Loading