Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.github.mkram17.bazaarutils.utils.PlayerActionUtil;
import com.github.mkram17.bazaarutils.utils.SoundUtil;
import com.github.mkram17.bazaarutils.utils.Util;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderUtil;
import meteordevelopment.orbit.EventHandler;

import java.util.Optional;
Expand Down Expand Up @@ -66,7 +67,7 @@ private static void onOrderCreated(BazaarChatEvent<? extends OrderInfo> event) {

BazaarLimitsVisualizer.addOrderToLimit(order.getVolume()* order.getPricePerItem());

Util.addWatchedOrder(order);
OrderUtil.trackUserOrder(order);
//for some reason 52800046 for 4 was on hypixel as 13200011.6 but calculates to 13200011.5. current theory is that buy price wasnt fully accurate, and it rounded up. also was .2 off on sell order for it. obviously problems with big prices
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.github.mkram17.bazaarutils.utils.annotations.autoregistration.RunOnInit;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.Order;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderInfo;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.PlayerActionUtil;
import com.github.mkram17.bazaarutils.utils.Util;
import com.github.mkram17.bazaarutils.utils.minecraft.components.TextSearch;
Expand Down Expand Up @@ -122,7 +122,7 @@ private static Optional<BazaarChatEvent.BazaarEventTypes> getMessageType(Text me
* @param priceIndex index of the price component
* @return the parsed order information if successful, empty otherwise
*/
private static Optional<OrderInfo> parseOrderData(ArrayList<Text> siblings, int volumeIndex, int nameIndex, int priceIndex) {
private static Optional<OrderInfo> parseOrderData(ArrayList<Text> siblings, int volumeIndex, int nameIndex, int priceIndex, TransactionType.Side side) {
try {
String volumeString = siblings.get(volumeIndex).getString().replace(",", "");
int volume = Integer.parseInt(volumeString);
Expand All @@ -139,7 +139,7 @@ private static Optional<OrderInfo> parseOrderData(ArrayList<Text> siblings, int
double totalPrice = Double.parseDouble(priceString);
double pricePerUnit = totalPrice / volume;

return Optional.of(new OrderInfo(name, null, null, volume, pricePerUnit, null));
return Optional.of(new OrderInfo(name, side, null, volume, pricePerUnit, null));
} catch (Exception e) {
Util.notifyError("Failed to parse order data from chat: " + siblings.stream().map(Text::getString), e);
return Optional.empty();
Expand All @@ -151,21 +151,21 @@ private static Optional<OrderInfo> parseOrderData(ArrayList<Text> siblings, int
*
* @param siblings the text components of the message
* @param eventType the type of bazaar event
* @param orderType the order type (buy/sell)
* @param transactionType the transaction type (buy/sell)
* @param volumeIndex index of the volume component
* @param nameIndex index of the item name component
* @param priceIndex index of the price component
*/
private static void processOrderEvent(
ArrayList<Text> siblings,
BazaarChatEvent.BazaarEventTypes eventType,
OrderType orderType,
TransactionType transactionType,
int volumeIndex,
int nameIndex,
int priceIndex
) {
parseOrderData(siblings, volumeIndex, nameIndex, priceIndex).ifPresent(order -> {
order.setOrderType(orderType);
parseOrderData(siblings, volumeIndex, nameIndex, priceIndex, transactionType.getSide()).ifPresent(order -> {
order.setTransactionType(transactionType);

EVENT_BUS.post(new BazaarChatEvent<>(eventType, order));
});
Expand All @@ -178,7 +178,7 @@ private static void processOrderEvent(
*/
public static void handleFlip(ArrayList<Text> siblings) {
int priceIndex = TextSearch.indexOf(siblings, "for") + 1;
processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.ORDER_FLIPPED, OrderType.SELL, 3, 4, priceIndex);
processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.ORDER_FLIPPED, TransactionType.of(TransactionType.Side.SELL, TransactionType.Method.ORDER), 3, 4, priceIndex);
}

/**
Expand All @@ -189,7 +189,7 @@ public static void handleFlip(ArrayList<Text> siblings) {
public static void handleCancelled(ArrayList<Text> siblings) {
int priceIndex = TextSearch.indexOf(siblings, "for") + 1;

processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.ORDER_CANCELLED, OrderType.SELL, 2, 4, priceIndex);
processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.ORDER_CANCELLED, TransactionType.of(TransactionType.Side.SELL, TransactionType.Method.ORDER), 2, 4, priceIndex);
}

/**
Expand All @@ -200,7 +200,7 @@ public static void handleCancelled(ArrayList<Text> siblings) {
public static void handleInstaSell(ArrayList<Text> siblings) {
int priceIndex = TextSearch.indexOf(siblings, "for") + 1;

processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.INSTA_SELL, OrderType.BUY, 2, 4, priceIndex);
processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.INSTA_SELL, TransactionType.of(TransactionType.Side.SELL, TransactionType.Method.INSTANT), 2, 4, priceIndex);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cancellation isnt any type of current transaction. Should we add it to TransactionType?

}

/**
Expand All @@ -209,7 +209,7 @@ public static void handleInstaSell(ArrayList<Text> siblings) {
* @param siblings the text components of the message
*/
public static void handleInstaBuy(ArrayList<Text> siblings) {
processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.INSTA_BUY, OrderType.SELL, 2, 4, 6);
processOrderEvent(siblings, BazaarChatEvent.BazaarEventTypes.INSTA_BUY, TransactionType.of(TransactionType.Side.BUY, TransactionType.Method.INSTANT), 2, 4, 6);
}

/**
Expand All @@ -232,8 +232,8 @@ private static void handleFilled(Text message) {
int volume = Integer.parseInt(parts[1].replace(",", ""));
String itemName = parts[2].trim();

OrderType orderType = messageString.contains("Sell Offer") ? OrderType.SELL : OrderType.BUY;
OrderInfo item = new OrderInfo(itemName, orderType, null, volume, null, null);
TransactionType.Side side = messageString.contains("Sell Offer") ? TransactionType.Side.SELL: TransactionType.Side.BUY;
OrderInfo item = new OrderInfo(itemName, side, null, volume, null, null);

EVENT_BUS.post(new BazaarChatEvent<>(BazaarChatEvent.BazaarEventTypes.ORDER_FILLED, item));
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -263,8 +263,8 @@ private static void handleOrderCreated(ArrayList<Text> siblings) {
price /= ((100 - BUConfig.USER_BAZAAR_FLIPPER_ACCOUNT_UPGRADE.userBazaarTax) / 100);
}

OrderType orderType = isSellOrder ? OrderType.SELL : OrderType.BUY;
Order orderToAdd = new Order(itemName, volume, price, orderType, null);
TransactionType.Side transactionType = isSellOrder ? TransactionType.Side.SELL: TransactionType.Side.BUY;
Order orderToAdd = new Order(itemName, volume, price, transactionType, null);

EVENT_BUS.post(new BazaarChatEvent<>(BazaarChatEvent.BazaarEventTypes.ORDER_CREATED, orderToAdd));
}
Expand Down Expand Up @@ -369,9 +369,9 @@ private static Optional<Order> getClaimedBuyOrder(ArrayList<Text> siblings) {
OrderInfo item;

if (OrderInfo.getVariables(OrderInfo::getVolume).contains(volumeClaimed)) {
item = new OrderInfo(itemName, OrderType.BUY, null, volumeClaimed, price, null);
item = new OrderInfo(itemName, TransactionType.Side.BUY, null, volumeClaimed, price, null);
} else {
item = new OrderInfo(itemName, OrderType.BUY, null, null, price, null);
item = new OrderInfo(itemName, TransactionType.Side.BUY, null, null, price, null);
}

return getOrderInfo(item);
Expand All @@ -396,7 +396,7 @@ private static Optional<Order> getClaimedSellOrder(ArrayList<Text> siblings) {
String priceString = priceComponent.getString().replace(",", "").trim();
double price = Double.parseDouble(priceString);

OrderInfo item = new OrderInfo(name, OrderType.SELL, null, volume, price, null);
OrderInfo item = new OrderInfo(name, TransactionType.Side.SELL, null, volume, price, null);

return getOrderInfo(item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.github.mkram17.bazaarutils.features.gui.buttons.bookmarks;

import com.github.mkram17.bazaarutils.config.features.gui.ButtonsConfig;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderUtil;
import com.github.mkram17.bazaarutils.utils.minecraft.gui.widgets.ItemSlotButtonWidget;
import com.github.mkram17.bazaarutils.utils.PlayerActionUtil;
import com.github.mkram17.bazaarutils.utils.SoundUtil;
import com.github.mkram17.bazaarutils.utils.Util;
import com.github.mkram17.bazaarutils.utils.annotations.autoregistration.RegisterWidget;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarScreens;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderInfo;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PricingPosition;
import com.github.mkram17.bazaarutils.utils.minecraft.ItemButton;
import com.github.mkram17.bazaarutils.utils.minecraft.PlayerSlots;
Expand Down Expand Up @@ -48,13 +48,9 @@ public static List<ItemSlotButtonWidget> getWidgets() {
final ItemStack itemForButton = (configuredItem == null) ? Items.BARRIER.getDefaultStack() : configuredItem;
MutableText text = Text.literal(bookmark.name()).formatted(Formatting.BOLD);

OrderInfo orderInfo = new OrderInfo(bookmark.name(), OrderType.SELL, null, null, null, null);

orderInfo.updateMarketPrice();

Style style = Style.EMPTY.withColor(Formatting.GRAY).withBold(false);
text.append(Text.literal("\nBuy: " + Util.getPrettyString(orderInfo.getPriceForPosition(PricingPosition.MATCHED, OrderType.SELL)) + " coins").setStyle(style));
text.append(Text.literal("\nSell: " + Util.getPrettyString(orderInfo.getPriceForPosition(PricingPosition.MATCHED, OrderType.BUY)) + " coins").setStyle(style));
text.append(Text.literal("\nInsta Buy: " + Util.getPrettyString(OrderUtil.getPriceForPosition(bookmark.productID(), PricingPosition.MATCHED, TransactionType.of(TransactionType.Side.BUY, TransactionType.Method.INSTANT))) + " coins").setStyle(style));
text.append(Text.literal("\nInsta Sell: " + Util.getPrettyString(OrderUtil.getPriceForPosition(bookmark.productID(), PricingPosition.MATCHED, TransactionType.of(TransactionType.Side.SELL, TransactionType.Method.INSTANT))) + " coins").setStyle(style));

ItemSlotButtonWidget button = new ItemSlotButtonWidget(
buttonX,
Expand Down Expand Up @@ -89,13 +85,11 @@ public static void onWidgetShiftClick(Bookmark bookmark) {
public static void onWidgetLeftClick(Bookmark bookmark) {
SoundUtil.playSound(ItemButton.BUTTON_SOUND, ItemButton.BUTTON_VOLUME);

if (bookmark.productID() != null) {
Optional<Integer> inventorySlot = PlayerSlots.findScreenSlotByProductId(bookmark.productID());
Optional<Integer> inventorySlot = PlayerSlots.findScreenSlotByProductId(bookmark.productID());

if (inventorySlot.isPresent()) {
ContainerManager.clickSlot(inventorySlot.get(), 0);
return;
}
if (inventorySlot.isPresent()) {
ContainerManager.clickSlot(inventorySlot.get(), 0);
return;
}

PlayerActionUtil.runCommand("bz " + bookmark.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.mkram17.bazaarutils.utils.bazaar.SignInputHelper;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarScreens;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarSlots;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PriceInfo;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.minecraft.gui.ScreenManager;
import com.teamresourceful.resourcefulconfig.api.annotations.Comment;
import com.teamresourceful.resourcefulconfig.api.annotations.ConfigEntry;
Expand Down Expand Up @@ -66,8 +65,7 @@ public class BuyOrderAmountHelper extends SignInputHelper.TransactionAmount {
)
public int fixedAmount = 1;

public OrderType orderType = OrderType.BUY;
public MarketType marketType = MarketType.ORDER;
public TransactionType transactionType = TransactionType.of(TransactionType.Side.BUY, TransactionType.Method.ORDER);

@Override
public Item getButtonItem() {
Expand All @@ -91,7 +89,7 @@ public BuyOrderAmountHelper(boolean enabled, int slotNumber) {
}

@Override
protected int computeFixedValue(TransactionState state, PriceInfo price) {
protected int computeFixedValue(TransactionState state) {
return getFixedAmount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.mkram17.bazaarutils.utils.bazaar.SignInputHelper;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarScreens;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarSlots;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PriceInfo;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.minecraft.gui.ScreenManager;
import com.teamresourceful.resourcefulconfig.api.annotations.Comment;
import com.teamresourceful.resourcefulconfig.api.annotations.ConfigEntry;
Expand Down Expand Up @@ -66,8 +65,7 @@ public class InstantBuyAmountHelper extends SignInputHelper.TransactionAmount {
)
public int fixedAmount = 1;

public OrderType orderType = OrderType.BUY;
public MarketType marketType = MarketType.INSTANT;
public TransactionType transactionType = TransactionType.of(TransactionType.Side.BUY, TransactionType.Method.INSTANT);

@Override
public Item getButtonItem() {
Expand All @@ -91,7 +89,7 @@ public InstantBuyAmountHelper(boolean enabled, int slotNumber) {
}

@Override
protected int computeFixedValue(TransactionState state, PriceInfo price) {
protected int computeFixedValue(TransactionState state) {
return getFixedAmount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.mkram17.bazaarutils.utils.bazaar.SignInputHelper;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarScreens;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarSlots;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PriceInfo;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.minecraft.gui.ScreenManager;
import com.teamresourceful.resourcefulconfig.api.annotations.Comment;
import com.teamresourceful.resourcefulconfig.api.annotations.ConfigEntry;
Expand Down Expand Up @@ -66,8 +65,7 @@ public class SellOfferAmountHelper extends SignInputHelper.TransactionAmount {
)
public int fixedAmount = 1;

public OrderType orderType = OrderType.SELL;
public MarketType marketType = MarketType.ORDER;
public TransactionType transactionType = TransactionType.of(TransactionType.Side.SELL, TransactionType.Method.ORDER);

@Override
public Item getButtonItem() {
Expand All @@ -91,7 +89,7 @@ public SellOfferAmountHelper(boolean enabled, int slotNumber) {
}

@Override
protected int computeFixedValue(TransactionState state, PriceInfo price) {
protected int computeFixedValue(TransactionState state) {
return getFixedAmount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.mkram17.bazaarutils.utils.bazaar.SignInputHelper;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarScreens;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarSlots;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PriceInfo;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PricingPosition;
import com.github.mkram17.bazaarutils.utils.minecraft.gui.ScreenManager;
import com.teamresourceful.resourcefulconfig.api.annotations.Comment;
Expand Down Expand Up @@ -57,9 +56,7 @@ public class BuyOrderPriceHelper extends SignInputHelper.TransactionCost {
)
public PricingPosition pricingPosition;

public OrderType orderType = OrderType.BUY;

public MarketType marketType = MarketType.ORDER;
public TransactionType transactionType = TransactionType.of(TransactionType.Side.BUY, TransactionType.Method.ORDER);

@Override
public Item getButtonItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.github.mkram17.bazaarutils.utils.bazaar.SignInputHelper;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarScreens;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarSlots;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PricingPosition;
import com.github.mkram17.bazaarutils.utils.minecraft.gui.ScreenManager;
import com.teamresourceful.resourcefulconfig.api.annotations.Comment;
Expand Down Expand Up @@ -56,9 +56,7 @@ public class FlipOrderPriceHelper extends SignInputHelper.TransactionFlip {
)
public PricingPosition pricingPosition;

public OrderType orderType = OrderType.SELL;

public MarketType marketType = MarketType.ORDER;
public TransactionType transactionType = TransactionType.of(TransactionType.Side.SELL, TransactionType.Method.ORDER);

@Override
public Item getButtonItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.mkram17.bazaarutils.utils.bazaar.SignInputHelper;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarScreens;
import com.github.mkram17.bazaarutils.utils.bazaar.gui.BazaarSlots;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.OrderType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PriceInfo;
import com.github.mkram17.bazaarutils.utils.bazaar.market.order.TransactionType;
import com.github.mkram17.bazaarutils.utils.bazaar.market.price.PricingPosition;
import com.github.mkram17.bazaarutils.utils.minecraft.gui.ScreenManager;
import com.teamresourceful.resourcefulconfig.api.annotations.Comment;
Expand Down Expand Up @@ -57,9 +56,7 @@ public class SellOfferPriceHelper extends SignInputHelper.TransactionCost {
)
public PricingPosition pricingPosition;

public OrderType orderType = OrderType.SELL;

public MarketType marketType = MarketType.ORDER;
public TransactionType transactionType = TransactionType.of(TransactionType.Side.SELL, TransactionType.Method.ORDER);

@Override
public Item getButtonItem() {
Expand Down
Loading
Loading