Interface Helper
-
Method Summary
Modifier and TypeMethodDescriptionForms a human-readable String given by an ItemStack.composeJsonAsSNBT
(com.google.gson.JsonObject json) Tries to convert a JsonObject to a SNBT data tag.int
copy
(InputStream is, OutputStream os) Copies bytes from an InputStream to an OutputStream.Tries to apply a color to anItemStack
if possible.@Nullable Double
evaluateString
(String expression) Tries to evaluate an equation passed in as a String.formatDuration
(long duration) Formats the milliseconds duration in a human-readable string.default String
formatDuration
(Duration duration) Formats the duration in a human-readable string.formatNumber
(double num) Tries to format the number in a human-readable way.formatNumber
(long num) Tries to format the number in a human-readable way.formatNumber
(BigDecimal num) Tries to format the number in a human-readable way.static Helper
get()
Contains utility stuff.default void
getBlockAsync
(Location location, Consumer<Block> callback) Allows you to retrieve and modify a block asynchronously on 1.14+void
getBlockAsync
(World world, int x, int y, int z, Consumer<Block> callback) Allows you to retrieve and modify a block asynchronously on 1.14+default void
getBlockAsync
(World world, XYZ xyz, Consumer<Block> callback) Allows you to retrieve and modify a block asynchronously on 1.14+getBlockVariant
(Material mat) Returns the block variant of a material.getBukkitChatColorFromBungee
(net.md_5.bungee.api.ChatColor color) Gets the ChatColor (from the Bukkit package) that fits the most to the Bungee color.void
getChunkAsync
(World world, int x, int z, Consumer<Chunk> callback) Allows you to retrieve and modify a block asynchronously on 1.14+@Nullable Effect
getEffectByName
(String name) Tries to identify an effect given by its name.@Nullable Enchantment
getEnchantmentByName
(String name) Tries to identify an enchantment given by its name.@Nullable EntityType
getEntityTypeByName
(String name) Tries to identify the type of an entity given by its name.Returns the inventory variant of a material.int
Returns the current java version.@Nullable Material
getMaterialByName
(String name) Tries to identify a material given by its name.int
getMinHeight
(World world) Returns the minimum height of an arena.getNickedPlayerRealName
(Player player) Nicknaming plugins might replaceHumanEntity.getName()
in favour for the nicked name.getPlayerDisplayName
(Player player) Returns the display name of a player that shall be shown to the public.@Nullable String
getPlayerNickName
(Player player) Tries to obtain the nicked name of a plugin which possibly has been changed by a third-party nick plugin.getPlayerSkinData
(Player player) Gets the texture & signature of the player's skin.@Nullable PotionType
getPotionTypeByName
(String name) Tries to identify a potion type given by its name.@Nullable Sound
getSoundByName
(String name) Tries to identify a sound given by its name.void
givePlayerItem
(Player player, ItemStack itemStack) Properly gives an item to a player.boolean
isBedrockPlayer
(UUID uuid) Returns whether the player is playing using Minecraft's Bedrock Edition or not.boolean
isBedrockPlayer
(OfflinePlayer player) Returns whether the player is playing using Minecraft's Bedrock Edition or not.@Nullable Double
parseDouble
(String str) Parses the string to a double@Nullable Integer
Parses the string to an int@Nullable ItemStack
parseItemStack
(String str) Tries to form anItemStack
given by a String.@Nullable Long
Parses the string to a longcom.google.gson.JsonObject
parseSNBTAsJson
(String nbt) Converts a SNBT (String format of NBT) to a JsonObject.void
playCustomSound
(Player player, Location location, String sound, float volume, float pitch) Plays a custom sound - even on a non-main thread.void
playCustomSound
(Location location, String sound, float volume, float pitch) Plays a custom sound - even on a non-main thread.void
Plays a sound - even on a non-main thread.void
Plays a sound - even on a non-main thread.replacePAPIPlaceholders
(String str, Player player) Will return a new String will all the PAPI (or similar supported plugins) being replaced.boolean
setPlayerArmor
(Player player, ItemStack armor, boolean force) Tries to make a player wear armor (ie automatically puts an items in a players armor slot)default void
setUnbreakable
(ItemStack is, boolean unbreakable) Sets the "unbreakable" tag to the given item.void
setUnbreakable
(ItemMeta im, boolean unbreakable) Sets the "unbreakable" tag to the given ItemMeta.void
synchronize
(Runnable runn) Runs a given task on the main thread.void
teleportAsync
(Entity entity, Location loc, @Nullable Runnable callback) Allows you to teleport entities asynchronously on 1.14+
-
Method Details
-
getJavaVersion
int getJavaVersion()Returns the current java version.- Returns:
- The current java version used in this JVM
-
parseInt
Parses the string to an int- Parameters:
str
- The string we want to parse- Returns:
- Parsed string. Null if it's not valid
-
parseLong
Parses the string to a long- Parameters:
str
- The string we want to parse- Returns:
- Parsed string. Null if it's not valid
-
parseDouble
Parses the string to a double- Parameters:
str
- The string we want to parse- Returns:
- Parsed string. Null if it's not valid
-
formatNumber
Tries to format the number in a human-readable way.Uses system or user configuration to understand in which language it shall format in.
Example: When user is running an english system and you're passing the number 1989321, then this method returns "1,989,321"- Parameters:
num
- The number you want to get formatted- Returns:
- The formatted number
-
formatNumber
Tries to format the number in a human-readable way.Uses system or user configuration to understand in which language it shall format in.
Example: When user is running an english system and you're passing the number 1989321.5555, then this method returns "1,989,321.555,5"- Parameters:
num
- The number you want to get formatted- Returns:
- The formatted number
-
formatNumber
Tries to format the number in a human-readable way.Uses system or user configuration to understand in which language it shall format in.
Example: When user is running an english system and you're passing the number 1989321.5555, then this method returns "1,989,321.555,5"- Parameters:
num
- The number you want to get formatted- Returns:
- The formatted number
-
formatDuration
Formats the duration in a human-readable string.Example: 5h 10m 30s. Exact value depends on the configuration of the user.
- Parameters:
duration
- the duration to format- Returns:
- The human-readable format
-
formatDuration
Formats the milliseconds duration in a human-readable string.Example: 5h 10m 30s. Exact value depends on the configuration of the user.
- Parameters:
duration
- the duration to format in milliseconds- Returns:
- The human-readable format
-
evaluateString
Tries to evaluate an equation passed in as a String.Uses the javaluator library internally. Example: If you pass in the string
(e^3-1)*sin(pi/4)*ln(pi^2)
, the result would be 30.8974331526.- Parameters:
expression
- The expression you want to evaluate- Returns:
- The solution to the expression. May be
null
if the equation is invalid.
-
parseItemStack
Tries to form anItemStack
given by a String. The same format as every else in the plugin configurations is being used.The opposite of that is
composeItemStack(ItemStack)
.- Parameters:
str
- The String that shall get parsed- Returns:
- The resulting ItemStack. May be
null
if the given String is nonsense
-
composeItemStack
Forms a human-readable String given by an ItemStack. The same format as every else in the plugin configurations is being used.The opposite of that is
parseItemStack(String)
.- Parameters:
is
- The ItemStack that shall be parsed- Returns:
- The resulting human-readable String
-
dye
Tries to apply a color to anItemStack
if possible. This includes e.g. dying a leather armor or changing the wool color.It's possible that this method doesn't return a new instance and instead applies the effect to the instance given.
- Parameters:
is
- The item that shall be dyedcolor
- The color that needs to be applied to the item- Returns:
- Possibly a new instance depending on the internal method used. Otherwise the same ItemStack instance
-
setUnbreakable
Sets the "unbreakable" tag to the given ItemMeta.You should use this method instead of
ItemMeta.setUnbreakable(boolean)
as that method has involved in some spigot versions and by that might not work for any user.- Parameters:
im
- The ItemMeta of the item whose tag shall be changedunbreakable
-true
causes the item to not lose any damage
-
setUnbreakable
Sets the "unbreakable" tag to the given item.You should use this method instead of
ItemMeta.setUnbreakable(boolean)
as that method has involved in some spigot versions and by that might not work for any user.- Parameters:
is
- The item whose tag shall be changedunbreakable
-true
causes the item to not lose any damage
-
replacePAPIPlaceholders
Will return a new String will all the PAPI (or similar supported plugins) being replaced.Example: "Hi, my K/D is %mbedwars_stats-kd%"
will be become: "Hi, my K/D is 1.5"- Parameters:
str
- The raw string- Returns:
- The new formatted string
-
getPlayerNickName
Tries to obtain the nicked name of a plugin which possibly has been changed by a third-party nick plugin.The plugin automatically injects itself into quite a few nick plugins automatically and tries to obtain the players nick name using their API. In cases where the player is not nicked the method returns
null
.- Parameters:
player
- The player whose nickname we want to find out- Returns:
- The nickname of the player.
null
if he doesn't have one
-
getNickedPlayerRealName
Nicknaming plugins might replaceHumanEntity.getName()
in favour for the nicked name. This method returns the player's real name.The plugin automatically injects itself into quite a few nick plugins automatically and tries to obtain the players real name using their API.
- Parameters:
player
- The player from who want to find out the real name- Returns:
- His real username
-
getPlayerDisplayName
Returns the display name of a player that shall be shown to the public.Generally, this method works similar to
getPlayerNickName(Player)
. Only that it returns the player's name if he isn't nicked. Meaning that this method never returns null.- Parameters:
player
- The player whose public display name we want to find out- Returns:
- His name that can safely be shown to the public
-
isBedrockPlayer
Returns whether the player is playing using Minecraft's Bedrock Edition or not.- Parameters:
uuid
- The id of the player- Returns:
true
when we are able to confirm that
-
isBedrockPlayer
Returns whether the player is playing using Minecraft's Bedrock Edition or not.- Parameters:
player
- The player we want to check- Returns:
true
when we are able to confirm that
-
getEntityTypeByName
Tries to identify the type of an entity given by its name.- Parameters:
name
- The name of the entity- Returns:
- The EntityType that might fit.
null
if none was found
-
copy
Copies bytes from an InputStream to an OutputStream.
This method buffers the input internally, so there is no need to use a BufferedInputStream.
Large streams (over 2GB) will return a bytes copied value of -1 after the copy has completed since the correct number of bytes cannot be returned as an int. For large streams use the copyLarge(InputStream, OutputStream) method.- Parameters:
is
- The InputStream to read.os
- The OutputStream to write.- Returns:
- The number of bytes copied, or -1 if greater than Integer.MAX_VALUE.
- Throws:
IOException
- If an I/O error occurs.
-
parseSNBTAsJson
Converts a SNBT (String format of NBT) to a JsonObject.- Parameters:
nbt
- The data tag- Returns:
- The converted JsonObject containing the info of the given SNBT tag.
- Throws:
IllegalArgumentException
- When it failed to parse the NBT
-
composeJsonAsSNBT
Tries to convert a JsonObject to a SNBT data tag.The process is not perfect due to the way of how json stores their numbers etc.
- Parameters:
json
- The json object- Returns:
- The converted NBT string containing the info of the JsonObject.
-
setPlayerArmor
Tries to make a player wear armor (ie automatically puts an items in a players armor slot)- Parameters:
player
- the player we are giving the armor toarmor
- itemstack of armor that the player should wearforce
- weather or not to override an existing piece of armor- Returns:
- whether or not the armor was given successfully
-
givePlayerItem
Properly gives an item to a player.If a players Inventory is full, the items will be dropped close to them. No items will be deleted/lost (Unlike when using Inventory#addItem())
- Parameters:
player
- the player we are giving the item toitemStack
- the item that is being given to the player
-
getMaterialByName
Tries to identify a material given by its name.- Parameters:
name
- The name of the material- Returns:
- The Material that might fit.
null
if none was found
-
getEffectByName
Tries to identify an effect given by its name.- Parameters:
name
- The name of the effect- Returns:
- The Effect that might fit.
null
if none was found
-
getPotionTypeByName
Tries to identify a potion type given by its name.- Parameters:
name
- The name of the potion type- Returns:
- The type that might fit.
null
if none was found
-
getSoundByName
Tries to identify a sound given by its name.- Parameters:
name
- The name of the sound- Returns:
- The sound that might fit.
null
if none was found
-
getEnchantmentByName
Tries to identify an enchantment given by its name.- Parameters:
name
- The name of the enchantment- Returns:
- The enchantment that might fit.
null
if none was found
-
getBlockVariant
Returns the block variant of a material.Sometimes there are multiple entries within Material for basically the same material, but with the only difference being that one is thought to be added to the inventory and the other one to be placed. This is especially common in 1.12 and previous versions.
- Parameters:
mat
- The input material- Returns:
- The output material, possibly the same one as the input one
-
getInventoryVariant
Returns the inventory variant of a material.Sometimes there are multiple entries within Material for basically the same material, but with the only difference being that one is thought to be added to the inventory and the other one to be placed. This is especially common in 1.12 and previous versions.
- Parameters:
mat
- The input material- Returns:
- The output material, possibly the same one as the input one
-
synchronize
Runs a given task on the main thread.Due to performance reasons, it's not granted that the task will be executed immediately with the next tick-
- Parameters:
runn
- The task that shall be run on the main thread
-
getMinHeight
Returns the minimum height of an arena.Basically returns World#getMinHeight() on 1.17+. Always returns 0 on older version. Useful when you're trying to add support for newer versions.
- Parameters:
world
- The world- Returns:
- The minimum height at which players may place blocks at
-
getPlayerSkinData
Gets the texture & signature of the player's skin.Note that the method may return
null
when the skin generally can't be seen, such as when the server is on cracked mode, when the server hasn't fetched the skin yet or when no custom skin has been defined by the player.- Parameters:
player
- The player from whom we want to fetch it- Returns:
- A pair, with the key being the texture, and the value being the signature. May be
null
if he doesn't have one
-
getBukkitChatColorFromBungee
Gets the ChatColor (from the Bukkit package) that fits the most to the Bungee color.This method also supports hex colors.
- Parameters:
color
- The color instance from the Bungee package- Returns:
- The matching Spigot color
-
getBlockAsync
Allows you to retrieve and modify a block asynchronously on 1.14+If run on unsupported versions, the loading of the block, as well as the execution callback will occur synchronously
- Parameters:
location
- the location of the blockcallback
- called when the block is ready to be used
-
getBlockAsync
Allows you to retrieve and modify a block asynchronously on 1.14+If run on unsupported versions, the loading of the block, as well as the execution callback will occur synchronously
- Parameters:
world
- the world of the blockxyz
- the coordinates if the blockcallback
- called when the block is ready to be used
-
getBlockAsync
Allows you to retrieve and modify a block asynchronously on 1.14+If run on unsupported versions, the loading of the block, as well as the execution callback will occur synchronously
- Parameters:
world
- the world of the blockx
- the x coordinate of the blocky
- the y coordinate of the blockz
- the z coordinate of the blockcallback
- called when the block is ready to be used
-
getChunkAsync
Allows you to retrieve and modify a block asynchronously on 1.14+If run on unsupported versions, the loading of the chunk, as well as the execution callback will occur synchronously
- Parameters:
world
- the world of the chunkx
- the x coordinate of the chunkz
- they y coordinate of the chunkcallback
- called when the chunk is ready to be used
-
teleportAsync
Allows you to teleport entities asynchronously on 1.14+If run on unsupported versions, the teleport and callback will be called synchronously. The callback can be null if nothing needs to be done after the entity has teleported.
- Parameters:
entity
- The entity being teleportedloc
- The location the entity should be teleported tocallback
- Called after the entity has been teleported
-
playSound
Plays a sound - even on a non-main thread.It is not possible anymore to play a sound on a non-main thread since 1.19. This method fixes it, but you may surely use this method on the main thread and on older versions as well.
- Parameters:
player
- The player who shall hear the soundlocation
- The location where the sound shall be playedsound
- The sound that shall be playedvolume
- The volume of the soundpitch
- The pitch of the sound
-
playSound
Plays a sound - even on a non-main thread.It is not possible anymore to play a sound on a non-main thread since 1.19. This method fixes it, but you may surely use this method on the main thread and on older versions as well.
- Parameters:
location
- The location where the sound shall be playedsound
- The sound that shall be playedvolume
- The volume of the soundpitch
- The pitch of the sound
-
playCustomSound
Plays a custom sound - even on a non-main thread.It is not possible anymore to play a sound on a non-main thread since 1.19. This method fixes it, but you may surely use this method on the main thread and on older versions as well.
This method does not play vanilla sounds and only works on 1.9+
- Parameters:
player
- The player who shall hear the soundlocation
- The location where the sound shall be playedsound
- The sound that shall be playedvolume
- The volume of the soundpitch
- The pitch of the sound
-
playCustomSound
Plays a custom sound - even on a non-main thread.It is not possible anymore to play a sound on a non-main thread since 1.19. This method fixes it, but you may surely use this method on the main thread and on older versions as well.
This method does not play vanilla sounds and only works on 1.9+
- Parameters:
location
- The location where the sound shall be playedsound
- The sound that shall be playedvolume
- The volume of the soundpitch
- The pitch of the sound
-
get
Contains utility stuff.- Returns:
- The global Helper instance
-