Skip to content

Commit

Permalink
Merge pull request #884 from VeritasDL/bleeding-edge-bz
Browse files Browse the repository at this point in the history
BazaarLookup Small Edit
  • Loading branch information
kevinthegreat1 authored Sep 6, 2024
2 parents f7c414a + bbfc102 commit 5ed09f8
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,19 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.helpers.bazaar.enableBazaarLookup"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.helpers.bazaar.enableBazaarLookup.@Tooltip")))
.binding(defaults.helpers.bazaar.enableBazaarLookup,
() -> config.helpers.bazaar.enableBazaarLookup,
newValue -> config.helpers.bazaar.enableBazaarLookup = newValue)
.name(Text.translatable("skyblocker.config.helpers.itemPrice.enableItemPriceLookup"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.helpers.itemPrice.enableItemPriceLookup.@Tooltip")))
.binding(defaults.helpers.itemPrice.enableItemPriceLookup,
() -> config.helpers.itemPrice.enableItemPriceLookup,
newValue -> config.helpers.itemPrice.enableItemPriceLookup = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.helpers.bazaar.enableRefreshItemPrices"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.helpers.bazaar.enableRefreshItemPrices.@Tooltip")))
.binding(defaults.helpers.bazaar.enableBazaarRefresh,
() -> config.helpers.bazaar.enableBazaarRefresh,
newValue -> config.helpers.bazaar.enableBazaarRefresh = newValue)
.name(Text.translatable("skyblocker.config.helpers.itemPrice.enableItemPriceRefresh"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.helpers.itemPrice.enableItemPriceRefresh.@Tooltip")))
.binding(defaults.helpers.itemPrice.enableItemPriceRefresh,
() -> config.helpers.itemPrice.enableItemPriceRefresh,
newValue -> config.helpers.itemPrice.enableItemPriceRefresh = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(ConfigUtils.createShortcutToKeybindsScreen())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class HelperConfig {
@SerialEntry
public Bazaar bazaar = new Bazaar();

@SerialEntry
public ItemPrice itemPrice = new ItemPrice();

public static class MythologicalRitual {
@SerialEntry
public boolean enableMythologicalRitualHelper = true;
Expand Down Expand Up @@ -101,11 +104,13 @@ public static class ChocolateFactory {
public static class Bazaar {
@SerialEntry
public boolean enableBazaarHelper = true;
}

public static class ItemPrice {
@SerialEntry
public boolean enableBazaarLookup = true;
public boolean enableItemPriceLookup = true;

@SerialEntry
public boolean enableBazaarRefresh = true;
public boolean enableItemPriceRefresh = true;
}
}
16 changes: 6 additions & 10 deletions src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.PetCache;
import de.hysky.skyblocker.skyblock.bazaar.BazaarHelper;
import de.hysky.skyblocker.skyblock.experiment.ExperimentSolver;
import de.hysky.skyblocker.skyblock.experiment.SuperpairsSolver;
import de.hysky.skyblocker.skyblock.experiment.UltrasequencerSolver;
import de.hysky.skyblocker.skyblock.garden.VisitorHelper;
import de.hysky.skyblocker.skyblock.item.ItemProtection;
import de.hysky.skyblocker.skyblock.item.ItemRarityBackgrounds;
import de.hysky.skyblocker.skyblock.item.MuseumItemCache;
import de.hysky.skyblocker.skyblock.item.WikiLookup;
import de.hysky.skyblocker.skyblock.item.*;
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextManager;
import de.hysky.skyblocker.skyblock.item.tooltip.BackpackPreview;
import de.hysky.skyblocker.skyblock.item.tooltip.CompactorDeletorPreview;
Expand Down Expand Up @@ -128,13 +124,13 @@ protected HandledScreenMixin(Text title) {
if (ItemProtection.itemProtection.matchesKey(keyCode, scanCode)) {
ItemProtection.handleKeyPressed(this.focusedSlot.getStack());
}
//Bazaar Lookup
if (config.helpers.bazaar.enableBazaarLookup && BazaarHelper.BAZAAR_LOOKUP.matchesKey(keyCode, scanCode)) {
BazaarHelper.bazaarLookup(client.player, this.focusedSlot);
//Item Price Lookup
if (config.helpers.itemPrice.enableItemPriceLookup && ItemPrice.ITEM_PRICE_LOOKUP.matchesKey(keyCode, scanCode)) {
ItemPrice.itemPriceLookup(client.player, this.focusedSlot);
}
//Refresh Item Prices
if (config.helpers.bazaar.enableBazaarRefresh && BazaarHelper.BAZAAR_REFRESH.matchesKey(keyCode, scanCode)) {
BazaarHelper.refreshItemPrices(this.client.player);
if (config.helpers.itemPrice.enableItemPriceRefresh && ItemPrice.ITEM_PRICE_REFRESH.matchesKey(keyCode, scanCode)) {
ItemPrice.refreshItemPrices(this.client.player);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
package de.hysky.skyblocker.skyblock.bazaar;

import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder;
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.info.DataTooltipInfoType;
import de.hysky.skyblocker.skyblock.item.tooltip.info.TooltipInfoType;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.MutableText;
Expand All @@ -22,38 +12,21 @@
import org.apache.commons.lang3.math.NumberUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class BazaarHelper extends SimpleSlotTextAdder {
private static final Pattern FILLED_PATTERN = Pattern.compile("Filled: \\S+ \\(?([\\d.]+)%\\)?!?");
private static final int RED = 0xe60b1e;
private static final int YELLOW = 0xe6ba0b;
private static final int GREEN = 0x1ee60b;

public static final KeyBinding BAZAAR_LOOKUP = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.bazaarLookup",
GLFW.GLFW_KEY_F6,
"key.categories.skyblocker"
));
public static final KeyBinding BAZAAR_REFRESH = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.bazaarRefresh",
GLFW.GLFW_KEY_Z,
"key.categories.skyblocker"
));

public BazaarHelper() {
public BazaarHelper() {
super("(?:Co-op|Your) Bazaar Orders");
}

@Init
public static void init() {}

@Override
public boolean isEnabled() {
return SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper;
Expand Down Expand Up @@ -103,28 +76,4 @@ public boolean isEnabled() {
if (filled < 100) return Text.literal("%").withColor(YELLOW).formatted(Formatting.BOLD);
return Text.literal("✅").withColor(GREEN).formatted(Formatting.BOLD);
}

// ======== Other Bazaar Features ========

public static void bazaarLookup(ClientPlayerEntity player, @NotNull Slot slot) {
ItemStack stack = ItemRepository.getItemStack(slot.getStack().getNeuName());
if (stack != null && !stack.isEmpty()) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/bz " + Formatting.strip(stack.getName().getString()));
} else {
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.bazaarLookupFailed")));
}
}

public static void refreshItemPrices(ClientPlayerEntity player) {
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.refreshingItemPrices")));
CompletableFuture.allOf(Stream.of(TooltipInfoType.NPC, TooltipInfoType.BAZAAR, TooltipInfoType.LOWEST_BINS, TooltipInfoType.ONE_DAY_AVERAGE, TooltipInfoType.THREE_DAY_AVERAGE)
.map(DataTooltipInfoType::downloadIfEnabled)
.toArray(CompletableFuture[]::new)
).thenRun(() -> player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.refreshedItemPrices"))))
.exceptionally(e -> {
ItemTooltip.LOGGER.error("[Skyblocker] Failed to refresh item prices", e);
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.refreshItemPricesFailed")));
return null;
});
}
}
79 changes: 79 additions & 0 deletions src/main/java/de/hysky/skyblocker/skyblock/item/ItemPrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package de.hysky.skyblocker.skyblock.item;

import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.info.DataTooltipInfoType;
import de.hysky.skyblocker.skyblock.item.tooltip.info.TooltipInfoType;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.skyblock.searchoverlay.SearchOverManager;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;

import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

public class ItemPrice {
public static final KeyBinding ITEM_PRICE_LOOKUP = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.itemPriceLookup",
GLFW.GLFW_KEY_F6,
"key.categories.skyblocker"
));
public static final KeyBinding ITEM_PRICE_REFRESH = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.itemPriceRefresh",
GLFW.GLFW_KEY_Z,
"key.categories.skyblocker"
));

@Init
public static void init() {}

public static void itemPriceLookup(ClientPlayerEntity player, @NotNull Slot slot) {
ItemStack stack = slot.getStack();
String skyblockApiId = stack.getSkyblockApiId();
ItemStack neuStack = ItemRepository.getItemStack(stack.getNeuName());
if (neuStack != null && !neuStack.isEmpty()) {
String itemName = Formatting.strip(neuStack.getName().getString());

// Handle Pets
if (stack.getSkyblockId().equals("PET")) {
itemName = itemName.replaceFirst("\\[Lvl \\d+ ➡ \\d+] ", "");
}

// Handle Enchanted Books
if (itemName.equals("Enchanted Book")) {
itemName = SearchOverManager.capitalizeFully(skyblockApiId.replace("ENCHANTMENT_", "").replaceAll("_\\d+", ""));
}

// Search up the item in the bazaar or auction house
if (TooltipInfoType.BAZAAR.hasOrNullWarning(skyblockApiId)) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/bz " + itemName);
} else if (TooltipInfoType.LOWEST_BINS.hasOrNullWarning(skyblockApiId)) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/ahsearch " + itemName);
}
} else {
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.itemPrice.itemPriceLookupFailed")));
}
}

public static void refreshItemPrices(ClientPlayerEntity player) {
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.itemPrice.refreshingItemPrices")));
CompletableFuture.allOf(Stream.of(TooltipInfoType.NPC, TooltipInfoType.BAZAAR, TooltipInfoType.LOWEST_BINS, TooltipInfoType.ONE_DAY_AVERAGE, TooltipInfoType.THREE_DAY_AVERAGE)
.map(DataTooltipInfoType::downloadIfEnabled)
.toArray(CompletableFuture[]::new)
).thenRun(() -> player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.itemPrice.refreshedItemPrices"))))
.exceptionally(e -> {
ItemTooltip.LOGGER.error("[Skyblocker Item Price] Failed to refresh item prices", e);
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.itemPrice.itemPriceRefreshFailed")));
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public AvgBinTooltip(int priority) {

@Override
public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) {
String skyblockApiId = stack.getSkyblockApiId();
String neuName = stack.getNeuName();

if (TooltipInfoType.ONE_DAY_AVERAGE.getData() == null || TooltipInfoType.THREE_DAY_AVERAGE.getData() == null) {
Expand All @@ -28,7 +29,7 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text>
We are skipping check average prices for potions, runes
and enchanted books because there is no data for their in API.
*/
if (!neuName.isEmpty() && LBinTooltip.lbinExist) {
if (!neuName.isEmpty() && TooltipInfoType.LOWEST_BINS.hasOrNullWarning(skyblockApiId)) {
GeneralConfig.Average type = ItemTooltip.config.avg;

// "No data" line because of API not keeping old data, it causes NullPointerException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
import java.util.List;

public class BazaarPriceTooltip extends SimpleTooltipAdder {
public static boolean bazaarExist = false;

public BazaarPriceTooltip(int priority) {
public BazaarPriceTooltip(int priority) {
super(priority);
}

@Override
public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) {
bazaarExist = false;
String skyblockApiId = stack.getSkyblockApiId();

if (TooltipInfoType.BAZAAR.hasOrNullWarning(skyblockApiId)) {
Expand All @@ -46,7 +43,6 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text>
.append(product.sellPrice().isEmpty()
? Text.literal("No data").formatted(Formatting.RED)
: ItemTooltip.getCoinsMessage(product.sellPrice().getAsDouble(), amount)));
bazaarExist = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import java.util.List;

public class LBinTooltip extends SimpleTooltipAdder {
public static boolean lbinExist = false;

public LBinTooltip(int priority) {
public LBinTooltip(int priority) {
super(priority);
}

Expand All @@ -25,15 +23,13 @@ public boolean isEnabled() {

@Override
public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) {
lbinExist = false;
String skyblockApiId = stack.getSkyblockApiId();

// bazaarOpened & bazaarExist check for lbin, because Skytils keeps some bazaar item data in lbin api
if (TooltipInfoType.LOWEST_BINS.hasOrNullWarning(skyblockApiId) && !BazaarPriceTooltip.bazaarExist) {
// Check for whether the item exist in bazaar price data, because Skytils keeps some bazaar item data in lbin api
if (TooltipInfoType.LOWEST_BINS.hasOrNullWarning(skyblockApiId) && !TooltipInfoType.BAZAAR.hasOrNullWarning(skyblockApiId)) {
lines.add(Text.literal(String.format("%-19s", "Lowest BIN Price:"))
.formatted(Formatting.GOLD)
.append(ItemTooltip.getCoinsMessage(TooltipInfoType.LOWEST_BINS.getData().getDouble(skyblockApiId), stack.getCount())));
lbinExist = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static void loadItems() {
*
* @param str string to capitalize
*/
private static String capitalizeFully(String str) {
public static String capitalizeFully(String str) {
if (str == null || str.isEmpty()) {
return str;
}
Expand Down
Loading

0 comments on commit 5ed09f8

Please sign in to comment.