Class FarmerInv

java.lang.Object
xyz.geik.farmer.model.inventory.FarmerInv

public class FarmerInv extends Object
Farmer inventory which contains items. Farmer inventory is a list of items which farmer can take.
Author:
Geik
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    default items which farmer can take
  • Constructor Summary

    Constructors
    Constructor
    Description
    Farmer inv which don't have any item in it.
    FarmerInv(List<FarmerItem> items, long capacity)
    Farmer inv which contains items set.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    checkMaterial(org.bukkit.inventory.ItemStack itemStack)
    Checks if item is in default items.
    void
    forceSumItem(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
    Forces adding item amount to stock.
    static @NotNull FarmerItem
    getDefaultItem(xyz.geik.glib.shades.xseries.XMaterial material)
    Gets item from default items.
    getProductionModel(xyz.geik.glib.shades.xseries.XMaterial material)
    Gets production model of a material.
    getStockedItem(xyz.geik.glib.shades.xseries.XMaterial material)
    Gets item from farmer inv.
    long
    negateItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
    Removing x amount of item from stock.
    static void
    Rebuilds the static default-material set used by checkMaterial(ItemStack).
    void
    Rebuilds the O(1) item lookup index from the current items list.
    void
    setItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
    Update item amount in stock.
    void
    Replaces the production model list and rebuilds the lookup index.
    long
    sumItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
    Adding item amount to stock.
    long
    sumItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, @NotNull org.bukkit.entity.Item collectedItem)
    Adding item amount to stock.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • defaultItems

      public static List<FarmerItem> defaultItems
      default items which farmer can take
  • Constructor Details

    • FarmerInv

      public FarmerInv(List<FarmerItem> items, long capacity)
      Farmer inv which contains items set.
      Parameters:
      items - item list of inventory
      capacity - capacity of inventory item can hold
    • FarmerInv

      public FarmerInv()
      Farmer inv which don't have any item in it. Creating with default item set.
  • Method Details

    • setProductionModels

      public void setProductionModels(List<ProductionModel> productionModels)
      Replaces the production model list and rebuilds the lookup index. Hand written on purpose so Lombok does not generate a setter that would leave productionIndex stale.
      Parameters:
      productionModels - new model list
    • getProductionModel

      public ProductionModel getProductionModel(xyz.geik.glib.shades.xseries.XMaterial material)
      Gets production model of a material. O(1) lookup, safe to call once per item on every gui draw.
      Parameters:
      material - of item
      Returns:
      model or null when there is no calculation for it
    • rebuildItemIndex

      public void rebuildItemIndex()
      Rebuilds the O(1) item lookup index from the current items list. Call this whenever the items list is replaced wholesale.
    • rebuildDefaultIndex

      public static void rebuildDefaultIndex()
      Rebuilds the static default-material set used by checkMaterial(ItemStack). Should be called once after defaultItems is populated during plugin load.
    • getStockedItem

      public FarmerItem getStockedItem(xyz.geik.glib.shades.xseries.XMaterial material)
      Gets item from farmer inv. O(1) lookup via HashMap index instead of stream scan.
      Parameters:
      material - of stock item
      Returns:
      FarmerItem
    • getDefaultItem

      @NotNull public static @NotNull FarmerItem getDefaultItem(xyz.geik.glib.shades.xseries.XMaterial material)
      Gets item from default items. Uses direct enum equality instead of parseItem()/isSimilar().
      Parameters:
      material - of default item
      Returns:
      FarmerItem
    • checkMaterial

      public static boolean checkMaterial(org.bukkit.inventory.ItemStack itemStack)
      Checks if item is in default items. Uses a pre-built HashSet instead of stream+isSimilar() to avoid repeated parseItem() calls on every ItemSpawnEvent.
      Parameters:
      itemStack - to check
      Returns:
      check status
    • sumItemAmount

      public long sumItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, @NotNull @NotNull org.bukkit.entity.Item collectedItem)
      Adding item amount to stock. Respects capacity and if it above capacity return additional amount.
      Parameters:
      material - xmaterial of item
      collectedItem - item of collected item
      Returns:
      long left amount of item
    • sumItemAmount

      public long sumItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
      Adding item amount to stock. Respects capacity and if it above capacity return additional amount.
      Parameters:
      material - xmaterial of item
      amount - amount of the item
      Returns:
      long left amount of item
    • forceSumItem

      public void forceSumItem(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
      Forces adding item amount to stock. Doesn't respect capacity.
      Parameters:
      material - to sum
      amount - to sum
    • negateItemAmount

      public long negateItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
      Removing x amount of item from stock. Respects 0 if amount bigger than stock. And return the abs of negative number.
      Parameters:
      material - xmaterial of item
      amount - amount of negate
      Returns:
      long amount of abs
    • setItemAmount

      public void setItemAmount(xyz.geik.glib.shades.xseries.XMaterial material, long amount)
      Update item amount in stock. Doesn't respect capacity.
      Parameters:
      material - to set amount
      amount - to set amount