Package com.Moshu.Misc
Class Utils
java.lang.Object
com.Moshu.Misc.Utils
Utilities class, lots of useful stuff
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.inventory.ItemStackaddEnchants(org.bukkit.inventory.ItemStack itemStack, List<String> enchantments) static voidaddItemFlags(org.bukkit.inventory.meta.ItemMeta meta) static voidaddToInventory(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack a) Adds the item to the player's inventorystatic voidaddToInventory(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack[] is) Adds all the items provided in the array to the player's inventorystatic org.bukkit.inventory.ItemStackaddUnsafeEnchants(org.bukkit.inventory.ItemStack itemStack, List<String> enchants) static intchance()Generate a random number 1-100static org.bukkit.inventory.ItemStackcheckMaterial(String mat) static booleanCheck a string for numbersstatic intcountItemsOfType(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is) Counts identical itemsstatic booleanCheck if a string ends with a caracter used to distinguish time (like m for minutes, h for hours, d for days, etc)static voiderrorAsItem(org.bukkit.inventory.ItemStack is, String error) Send an error as an item with custom display name.static Stringstatic intextractInt(String s) Extracts an integer from a stringstatic voidfillWithGlass(org.bukkit.inventory.Inventory inv) Fill an inventory with colored glass, based on holidaystatic voidfillWithGlassLegacy(org.bukkit.inventory.Inventory inv) Deprecated.static StringFormats a message with legacy color codes and also HEXstatic StringTransforms the auto-message into a normal stringstatic StringformatItemStack(org.bukkit.inventory.ItemStack is) Makes an ItemStack's name much nicerformatList(List<String> list) static StringformatRemainingTime(long minute) Format time in stringstatic 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 radiusstatic org.bukkit.ChatColorParse a ChatColor object from a stringstatic net.md_5.bungee.api.ChatColorgetColorFromHex(String message) Get a ChatColor from a messagestatic StringgetCountDown(long l) A countdown of type mm:SSstatic intgetFreeSlots(org.bukkit.inventory.Inventory inv) Get how many free slots the inventory hasstatic org.bukkit.inventory.ItemStackgetGlass()Get the color of the glassstatic StringGet a HEX code from a messagestatic org.bukkit.LocationgetHighestBlock(org.bukkit.World world, int x, int z, org.bukkit.Location backup) Get the highest block at a locationstatic org.bukkit.LocationgetHighestBlockEnd(org.bukkit.World world, int x, int z) Get the highest block at a location for an end worldstatic org.bukkit.LocationgetHighestBlockNether(org.bukkit.World world, int x, int z, org.bukkit.Location backup) Get the highest block at a location for a nether worldstatic StringGet the main world of the serverstatic longgetMillies(String s) static List<org.bukkit.Material> getNearbyBlocks(org.bukkit.Location location, int radius) Get a list of the materials of the nearby blocksstatic List<org.bukkit.block.Block> getNearbyBlocks2(org.bukkit.Location location, int radius) Get a list of the nearby blocksstatic 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 chunkstatic 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 chunkstatic 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 chunkstatic 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 chunkstatic ArrayList<org.bukkit.entity.Player> getNearbyPlayers(org.bukkit.Location l, int radius) Get all players in a radius around the locationGet a list of all the online players namestatic org.bukkit.LocationgetParticleLocation(org.bukkit.Location loc) Gets the location for the particlesstatic org.bukkit.LocationgetPositionInFrontOfPlayer(org.bukkit.Location loc, int distance) Gets the location in front of the playerstatic StringgetProperty(String s, File f) Get a property from server.properties filestatic org.bukkit.LocationgetSafeBlock(org.bukkit.Location originalLoc, org.bukkit.Location backup) Get the highest block at a locationGet a list of all the online players namestatic booleanhasEmptySlot(org.bukkit.entity.Player p) Checks if the player has all the slots of the inventory occupiedstatic booleanhasFullInventory(org.bukkit.entity.Player p) Checks if the player has all the slots of the inventory occupiedstatic booleanhasItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is) Check if the player has at least one of the ItemStack providedstatic inthoursFromSeconds(int seconds) Convert seconds to hoursstatic booleanCheck if a String is actually a doublestatic booleanisEmpty(org.bukkit.inventory.Inventory inv) Check if an inventory is emptystatic booleanCheck if a plugin is enabledstatic booleanisInt(char c) Check if a char is actually an intstatic booleanCheck if a String is actually an intstatic booleanCheck if a plugin is loadedstatic booleanisPaper()Checks if the server is running Paper or spigot.static StringGet the last char of the stringstatic org.bukkit.Locationmiddle(org.bukkit.Location l1, org.bukkit.Location l2) Calculates the middle of 2 locationsstatic longmillisToNextHour(Calendar calendar) Calculates the milliseconds until the next sharp hour (e.g.static doublerandDouble(double min, double max) static intrandInt(int min, int max) Generates a random integer between two valuesstatic org.bukkit.LocationrandomCoordonatesMoreThan(org.bukkit.World world, double max, double min) static StringRemoves all HEX colors from a stringstatic voidremoveItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is) Removes all items of that type from the player's inventorystatic doubleround(double value) static floatround(float value) static voidsetBarrier(org.bukkit.entity.Player p, String permission, org.bukkit.inventory.ItemStack is) Sends a permission error like #errorAsItem(ItemStack, String)static StringSets a capital letter on the first word of the stringstatic StringsetInternalPlaceholders(org.bukkit.entity.Player p, String s) static org.bukkit.inventory.meta.ItemMetastatic voidsubstractItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is, int amount) Substracts the amount provided of item from the player's inventorystatic voidsubstractItem(org.bukkit.inventory.Inventory inv, org.bukkit.inventory.ItemStack is, int amount) Substracts the amount of the item from the inventorystatic voidsubstractItemUnlimited(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is, int amount) Substracts the amount provided of item from the player's inventorystatic Stringstatic voidtempGod(org.bukkit.entity.Player p, int seconds) Temporarily gives invulnerability to a playerstatic voidtrySpawningParticle(org.bukkit.Location location, org.bukkit.Particle p) static booleanCheck if a string contains only alphanumerical charactersstatic booleanCheck if a string contains only letters
-
Field Details
-
plugin
-
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
Get a list of the materials of the nearby blocks- Parameters:
location- the location you want to seachradius- 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 seachradius- the radius- Returns:
- the list containing the blocks
-
getColor
Parse a ChatColor object from a string- Parameters:
s- the string- Returns:
- a ChatColor
-
extractInt
Extracts an integer from a string- Parameters:
s- the string- Returns:
- the found integer
-
setMeta
-
getOnlinePlayersNames
Get a list of all the online players name- Returns:
- a list with all the online players namr
-
getWorldsNames
Get a list of all the online players name- Returns:
- a list with all the online players namr
-
formatAutoMessage
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 playeris- 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 playeris- 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 playeris- the item to be substractedamount- 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 playeris- the item to be substractedamount- 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 locatedis- the item to be substractedamount- 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 fromis- the item to be counted- Returns:
- how many items are there
-
succesSymbol
- Returns:
- a checkmark
-
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 playera- 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 playeris- the items to be added
-
millisToNextHour
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.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 locationl2- second location- Returns:
- the middle location
-
formatRemainingTime
Format time in string- Parameters:
minute- time to be formatted- Returns:
- the formatted string
-
containsNumbers
Check a string for numbers- Parameters:
s- the string- Returns:
- true/false
-
addEnchants
-
addUnsafeEnchants
-
errorAsItem
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 itemerror- the error (should be as short as possible)
-
formatList
-
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 inventorypermission- the permission he needs to haveis- the itemstack to affect
-
format
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
Get a ChatColor from a message- Parameters:
message- the message- Returns:
- the ChatColor, or white if the method doesn't find any colors
-
getHex
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
Removes all HEX colors from a string- Parameters:
s- the string- Returns:
- the string without the hex code
-
isEnabled
Check if a plugin is enabled- Parameters:
plugin- the plugin to check- Returns:
- true/false
-
isLoaded
Check if a plugin is loaded- Parameters:
plugin- the plugin to check- Returns:
- true/false
-
setCapitals
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 locationradius- 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 locationradius- 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 locationradius- the radius- Returns:
- the list containing all the entities
-
getNearbyItems
Get a list of all the entities near the location in a radius in a chunk- Parameters:
l- the locationradius- 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 locationradius- the radius- Returns:
- the list containing all the entities
-
formatItemStack
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 locationradius- 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 valuemax- 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 locationdistance- 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 worldx- the x coordinatez- 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 worldx- the x coordinatez- 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 worldx- the x coordinatez- the z coordinate- Returns:
- the location with the highest block
-
getCountDown
A countdown of type mm:SS- Parameters:
l- the number of minutes- Returns:
- the formatted string
-
validString
Check if a string contains only letters- Parameters:
s- the string- Returns:
- true/false
-
validAlphanumericString
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 playerseconds- 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
-
trySpawningParticle
public static void trySpawningParticle(org.bukkit.Location location, org.bukkit.Particle p) -
checkMaterial
-
randomCoordonatesMoreThan
public static org.bukkit.Location randomCoordonatesMoreThan(org.bukkit.World world, double max, double min) - Parameters:
world- , world to teleport intomax- , 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
Get the last char of the string- Parameters:
s- the string- Returns:
- the last character
-
getMillies
- Parameters:
s- The time you wish to transform, formatted. (ex: 1d, 3h, 30m)- Returns:
- The millies corresponding to the value, defaults at minutes
-
endsWithSpecialCharacter
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
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
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
Get a property from server.properties file- Parameters:
s- the string you want to getf- the file you wish to access- Returns:
- the value you wish to get
-
getMainWorld
Get the main world of the server- Returns:
- the main world's name
-