Class Utils

java.lang.Object
com.Moshu.Misc.Utils

public class Utils extends Object
Utilities class, lots of useful stuff
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static File
     
    static Main
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.inventory.ItemStack
    addEnchants(org.bukkit.inventory.ItemStack itemStack, List<String> enchantments)
     
    static void
    addItemFlags(org.bukkit.inventory.meta.ItemMeta meta)
     
    static void
    addToInventory(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack a)
    Adds the item to the player's inventory
    static void
    addToInventory(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack[] is)
    Adds all the items provided in the array to the player's inventory
    static org.bukkit.inventory.ItemStack
    addUnsafeEnchants(org.bukkit.inventory.ItemStack itemStack, List<String> enchants)
     
    static int
    Generate a random number 1-100
    static org.bukkit.inventory.ItemStack
     
    static boolean
    Check a string for numbers
    static int
    countItemsOfType(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is)
    Counts identical items
    static boolean
    Check if a string ends with a caracter used to distinguish time (like m for minutes, h for hours, d for days, etc)
    static void
    errorAsItem(org.bukkit.inventory.ItemStack is, String error)
    Send an error as an item with custom display name.
    static String
     
    static int
    Extracts an integer from a string
    static void
    fillWithGlass(org.bukkit.inventory.Inventory inv)
    Fill an inventory with colored glass, based on holiday
    static void
    fillWithGlassLegacy(org.bukkit.inventory.Inventory inv)
    Deprecated.
    static String
    format(String message)
    Formats a message with legacy color codes and also HEX
    static String
    Transforms the auto-message into a normal string
    static String
    formatItemStack(org.bukkit.inventory.ItemStack is)
    Makes an ItemStack's name much nicer
     
    static String
    formatRemainingTime(long minute)
    Format time in string
    static ArrayList<org.bukkit.entity.Entity>
    getAllNearbyEntities(org.bukkit.Location l, int radius)
    Get a list of all the living entities near the location in a radius
    static org.bukkit.ChatColor
    Parse a ChatColor object from a string
    static net.md_5.bungee.api.ChatColor
    Get a ChatColor from a message
    static String
    getCountDown(long l)
    A countdown of type mm:SS
    static int
    getFreeSlots(org.bukkit.inventory.Inventory inv)
    Get how many free slots the inventory has
    static org.bukkit.inventory.ItemStack
    Get the color of the glass
    static String
    getHex(String message)
    Get a HEX code from a message
    static org.bukkit.Location
    getHighestBlock(org.bukkit.World world, int x, int z, org.bukkit.Location backup)
    Get the highest block at a location
    static org.bukkit.Location
    getHighestBlockEnd(org.bukkit.World world, int x, int z)
    Get the highest block at a location for an end world
    static org.bukkit.Location
    getHighestBlockNether(org.bukkit.World world, int x, int z, org.bukkit.Location backup)
    Get the highest block at a location for a nether world
    static String
    Get the main world of the server
    static long
     
    static List<org.bukkit.Material>
    getNearbyBlocks(org.bukkit.Location location, int radius)
    Get a list of the materials of the nearby blocks
    static List<org.bukkit.block.Block>
    getNearbyBlocks2(org.bukkit.Location location, int radius)
    Get a list of the nearby blocks
    static ArrayList<org.bukkit.entity.Entity>
    getNearbyEntities(org.bukkit.Location l, int radius)
    Get a list of all the entities near the location in a radius in a chunk
    static ArrayList<org.bukkit.entity.Entity>
    getNearbyEntities(org.bukkit.Location l, org.bukkit.entity.EntityType et, int radius)
    Get a list of all the entities near the location in a radius in a chunk
    static ArrayList<org.bukkit.entity.Entity>
    getNearbyItems(org.bukkit.Location l, int radius)
    Get a list of all the entities near the location in a radius in a chunk
    static ArrayList<org.bukkit.entity.Entity>
    getNearbyItemsOfType(org.bukkit.Location l, org.bukkit.Material mat, int radius)
    Get a list of all the entities near the location in a radius in a chunk
    static ArrayList<org.bukkit.entity.Player>
    getNearbyPlayers(org.bukkit.Location l, int radius)
    Get all players in a radius around the location
    Get a list of all the online players name
    static org.bukkit.Location
    getParticleLocation(org.bukkit.Location loc)
    Gets the location for the particles
    static org.bukkit.Location
    getPositionInFrontOfPlayer(org.bukkit.Location loc, int distance)
    Gets the location in front of the player
    static String
    Get a property from server.properties file
    static org.bukkit.Location
    getSafeBlock(org.bukkit.Location originalLoc, org.bukkit.Location backup)
    Get the highest block at a location
    Get a list of all the online players name
    static boolean
    hasEmptySlot(org.bukkit.entity.Player p)
    Checks if the player has all the slots of the inventory occupied
    static boolean
    hasFullInventory(org.bukkit.entity.Player p)
    Checks if the player has all the slots of the inventory occupied
    static boolean
    hasItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is)
    Check if the player has at least one of the ItemStack provided
    static int
    hoursFromSeconds(int seconds)
    Convert seconds to hours
    static boolean
    Check if a String is actually a double
    static boolean
    isEmpty(org.bukkit.inventory.Inventory inv)
    Check if an inventory is empty
    static boolean
    isEnabled(String plugin)
    Check if a plugin is enabled
    static boolean
    isInt(char c)
    Check if a char is actually an int
    static boolean
    Check if a String is actually an int
    static boolean
    isLoaded(String plugin)
    Check if a plugin is loaded
    static boolean
    Checks if the server is running Paper or spigot.
    static String
    Get the last char of the string
    static org.bukkit.Location
    middle(org.bukkit.Location l1, org.bukkit.Location l2)
    Calculates the middle of 2 locations
    static long
    Calculates the milliseconds until the next sharp hour (e.g.
    static double
    randDouble(double min, double max)
     
    static int
    randInt(int min, int max)
    Generates a random integer between two values
    static org.bukkit.Location
    randomCoordonatesMoreThan(org.bukkit.World world, double max, double min)
     
    static String
    Removes all HEX colors from a string
    static void
    removeItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is)
    Removes all items of that type from the player's inventory
    static double
    round(double value)
     
    static float
    round(float value)
     
    static void
    setBarrier(org.bukkit.entity.Player p, String permission, org.bukkit.inventory.ItemStack is)
    Sends a permission error like #errorAsItem(ItemStack, String)
    static String
    Sets a capital letter on the first word of the string
    static String
    setInternalPlaceholders(org.bukkit.entity.Player p, String s)
     
    static org.bukkit.inventory.meta.ItemMeta
    setMeta(org.bukkit.inventory.meta.ItemMeta meta, String displayName, List<String> lore)
     
    static void
    substractItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is, int amount)
    Substracts the amount provided of item from the player's inventory
    static void
    substractItem(org.bukkit.inventory.Inventory inv, org.bukkit.inventory.ItemStack is, int amount)
    Substracts the amount of the item from the inventory
    static void
    substractItemUnlimited(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is, int amount)
    Substracts the amount provided of item from the player's inventory
    static String
     
    static void
    tempGod(org.bukkit.entity.Player p, int seconds)
    Temporarily gives invulnerability to a player
    static void
    trySpawningParticle(org.bukkit.Location location, org.bukkit.Particle p)
     
    static boolean
    Check if a string contains only alphanumerical characters
    static boolean
    Check if a string contains only letters

    Methods inherited from class java.lang.Object

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

    • plugin

      public static Main plugin
    • kitsf

      public static File kitsf
  • Method Details

    • randDouble

      public static double randDouble(double min, double max)
    • round

      public static double round(double value)
    • round

      public static float round(float value)
    • addItemFlags

      public static void addItemFlags(org.bukkit.inventory.meta.ItemMeta meta)
    • getParticleLocation

      public static org.bukkit.Location getParticleLocation(org.bukkit.Location loc)
      Gets the location for the particles
      Returns:
      the location for the particles
    • isPaper

      public static boolean isPaper()
      Checks if the server is running Paper or spigot.
      Returns:
      true/false
    • getNearbyBlocks

      public static List<org.bukkit.Material> getNearbyBlocks(org.bukkit.Location location, int radius)
      Get a list of the materials of the nearby blocks
      Parameters:
      location - the location you want to seach
      radius - the radius
      Returns:
      the list containing the materials
    • getNearbyBlocks2

      public static List<org.bukkit.block.Block> getNearbyBlocks2(org.bukkit.Location location, int radius)
      Get a list of the nearby blocks
      Parameters:
      location - the location you want to seach
      radius - the radius
      Returns:
      the list containing the blocks
    • getColor

      public static org.bukkit.ChatColor getColor(String s)
      Parse a ChatColor object from a string
      Parameters:
      s - the string
      Returns:
      a ChatColor
    • extractInt

      public static int extractInt(String s)
      Extracts an integer from a string
      Parameters:
      s - the string
      Returns:
      the found integer
    • setMeta

      public static org.bukkit.inventory.meta.ItemMeta setMeta(org.bukkit.inventory.meta.ItemMeta meta, String displayName, List<String> lore)
    • getOnlinePlayersNames

      public static ArrayList<String> getOnlinePlayersNames()
      Get a list of all the online players name
      Returns:
      a list with all the online players namr
    • getWorldsNames

      public static ArrayList<String> getWorldsNames()
      Get a list of all the online players name
      Returns:
      a list with all the online players namr
    • formatAutoMessage

      public static String formatAutoMessage(String r)
      Transforms the auto-message into a normal string
      Parameters:
      r - the message
      Returns:
      the formatted string
    • hasItem

      public static boolean hasItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is)
      Check if the player has at least one of the ItemStack provided
      Parameters:
      p - the player
      is - the itemstack
      Returns:
      true/false
    • removeItem

      public static void removeItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is)
      Removes all items of that type from the player's inventory
      Parameters:
      p - the player
      is - the item to be removed
    • substractItem

      public static void substractItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is, int amount)
      Substracts the amount provided of item from the player's inventory
      Parameters:
      p - the player
      is - the item to be substracted
      amount - the amount of item to be substracted
    • substractItemUnlimited

      public static void substractItemUnlimited(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is, int amount)
      Substracts the amount provided of item from the player's inventory
      Parameters:
      p - the player
      is - the item to be substracted
      amount - the amount of item to be substracted
    • substractItem

      public static void substractItem(org.bukkit.inventory.Inventory inv, org.bukkit.inventory.ItemStack is, int amount)
      Substracts the amount of the item from the inventory
      Parameters:
      inv - the inventory where the item is located
      is - the item to be substracted
      amount - the amount of item to be substracted
    • countItemsOfType

      public static int countItemsOfType(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is)
      Counts identical items
      Parameters:
      p - the player to count the items from
      is - the item to be counted
      Returns:
      how many items are there
    • succesSymbol

      public static String succesSymbol()
      Returns:
      a checkmark
    • errorSymbol

      public static String errorSymbol()
      Returns:
      an x
    • addToInventory

      public static void addToInventory(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack a)
      Adds the item to the player's inventory
      Parameters:
      p - the player
      a - the items to be added
    • addToInventory

      public static void addToInventory(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack[] is)
      Adds all the items provided in the array to the player's inventory
      Parameters:
      p - the player
      is - the items to be added
    • millisToNextHour

      public static long millisToNextHour(Calendar calendar)
      Calculates the milliseconds until the next sharp hour (e.g. 1:00)
      Parameters:
      calendar - an instance of Calendar
      Returns:
      how many millies until the next hour
    • fillWithGlass

      public static void fillWithGlass(org.bukkit.inventory.Inventory inv)
      Fill an inventory with colored glass, based on holiday
      Parameters:
      inv - the inventory to be filled
    • getGlass

      public static org.bukkit.inventory.ItemStack getGlass()
      Get the color of the glass
      Returns:
      an ItemStack with the glass having the appropriate color for the holiday
    • fillWithGlassLegacy

      @Deprecated public static void fillWithGlassLegacy(org.bukkit.inventory.Inventory inv)
      Deprecated.
      Fills the inventory with black glass
      Parameters:
      inv - the inventory to be filled
    • middle

      public static org.bukkit.Location middle(org.bukkit.Location l1, org.bukkit.Location l2)
      Calculates the middle of 2 locations
      Parameters:
      l1 - first location
      l2 - second location
      Returns:
      the middle location
    • formatRemainingTime

      public static String formatRemainingTime(long minute)
      Format time in string
      Parameters:
      minute - time to be formatted
      Returns:
      the formatted string
    • containsNumbers

      public static boolean containsNumbers(String s)
      Check a string for numbers
      Parameters:
      s - the string
      Returns:
      true/false
    • addEnchants

      public static org.bukkit.inventory.ItemStack addEnchants(org.bukkit.inventory.ItemStack itemStack, List<String> enchantments)
    • addUnsafeEnchants

      public static org.bukkit.inventory.ItemStack addUnsafeEnchants(org.bukkit.inventory.ItemStack itemStack, List<String> enchants)
    • errorAsItem

      public static void errorAsItem(org.bukkit.inventory.ItemStack is, String error)
      Send an error as an item with custom display name. When a player clicks on an item in an inventory and an error happens, the item will transform into a Material.BARRIER and the error message will be displayed for a brief period of time, after which the item will reappear in the menu as before.
      Parameters:
      is - the inventory holding the item
      error - the error (should be as short as possible)
    • formatList

      public static ArrayList<String> formatList(List<String> list)
    • setBarrier

      public static void setBarrier(org.bukkit.entity.Player p, String permission, org.bukkit.inventory.ItemStack is)
      Sends a permission error like #errorAsItem(ItemStack, String)
      Parameters:
      p - the player's inventory
      permission - the permission he needs to have
      is - the itemstack to affect
    • format

      public static String format(String message)
      Formats a message with legacy color codes and also HEX
      Parameters:
      message - the message you want to apply colors to
      Returns:
      the formatted string
    • getColorFromHex

      public static net.md_5.bungee.api.ChatColor getColorFromHex(String message)
      Get a ChatColor from a message
      Parameters:
      message - the message
      Returns:
      the ChatColor, or white if the method doesn't find any colors
    • getHex

      public static String getHex(String message)
      Get a HEX code from a message
      Parameters:
      message - the message
      Returns:
      the HEX code, or white if the method doesn't find any colors
    • removeHex

      public static String removeHex(String s)
      Removes all HEX colors from a string
      Parameters:
      s - the string
      Returns:
      the string without the hex code
    • isEnabled

      public static boolean isEnabled(String plugin)
      Check if a plugin is enabled
      Parameters:
      plugin - the plugin to check
      Returns:
      true/false
    • isLoaded

      public static boolean isLoaded(String plugin)
      Check if a plugin is loaded
      Parameters:
      plugin - the plugin to check
      Returns:
      true/false
    • setCapitals

      public static String setCapitals(String s)
      Sets a capital letter on the first word of the string
      Parameters:
      s - the string
      Returns:
      the formatted string
    • chance

      public static int chance()
      Generate a random number 1-100
      Returns:
      a random number 1-100
    • getNearbyEntities

      public static ArrayList<org.bukkit.entity.Entity> getNearbyEntities(org.bukkit.Location l, int radius)
      Get a list of all the entities near the location in a radius in a chunk
      Parameters:
      l - the location
      radius - the radius
      Returns:
      the list containing all the entities
    • getNearbyEntities

      public static ArrayList<org.bukkit.entity.Entity> getNearbyEntities(org.bukkit.Location l, org.bukkit.entity.EntityType et, int radius)
      Get a list of all the entities near the location in a radius in a chunk
      Parameters:
      l - the location
      radius - the radius
      Returns:
      the list containing all the entities
    • getNearbyItemsOfType

      public static ArrayList<org.bukkit.entity.Entity> getNearbyItemsOfType(org.bukkit.Location l, org.bukkit.Material mat, int radius)
      Get a list of all the entities near the location in a radius in a chunk
      Parameters:
      l - the location
      radius - the radius
      Returns:
      the list containing all the entities
    • getNearbyItems

      public static ArrayList<org.bukkit.entity.Entity> getNearbyItems(org.bukkit.Location l, int radius)
      Get a list of all the entities near the location in a radius in a chunk
      Parameters:
      l - the location
      radius - the radius
      Returns:
      the list containing all the entities
    • getAllNearbyEntities

      public static ArrayList<org.bukkit.entity.Entity> getAllNearbyEntities(org.bukkit.Location l, int radius)
      Get a list of all the living entities near the location in a radius
      Parameters:
      l - the location
      radius - the radius
      Returns:
      the list containing all the entities
    • formatItemStack

      public static String formatItemStack(org.bukkit.inventory.ItemStack is)
      Makes an ItemStack's name much nicer
      Parameters:
      is - the itemstack
      Returns:
      the formatted string
    • getNearbyPlayers

      public static ArrayList<org.bukkit.entity.Player> getNearbyPlayers(org.bukkit.Location l, int radius)
      Get all players in a radius around the location
      Parameters:
      l - the location
      radius - the radius
      Returns:
      a list containing all the players near that locations in the specified radius
    • randInt

      public static int randInt(int min, int max)
      Generates a random integer between two values
      Parameters:
      min - the min value
      max - the max value
      Returns:
      the random integer
    • getPositionInFrontOfPlayer

      public static org.bukkit.Location getPositionInFrontOfPlayer(org.bukkit.Location loc, int distance)
      Gets the location in front of the player
      Parameters:
      loc - the location
      distance - how far away the new location should be
      Returns:
      the location in front of the player
    • getHighestBlock

      public static org.bukkit.Location getHighestBlock(org.bukkit.World world, int x, int z, org.bukkit.Location backup)
      Get the highest block at a location
      Parameters:
      world - the world
      x - the x coordinate
      z - the z coordinate
      Returns:
      the location with the highest block
    • getSafeBlock

      public static org.bukkit.Location getSafeBlock(org.bukkit.Location originalLoc, org.bukkit.Location backup)
      Get the highest block at a location
      Parameters:
      originalLoc - the location that could be unsafe
      Returns:
      the location with the highest block
    • getHighestBlockNether

      public static org.bukkit.Location getHighestBlockNether(org.bukkit.World world, int x, int z, org.bukkit.Location backup)
      Get the highest block at a location for a nether world
      Parameters:
      world - the world
      x - the x coordinate
      z - the z coordinate
      Returns:
      the location with the highest block
    • getHighestBlockEnd

      public static org.bukkit.Location getHighestBlockEnd(org.bukkit.World world, int x, int z)
      Get the highest block at a location for an end world
      Parameters:
      world - the world
      x - the x coordinate
      z - the z coordinate
      Returns:
      the location with the highest block
    • getCountDown

      public static String getCountDown(long l)
      A countdown of type mm:SS
      Parameters:
      l - the number of minutes
      Returns:
      the formatted string
    • validString

      public static boolean validString(String s)
      Check if a string contains only letters
      Parameters:
      s - the string
      Returns:
      true/false
    • validAlphanumericString

      public static boolean validAlphanumericString(String s)
      Check if a string contains only alphanumerical characters
      Parameters:
      s - the string
      Returns:
      true/false
    • hasFullInventory

      public static boolean hasFullInventory(org.bukkit.entity.Player p)
      Checks if the player has all the slots of the inventory occupied
      Parameters:
      p - the player
      Returns:
      true/false
    • hasEmptySlot

      public static boolean hasEmptySlot(org.bukkit.entity.Player p)
      Checks if the player has all the slots of the inventory occupied
      Parameters:
      p - the player
      Returns:
      true/false
    • tempGod

      public static void tempGod(org.bukkit.entity.Player p, int seconds)
      Temporarily gives invulnerability to a player
      Parameters:
      p - the player
      seconds - how many seconds should the effect last
    • getFreeSlots

      public static int getFreeSlots(org.bukkit.inventory.Inventory inv)
      Get how many free slots the inventory has
      Parameters:
      inv - the inventory
      Returns:
      how many free slots are in the inventory
    • setInternalPlaceholders

      public static String setInternalPlaceholders(org.bukkit.entity.Player p, String s)
    • trySpawningParticle

      public static void trySpawningParticle(org.bukkit.Location location, org.bukkit.Particle p)
    • checkMaterial

      public static org.bukkit.inventory.ItemStack checkMaterial(String mat)
    • randomCoordonatesMoreThan

      public static org.bukkit.Location randomCoordonatesMoreThan(org.bukkit.World world, double max, double min)
      Parameters:
      world - , world to teleport into
      max - , max coordinates to teleport
      Returns:
      the highest block at a locations
    • isEmpty

      public static boolean isEmpty(org.bukkit.inventory.Inventory inv)
      Check if an inventory is empty
      Parameters:
      inv - the inventory
      Returns:
      true/false
    • lastChar

      public static String lastChar(String s)
      Get the last char of the string
      Parameters:
      s - the string
      Returns:
      the last character
    • getMillies

      public static long getMillies(String s)
      Parameters:
      s - The time you wish to transform, formatted. (ex: 1d, 3h, 30m)
      Returns:
      The millies corresponding to the value, defaults at minutes
    • endsWithSpecialCharacter

      public static boolean endsWithSpecialCharacter(String s)
      Check if a string ends with a caracter used to distinguish time (like m for minutes, h for hours, d for days, etc)
      Parameters:
      s - the string
      Returns:
      true/false
    • isInt

      public static boolean isInt(String str)
      Check if a String is actually an int
      Parameters:
      str - the string
      Returns:
      true/false
    • isInt

      public static boolean isInt(char c)
      Check if a char is actually an int
      Parameters:
      c - the char
      Returns:
      true/false
    • isDouble

      public static boolean isDouble(String str)
      Check if a String is actually a double
      Parameters:
      str - the string
      Returns:
      true/false
    • hoursFromSeconds

      public static int hoursFromSeconds(int seconds)
      Convert seconds to hours
      Parameters:
      seconds - the time in seconds
      Returns:
      the rounded hours
    • getProperty

      public static String getProperty(String s, File f)
      Get a property from server.properties file
      Parameters:
      s - the string you want to get
      f - the file you wish to access
      Returns:
      the value you wish to get
    • getMainWorld

      public static String getMainWorld()
      Get the main world of the server
      Returns:
      the main world's name