Class BarterShopState

java.lang.Object
com.hypixel.hytale.builtin.adventure.shop.barter.BarterShopState

public class BarterShopState extends Object
Global singleton tracking barter shop stock and refresh timers. Persists to disk for survival across server restarts.
  • Field Details

  • Constructor Details

    • BarterShopState

      public BarterShopState()
  • Method Details

    • initialize

      public static void initialize(@Nonnull Path dataDirectory)
      Initialize the global state, loading from disk if available.
    • get

      @Nonnull public static BarterShopState get()
      Get the global instance.
    • load

      public static void load()
      Load state from disk.
    • save

      public static void save()
      Save state to disk.
    • shutdown

      public static void shutdown()
      Shutdown - save state before server stops.
    • getShopGameTime

      @Nonnull public static Instant getShopGameTime(@Nonnull Store<EntityStore> store)
      Resolve the game time that drives shop stock and refresh schedules.

      Shop state is shared by every world, so it follows the default world's clock. Instances such as the Forgotten Temple pause their own clock, and a shop read with that clock would never restock.

      Parameters:
      store - The entity store of the world the shop is opened in, used when the default world is not loaded.
      Returns:
      The game time to pass to the stock and trade methods of this class.
    • getOrCreateShopState

      @Nonnull public BarterShopState.ShopInstanceState getOrCreateShopState(@Nonnull BarterShopAsset asset, @Nonnull Instant gameTime)
      Get or create the state for a shop.
      Parameters:
      gameTime - Current game time from WorldTimeResource
    • checkRefresh

      public void checkRefresh(@Nonnull BarterShopAsset asset, @Nonnull Instant gameTime)
      Check and perform refresh if needed for a shop. Shops restock at their configured hour on their scheduled day (fixed world schedule).
      Parameters:
      gameTime - Current game time from WorldTimeResource
    • getStockArray

      public int[] getStockArray(@Nonnull BarterShopAsset asset, @Nonnull Instant gameTime)
      Get current stock array for a shop.
      Parameters:
      gameTime - Current game time from WorldTimeResource
    • getResolvedTrades

      @Nonnull public BarterTrade[] getResolvedTrades(@Nonnull BarterShopAsset asset, @Nonnull Instant gameTime)
      Get the resolved trades for a shop. For legacy shops, returns the static Trades array. For shops with TradeSlots, returns the randomly resolved trades.
      Parameters:
      gameTime - Current game time from the WorldTimeResource of the world.
    • executeTrade

      public boolean executeTrade(@Nonnull BarterShopAsset asset, int tradeIndex, int quantity, @Nonnull Instant gameTime)
      Attempt to execute a trade.
      Parameters:
      gameTime - Current game time from WorldTimeResource
      Returns:
      true if the trade was successful, false if otherwise.