Class PipesUtil

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

public class PipesUtil
extends Object
  • Field Summary

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

    Constructors 
    Constructor Description
    PipesUtil()  
  • 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
    static AbstractPipePart 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 String getHiddenString​(String string)
    Returns a hidden string in the itemstack which is hidden using the last lore line
    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 String hideString​(String hidden, String string)
    Hide a string inside another string with chat color characters
    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

  • 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
    • hideString

      public static String hideString​(String hidden, String string)
      Hide a string inside another string with chat color characters
      Parameters:
      hidden - The string to hide
      string - The string to hide in
      Returns:
      The string with the hidden string appended
    • getHiddenString

      public static String getHiddenString​(String string)
      Returns a hidden string in the itemstack which is hidden using the last lore line
      Parameters:
      string - The string to search in for a hidden string
      Returns:
      The hidden string or null if there is none or the input is null
    • 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