Contents
Class BarterShopState
java.lang.Object
com.hypixel.hytale.builtin.adventure.shop.barter.BarterShopState
Global singleton tracking barter shop stock and refresh timers.
Persists to disk for survival across server restarts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classState for a single shop instance. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BuilderCodec<BarterShopState> Codec for the entire barter shop state (map of shop IDs to instance states).static final BuilderCodec<BarterShopState.ShopInstanceState> Codec for a single shop instance state. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckRefresh(BarterShopAsset asset, Instant gameTime) Check and perform refresh if needed for a shop.booleanexecuteTrade(BarterShopAsset asset, int tradeIndex, int quantity, Instant gameTime) Attempt to execute a trade.static BarterShopStateget()Get the global instance.getOrCreateShopState(BarterShopAsset asset, Instant gameTime) Get or create the state for a shop.getResolvedTrades(BarterShopAsset asset, Instant gameTime) Get the resolved trades for a shop.static InstantgetShopGameTime(Store<EntityStore> store) Resolve the game time that drives shop stock and refresh schedules.int[]getStockArray(BarterShopAsset asset, Instant gameTime) Get current stock array for a shop.static voidinitialize(Path dataDirectory) Initialize the global state, loading from disk if available.static voidload()Load state from disk.static voidsave()Save state to disk.static voidshutdown()Shutdown - save state before server stops.
-
Field Details
-
SHOP_INSTANCE_CODEC
Codec for a single shop instance state. -
CODEC
Codec for the entire barter shop state (map of shop IDs to instance states).
-
-
Constructor Details
-
BarterShopState
public BarterShopState()
-
-
Method Details
-
initialize
Initialize the global state, loading from disk if available. -
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
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
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
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 theWorldTimeResourceof 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:
trueif the trade was successful,falseif otherwise.
-