Skip to content

Commit

Permalink
1.6.1: Improved Conversions and Important Bug Fixes (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
symt authored Dec 23, 2022
1 parent a236ac3 commit 02114fb
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 147 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "dev.meyi.bazaarnotifier"
version = "1.6.0"
version = "1.6.1"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/meyi/bn/BazaarNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.meyi.bn.json.Order;
import dev.meyi.bn.json.resp.BazaarResponse;
import dev.meyi.bn.modules.ModuleList;
import dev.meyi.bn.modules.calc.BankCalculator;
import dev.meyi.bn.utilities.ReflectionHelper;
import dev.meyi.bn.utilities.ScheduledEvents;
import dev.meyi.bn.utilities.Utils;
Expand All @@ -41,7 +42,7 @@
public class BazaarNotifier {

public static final String MODID = "BazaarNotifier";
public static final String VERSION = "1.6.0";
public static final String VERSION = "1.6.1";
public static final String prefix =
EnumChatFormatting.GOLD + "[" + EnumChatFormatting.YELLOW + "BN" + EnumChatFormatting.GOLD
+ "] " + EnumChatFormatting.RESET;
Expand Down Expand Up @@ -152,6 +153,8 @@ public void preInit(FMLPreInitializationEvent event) {
enchantCraftingList = resources.getAsJsonObject("enchantCraftingList");
bazaarConv = Utils.jsonToBimap(bazaarConversions);
}

BankCalculator.reset();
}


Expand Down
2 changes: 0 additions & 2 deletions src/main/java/dev/meyi/bn/commands/BazaarNotifierCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public void processCommand(ICommandSender ics, String[] args) {
BazaarNotifier.config.api = args[1];
BazaarNotifier.validApiKey = true;
BazaarNotifier.activeBazaar = true;
CraftingCalculator.getUnlockedRecipes();
BazaarNotifier.config.collectionCheckDisabled = false;
} else {
player.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/dev/meyi/bn/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import dev.meyi.bn.BazaarNotifier;
import dev.meyi.bn.modules.ModuleName;
import dev.meyi.bn.modules.calc.BankCalculator;
import dev.meyi.bn.utilities.Defaults;
import java.io.File;
import java.io.IOException;
Expand All @@ -14,7 +15,7 @@ public class Configuration {

private static final int MODULE_LENGTH = 4;

public boolean collectionCheckDisabled;
public boolean collectionCheck;
public int craftingSortingOption;
public int craftingListLength;
public int suggestionListLength;
Expand All @@ -25,23 +26,26 @@ public class Configuration {
public String version;
public ModuleConfig[] modules;

public double bazaarProfit = 0;

private boolean showInstantSellProfit;
private boolean showSellOfferProfit;
private boolean showProfitPerMil;

public Configuration(boolean collectionCheckDisabled, int craftingSortingOption,
public Configuration(boolean collectionCheck, int craftingSortingOption,
int craftingListLength, boolean suggestionShowEnchantments,
boolean showInstantSellProfit, boolean showSellOfferProfit, boolean showProfitPerMil,
int suggestionListLength, boolean showChatMessages, String apiKey, boolean useBuyOrders,
int suggestionListLength, boolean showChatMessages, String apiKey, boolean useBuyOrders, double bazaarProfit,
ModuleConfig[] modules) {
this.collectionCheckDisabled = collectionCheckDisabled;
this.collectionCheck = collectionCheck;
this.craftingSortingOption = craftingSortingOption;
this.craftingListLength = craftingListLength;
this.suggestionShowEnchantments = suggestionShowEnchantments;
this.showInstantSellProfit = showInstantSellProfit;
this.showSellOfferProfit = showSellOfferProfit;
this.showProfitPerMil = showProfitPerMil;
this.suggestionListLength = suggestionListLength;
this.bazaarProfit = bazaarProfit;
this.api =
apiKey == null ? "" : apiKey; // It is fixed in createDefaultConfig, but redundancies.
this.version = BazaarNotifier.VERSION;
Expand All @@ -54,6 +58,7 @@ public Configuration(boolean collectionCheckDisabled, int craftingSortingOption,
public static void saveConfig(File file, Configuration config) {
Gson gson = new Gson();
BazaarNotifier.config.modules = BazaarNotifier.modules.generateConfig();
BazaarNotifier.config.bazaarProfit = BankCalculator.getBazaarProfit();
try {
if (!file.isFile()) {
//noinspection ResultOfMethodCallIgnored
Expand All @@ -72,12 +77,12 @@ public static Configuration createDefaultConfig() {
for (ModuleName moduleName : ModuleName.values()) {
c[i++] = ModuleConfig.generateDefaultConfig(moduleName.name());
}
return new Configuration(Defaults.COLLECTION_CHECKING_DISABLED,
return new Configuration(Defaults.COLLECTION_CHECKING,
Defaults.CRAFTING_SORTING_OPTION, Defaults.CRAFTING_LIST_LENGTH,
Defaults.SUGGESTION_SHOW_ENCHANTMENTS,
Defaults.INSTANT_SELL_PROFIT, Defaults.SELL_OFFER_PROFIT,
Defaults.PROFIT_PER_MIL, Defaults.SUGGESTION_LIST_LENGTH, Defaults.SEND_CHAT_MESSAGES, "",
Defaults.USE_BUY_ORDERS, c);
Defaults.USE_BUY_ORDERS, 0, c);
}

public boolean isShowSellOfferProfit() {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/dev/meyi/bn/gui/ModuleSettingsGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void initGui() {
100, BazaarNotifier.config.craftingListLength, false, true));
buttonList.add(new GuiButton(ButtonIds.COLLECTION_CHECK.id, getButtonX(),
getButtonY(), "Collection Check: " +
SettingsGui.getOnOff(!BazaarNotifier.config.collectionCheckDisabled)));
SettingsGui.getOnOff(BazaarNotifier.config.collectionCheck)));
if (!BazaarNotifier.validApiKey) {
buttonList.get(3).enabled = false;
}
Expand Down Expand Up @@ -87,16 +87,17 @@ protected void actionPerformed(GuiButton Button) {
BazaarNotifier.config.craftingListLength = (int) Math.round(lengthSlider.getValue());
}
} else if (Button.id == ButtonIds.COLLECTION_CHECK.id) {
BazaarNotifier.config.collectionCheckDisabled ^= true;
BazaarNotifier.config.collectionCheck ^= true;
Button.displayString =
"Collection Check: " + SettingsGui.getOnOff(!BazaarNotifier.config.collectionCheckDisabled);
"Collection Check: " + SettingsGui.getOnOff(BazaarNotifier.config.collectionCheck);

if (!BazaarNotifier.config.collectionCheckDisabled) {
if (BazaarNotifier.config.collectionCheck) {
new Thread(() -> {
CraftingCalculator.getUnlockedRecipes();
Button.displayString =
"Collection Check: " + SettingsGui.getOnOff(!BazaarNotifier.config.collectionCheckDisabled);
if (BazaarNotifier.config.collectionCheckDisabled) {
"Collection Check: " + SettingsGui.getOnOff(
BazaarNotifier.config.collectionCheck);
if (!BazaarNotifier.config.collectionCheck) {
Minecraft.getMinecraft().thePlayer
.addChatMessage(new ChatComponentText(BazaarNotifier.prefix +
EnumChatFormatting.RED
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/dev/meyi/bn/handlers/ChestTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import dev.meyi.bn.BazaarNotifier;
import dev.meyi.bn.json.Order;
import dev.meyi.bn.modules.calc.BankCalculator;
import dev.meyi.bn.utilities.ReflectionHelper;
import dev.meyi.bn.utilities.Utils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
Expand All @@ -27,7 +25,6 @@
public class ChestTickHandler {

public static String lastScreenDisplayName = "";
private static long date = System.currentTimeMillis();

// /blockdata x y z {CustomName:"___"} << For Custom Chest Name Testing

Expand Down Expand Up @@ -179,21 +176,33 @@ private void orderConfirmation(IInventory chest) {

String product = StringUtils.stripControlCodes(
chest.getStackInSlot(13).getTagCompound().getCompoundTag("display").getTagList("Lore", 8)
.getStringTagAt(4)).split("x ")[1];
.getStringTagAt(4)).split("x ", 2)[1];

String productName;

if (!BazaarNotifier.bazaarConv.containsValue(product)) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
+ "The bazaar item you just put an order for doesn't exist. Please report this in the discord server"));
if (System.currentTimeMillis() > date + (60 * 60 * 1000)) {
try {
Utils.updateResources();
} catch (IOException ignored) {
}
String[] possibleConversion = Utils.getItemIdFromName(product);
productName = possibleConversion[1];

if (!possibleConversion[0].equals(product) && !productName.isEmpty()) {
BazaarNotifier.bazaarConv.put(productName, product);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
+ "A possible conversion was found. Please report this to the discord server:"
+ EnumChatFormatting.GRAY + " \""
+ productName + "\" - \"" + product + "\" \"" + possibleConversion[0] + "\"."));
} else {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
+ "No item conversion was found for that item. Please report this to the discord server: "
+ EnumChatFormatting.GRAY + "\""
+ product + "\"."));
}
date = System.currentTimeMillis();
} else {
String productName = BazaarNotifier.bazaarConv.inverse().get(product);
productName = BazaarNotifier.bazaarConv.inverse().get(product);
}

if (BazaarNotifier.bazaarConv.containsKey(productName)) {
String productWithAmount = StringUtils.stripControlCodes(
chest.getStackInSlot(13).getTagCompound().getCompoundTag("display")
.getTagList("Lore", 8).getStringTagAt(4)).split(": ")[1];
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/dev/meyi/bn/handlers/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ public void bazaarChatHandler(ClientChatReceivedEvent e) {
BazaarNotifier.config.api = apiKey;
BazaarNotifier.validApiKey = true;
BazaarNotifier.activeBazaar = true;
CraftingCalculator.getUnlockedRecipes();
BazaarNotifier.config.collectionCheckDisabled = false;
} else {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
BazaarNotifier.prefix + EnumChatFormatting.RED
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/meyi/bn/json/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public boolean matchesOrder(Exchange exchange) {
}

public boolean canCraft() {
return BazaarNotifier.enchantCraftingList.getAsJsonObject("other").has(productId)
&& type == OrderType.SELL;
return type == OrderType.SELL && BazaarNotifier.enchantCraftingList.getAsJsonObject("other")
.has(productId);
}

@Override
Expand Down
Loading

0 comments on commit 02114fb

Please sign in to comment.