Class PipesUtil

java.lang.Object
io.github.apfelcreme.Pipes.PipesUtil

public class PipesUtil extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.bukkit.block.BlockFace[]
     
    static final int[][]
     
    static final Random
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addFuel(org.bukkit.inventory.Inventory source, org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack)
    Add fuel to an inventory that supports fuel
    static void
    addItem(org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack)
    Add an item to an inventory.
    static boolean
    containsSimilar(Collection<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack)
    checks if the given list of items contains an item stack similar to the given item stack
    convertToPipePart(org.bukkit.block.BlockState state, PipesItem type)
    This is a helper method to convert a block to a PipesPart.
    static int
    countChar(char c, String... strings)
    Get the amount of times that a character appears in a certain string (array)
    static double
    getCompostableChance(org.bukkit.Material type)
    Gets the chance that a compostable item has to fill a layer
    static org.bukkit.inventory.ItemStack
    getFirstSimilar(List<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack)
    checks if the given list of items contains an item stack similar to the given item stack and returns the first one
    static org.bukkit.inventory.ItemStack
    getFuel(org.bukkit.inventory.Inventory inventory)
    Get the fuel of an inventory (currently either of type BREWING or FURNACE)
    static PipesItem
    getPipesItem(org.bukkit.block.Block block)
    Get the PipesItem from a Block
    static PipesItem
    getPipesItem(org.bukkit.block.BlockState state)
     
    static PipesItem
    getPipesItem(org.bukkit.inventory.ItemStack item)
    Get the PipesItem from an ItemStack
    static boolean
    isNumeric(String string)
    returns whether a string only contains numbers
    static boolean
    isSimilarFuzzy(org.bukkit.inventory.ItemStack a, org.bukkit.inventory.ItemStack b)
    Check if two ItemStacks are similar ignoring amounts and meta
    static org.bukkit.inventory.ItemStack
    moveToSingleSlot(org.bukkit.inventory.Inventory source, org.bukkit.inventory.ItemStack current, org.bukkit.inventory.ItemStack added)
    Calculate the result itemstack that should be moved to a single slot containing some item
    static boolean
    potionAcceptsIngredient(org.bukkit.inventory.ItemStack itemStack, org.bukkit.inventory.ItemStack ingredient)
    Check whether or not a certain potion item can accepts an ingredient
    static void
    removeItems(org.bukkit.inventory.Inventory inventory, org.bukkit.Material material, int count, boolean removeSpecial)
    Remove a specific material from an inventory
    static void
    setFuel(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack)
    Set the fuel of an inventory (currently either of type BREWING or FURNACE)

    Methods inherited from class java.lang.Object

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

    • RANDOM

      public static final Random RANDOM
    • BLOCK_FACES

      public static final org.bukkit.block.BlockFace[] BLOCK_FACES
    • OFFSETS

      public static final int[][] OFFSETS
  • Constructor Details

    • PipesUtil

      public PipesUtil()
  • Method Details

    • isNumeric

      public static boolean isNumeric(String string)
      returns whether a string only contains numbers
      Parameters:
      string - the string to be checked
      Returns:
      true or false
    • getPipesItem

      public static PipesItem getPipesItem(org.bukkit.inventory.ItemStack item)
      Get the PipesItem from an ItemStack
      Parameters:
      item - the ItemStack
      Returns:
      the PipesItem or null if none found
    • getPipesItem

      public static PipesItem getPipesItem(org.bukkit.block.Block block)
      Get the PipesItem from a Block
      Parameters:
      block - the Block
      Returns:
      the PipesItem or null if none found
    • getPipesItem

      public static PipesItem getPipesItem(org.bukkit.block.BlockState state)
    • convertToPipePart

      public static AbstractPipePart convertToPipePart(org.bukkit.block.BlockState state, PipesItem type)
      This is a helper method to convert a block to a PipesPart.
      Parameters:
      state - The block state to convert
      type - The type of the part
      Returns:
      the pipe part or null if the block isn't one
    • removeItems

      public static void removeItems(org.bukkit.inventory.Inventory inventory, org.bukkit.Material material, int count, boolean removeSpecial)
      Remove a specific material from an inventory
      Parameters:
      inventory - the inventory
      material - the material
      count - the amount to remove
      removeSpecial - should we remove items that have meta/enchantments/are damaged?
    • containsSimilar

      public static boolean containsSimilar(Collection<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack)
      checks if the given list of items contains an item stack similar to the given item stack
      Parameters:
      items - a list of item stacks
      itemStack - an item stack
      Returns:
      true if there is an item stack of the same type with the same data. Amount may vary
    • getFirstSimilar

      public static org.bukkit.inventory.ItemStack getFirstSimilar(List<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack)
      checks if the given list of items contains an item stack similar to the given item stack and returns the first one
      Parameters:
      items - a list of item stacks
      itemStack - an item stack
      Returns:
      The first itemstack matching this one or null if none was found
    • isSimilarFuzzy

      public static boolean isSimilarFuzzy(org.bukkit.inventory.ItemStack a, org.bukkit.inventory.ItemStack b)
      Check if two ItemStacks are similar ignoring amounts and meta
      Parameters:
      a - First item stack
      b - Second item stack
      Returns:
      Whether or not they are similar
    • setFuel

      public static void setFuel(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack)
      Set the fuel of an inventory (currently either of type BREWING or FURNACE)
      Parameters:
      inventory - The inventory that accepts fuel
      itemStack - The item that should be placed as fuel
    • getFuel

      public static org.bukkit.inventory.ItemStack getFuel(org.bukkit.inventory.Inventory inventory)
      Get the fuel of an inventory (currently either of type BREWING or FURNACE)
      Parameters:
      inventory - The inventory that accepts fuel
      Returns:
      The fuel ItemStack
    • addItem

      public static void addItem(org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack)
      Add an item to an inventory. This more complex method is necessary as not every implementation sets the leftover amount
      Parameters:
      target - Where to move the item to
      itemStack - The item stack
    • addFuel

      public static boolean addFuel(org.bukkit.inventory.Inventory source, org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack)
      Add fuel to an inventory that supports fuel
      Parameters:
      source - The inventory that we move it from
      target - Where to move the item to
      itemStack - The item stack
      Returns:
      Whether or not the fuel was successfully set
    • moveToSingleSlot

      public static org.bukkit.inventory.ItemStack moveToSingleSlot(org.bukkit.inventory.Inventory source, org.bukkit.inventory.ItemStack current, org.bukkit.inventory.ItemStack added)
      Calculate the result itemstack that should be moved to a single slot containing some item
      Parameters:
      source - The inventory the added item is coming from
      current - The current item in the target inventory
      added - The item to be added to the target
      Returns:
      The item stack that should be added to the target inventory
    • potionAcceptsIngredient

      public static boolean potionAcceptsIngredient(org.bukkit.inventory.ItemStack itemStack, org.bukkit.inventory.ItemStack ingredient) throws IllegalArgumentException
      Check whether or not a certain potion item can accepts an ingredient
      Parameters:
      itemStack - The potion to check
      ingredient - The ingredient
      Returns:
      true if the potion can be brewed with the ingredient; false if not
      Throws:
      IllegalArgumentException - When the input item is not a potion
    • countChar

      public static int countChar(char c, String... strings)
      Get the amount of times that a character appears in a certain string (array)
      Parameters:
      c - The character
      strings - The string(s) to search ing
      Returns:
      The amount of times the character appears in the string(s)
    • getCompostableChance

      public static double getCompostableChance(org.bukkit.Material type)
      Gets the chance that a compostable item has to fill a layer
      Parameters:
      type - The item type
      Returns:
      The chance, 0 if it isn't compostable