# Utils (ShopChest 1.12 API)
Date: 2017-06-08

de.epiceric.shopchest.utils

## Class Utils

- java.lang.Object
- - de.epiceric.shopchest.utils.Utils

    public class Utils
    extends Object

### Constructor Summary

Constructors
Constructor and Description
`Utils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static org.bukkit.inventory.ItemStack` `decode(String string)` Decodes an `ItemStack` from a Base64 String
`static String` `encode(org.bukkit.inventory.ItemStack itemStack)` Encodes an `ItemStack` in a Base64 String
`static int` `getAmount(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack)` Gets the amount of items in an inventory
`static Class<?>` `getCraftClass(String className)`
`static int` `getFreeSpaceForItem(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack)` Get the amount of the given item, that fits in the given inventory
`static org.bukkit.inventory.ItemStack` `getItemInMainHand(org.bukkit.entity.Player p)`
`static org.bukkit.inventory.ItemStack` `getItemInOffHand(org.bukkit.entity.Player p)`
`static int` `getMajorVersion()`
`static Class<?>` `getNMSClass(String className)`
`static org.bukkit.inventory.ItemStack` `getPreferredItemInHand(org.bukkit.entity.Player p)`
`static int` `getRevision()`
`static String` `getServerVersion()`
`static boolean` `hasAxeInHand(org.bukkit.entity.Player p)`
`static boolean` `hasPermissionToCreateShop(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, boolean buy, boolean sell)` Check if a player is allowed to create a shop that sells or buys the given item.
`static boolean` `isFlagAllowedOnPlot(com.intellectualcrafters.plot.object.Plot plot, com.intellectualcrafters.plot.flag.Flag flag, org.bukkit.entity.Player p)` Check if a flag is allowed for a player on a plot from PlotSquared
`static boolean` `isItemSimilar(org.bukkit.inventory.ItemStack itemStack1, org.bukkit.inventory.ItemStack itemStack2)` Check if two items are similar to each other
`static boolean` `sendPacket(ShopChest plugin, Object packet, org.bukkit.entity.Player player)` Send a packet to a player

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Utils

    public Utils()

### Method Detail

#### isItemSimilar

    public static boolean isItemSimilar(org.bukkit.inventory.ItemStack itemStack1,
                                        org.bukkit.inventory.ItemStack itemStack2)

Check if two items are similar to each other

Parameters:
  `itemStack1` - The first item
  `itemStack2` - The second item
Returns:
  `true` if the given items are similar or `false` if not

#### getAmount

    public static int getAmount(org.bukkit.inventory.Inventory inventory,
                                org.bukkit.inventory.ItemStack itemStack)

Gets the amount of items in an inventory

Parameters:
  `inventory` - The inventory, in which the items are counted
  `itemStack` - The items to count
Returns:
  Amount of given items in the given inventory

#### getFreeSpaceForItem

    public static int getFreeSpaceForItem(org.bukkit.inventory.Inventory inventory,
                                          org.bukkit.inventory.ItemStack itemStack)

Get the amount of the given item, that fits in the given inventory

Parameters:
  `inventory` - Inventory, where to search for free space
  `itemStack` - Item, of which the amount that fits in the inventory should be returned
Returns:
  Amount of the given item, that fits in the given inventory

#### getItemInMainHand

    public static org.bukkit.inventory.ItemStack getItemInMainHand(org.bukkit.entity.Player p)

Parameters:
  `p` - Player whose item in his main hand should be returned
Returns:
  `ItemStack` in his main hand, or `null` if he doesn't hold one

#### getItemInOffHand

    public static org.bukkit.inventory.ItemStack getItemInOffHand(org.bukkit.entity.Player p)

Parameters:
  `p` - Player whose item in his off hand should be returned
Returns:
  `ItemStack` in his off hand, or `null` if he doesn't hold one or the server version is below 1.9

#### getPreferredItemInHand

    public static org.bukkit.inventory.ItemStack getPreferredItemInHand(org.bukkit.entity.Player p)

Parameters:
  `p` - Player whose item in his hand should be returned
Returns:
  Item in his main hand, or the item in his off if he doesn't have one in this main hand, or `null` if he doesn't have one in both hands

#### hasAxeInHand

    public static boolean hasAxeInHand(org.bukkit.entity.Player p)

Parameters:
  `p` - Player to check if he has an axe in one of his hands
Returns:
  Whether a player has an axe in one of his hands

#### isFlagAllowedOnPlot

    public static boolean isFlagAllowedOnPlot(com.intellectualcrafters.plot.object.Plot plot,
                                              com.intellectualcrafters.plot.flag.Flag flag,
                                              org.bukkit.entity.Player p)

Check if a flag is allowed for a player on a plot from PlotSquared

Parameters:
  `plot` - Plot from PlotSquared
  `flag` - Flag to check
  `p` - Player to check
Returns:
  Whether the flag is allowed for the player

#### hasPermissionToCreateShop

    public static boolean hasPermissionToCreateShop(org.bukkit.entity.Player player,
                                                    org.bukkit.inventory.ItemStack item,
                                                    boolean buy,
                                                    boolean sell)

Check if a player is allowed to create a shop that sells or buys the given item.

Parameters:
  `player` - Player to check
  `item` - Item to be sold or bought
  `buy` - Whether buying should be enabled
  `sell` - Whether selling should be enabled
Returns:
  Whether the player is allowed

#### getNMSClass

    public static Class<?> getNMSClass(String className)

Parameters:
  `className` - Name of the class
Returns:
  Class in `net.minecraft.server.[VERSION]` package with the specified name or `null` if the class was not found

#### getCraftClass

    public static Class<?> getCraftClass(String className)

Parameters:
  `className` - Name of the class
Returns:
  Class in `org.bukkit.craftbukkit.[VERSION]` package with the specified name or `null` if the class was not found

#### sendPacket

    public static boolean sendPacket(ShopChest plugin,
                                     Object packet,
                                     org.bukkit.entity.Player player)

Send a packet to a player

Parameters:
  `packet` - Packet to send
  `player` - Player to which the packet should be sent
Returns:
  `true` if the packet was sent, or `false` if an exception was thrown

#### getServerVersion

    public static String getServerVersion()

Returns:
  The current server version with revision number (e.g. v1_9_R2, v1_10_R1)

#### getRevision

    public static int getRevision()

Returns:
  The revision of the current server version (e.g. 2 for v1_9_R2, 1 for v1_10_R1)

#### getMajorVersion

    public static int getMajorVersion()

Returns:
  The major version of the server (e.g. 9 for 1.9.2, 10 for 1.10)

#### encode

    public static String encode(org.bukkit.inventory.ItemStack itemStack)

Encodes an `ItemStack` in a Base64 String

Parameters:
  `itemStack` - `ItemStack` to encode
Returns:
  Base64 encoded String

#### decode

    public static org.bukkit.inventory.ItemStack decode(String string)

Decodes an `ItemStack` from a Base64 String

Parameters:
  `string` - Base64 encoded String to decode
Returns:
  Decoded `ItemStack`