Class ShopBuilder

java.lang.Object
com.pixelmonmod.pixelmon.api.shop.ShopBuilder

public class ShopBuilder extends Object
A builder for creating a shop that will be displayed to any number of players.
The shop can be created for a block or an entity, such as an NPC or a vending machine. But it is not required to have a block or entity to create a shop and it can be created without either.
The shop can be created with a list of items that can be bought and sold using the ShopItem class.
The ShopEvent events are fired when a player interacts with the shop.
  • Constructor Details

    • ShopBuilder

      protected ShopBuilder()
  • Method Details

    • builder

      public static ShopBuilder builder()
      Creates a new ShopBuilder instance.
      Returns:
      A new ShopBuilder instance
    • items

      public List<ShopItem> items()
      Gets the list of items in the shop.
      Returns:
      The list of items in the shop
    • findItem

      @Nullable public @Nullable ShopItem findItem(UUID id)
      Finds an item in the shop by its unique identifier.
      Parameters:
      id - The unique identifier of the item
      Returns:
      The item if found, otherwise null
    • blockPos

      @Nullable public @Nullable net.minecraft.core.BlockPos blockPos()
      Gets the block position of the shop.
      Returns:
      The block position of the shop
    • entity

      @Nullable public @Nullable net.minecraft.world.entity.Entity entity()
      Gets the entity of the shop.
      Returns:
      The entity of the shop
    • sellable

      public boolean sellable()
      Checks if items can be sold to the shop.
      Returns:
      True if the player can sell items to the shop
    • closeHandler

      @Nullable public @Nullable Consumer<net.minecraft.server.level.ServerPlayer> closeHandler()
      Gets the close handler for the shop.
      Returns:
      The close handler for the shop
    • purchaseHandler

      @Nullable public @Nullable BiConsumer<net.minecraft.server.level.ServerPlayer,ShopItem> purchaseHandler()
      Gets the purchase handler for the shop.
      Returns:
      The purchase handler for the shop
    • sellHandler

      @Nullable public @Nullable BiConsumer<net.minecraft.server.level.ServerPlayer,ShopItem> sellHandler()
      Gets the sell handler for the shop.
      Returns:
      The sell handler for the shop
    • items

      public ShopBuilder items(ShopItem... items)
      Sets the items in the shop.
      Parameters:
      items - The items in the shop
      Returns:
      This builder
    • items

      public ShopBuilder items(List<ShopItem> items)
      Sets the items in the shop.
      Parameters:
      items - The items in the shop
      Returns:
      This builder
    • blockPos

      public ShopBuilder blockPos(net.minecraft.core.BlockPos blockPos)
      Sets the block position of the shop.
      Parameters:
      blockPos - The block position of the shop
      Returns:
      This builder
    • entity

      public ShopBuilder entity(net.minecraft.world.entity.Entity entity)
      Sets the entity of the shop.
      Parameters:
      entity - The entity of the shop
      Returns:
      This builder
    • canSell

      public ShopBuilder canSell()
      Sets the shop as allowing players to sell items to it.
      Returns:
      This builder
    • cannotSell

      public ShopBuilder cannotSell()
      Sets the shop as not allowing players to sell items to it.
      Returns:
      This builder
    • sellable

      public ShopBuilder sellable(boolean sellable)
      Sets if the shop allows players to sell items to it.
      Parameters:
      sellable - True if the shop allows players to sell items to it
      Returns:
      This builder
    • onClose

      public ShopBuilder onClose(Consumer<net.minecraft.server.level.ServerPlayer> closeHandler)
      Sets the close handler for the shop.
      Parameters:
      closeHandler - The close handler for the shop
      Returns:
      This builder
    • onPurchase

      public ShopBuilder onPurchase(BiConsumer<net.minecraft.server.level.ServerPlayer,ShopItem> purchaseHandler)
      Sets the purchase handler for the shop.
      Parameters:
      purchaseHandler - The purchase handler for the shop
      Returns:
      This builder
    • onSell

      public ShopBuilder onSell(BiConsumer<net.minecraft.server.level.ServerPlayer,ShopItem> sellHandler)
      Sets the sell handler for the shop.
      Parameters:
      sellHandler - The sell handler for the shop
      Returns:
      This builder
    • send

      public void send(net.minecraft.server.level.ServerPlayer... players)
      Sends the shop to the given players.
      Parameters:
      players - The players to send the shop to