Package net.dv8tion.jda.api.utils
Class MiscUtil
java.lang.Object
net.dv8tion.jda.api.utils.MiscUtil
Utility methods for various aspects of the API.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Can be used to append a String to a formatter.static int
getShardForGuild
(long guildId, int shards) Returns the shard id the given guild will be loaded on for the given amount of shards.static int
getShardForGuild
(String guildId, int shards) Returns the shard id the given guild will be loaded on for the given amount of shards.static int
getShardForGuild
(Guild guild, int shards) Returns the shard id the givenGuild
will be loaded on for the given amount of shards.static void
locked
(ReentrantLock lock, Runnable task) static <E> E
locked
(ReentrantLock lock, Supplier<E> task) static <T> gnu.trove.map.TLongObjectMap
<T> Generates a new thread-safeTLongObjectMap
static long
static long
parseSnowflake
(String input) static void
Tries to acquire the provided lock in a 10 second timeframe.
-
Constructor Details
-
MiscUtil
public MiscUtil()
-
-
Method Details
-
getShardForGuild
public static int getShardForGuild(long guildId, int shards) Returns the shard id the given guild will be loaded on for the given amount of shards.Discord determines which guilds a shard is connect to using the following format:
shardId == (guildId >>> 22) % totalShards
Source for formula: Discord Documentation- Parameters:
guildId
- The guild id.shards
- The amount of shards.- Returns:
- The shard id for the guild.
-
getShardForGuild
Returns the shard id the given guild will be loaded on for the given amount of shards.Discord determines which guilds a shard is connect to using the following format:
shardId == (guildId >>> 22) % totalShards
Source for formula: Discord Documentation- Parameters:
guildId
- The guild id.shards
- The amount of shards.- Returns:
- The shard id for the guild.
-
getShardForGuild
Returns the shard id the givenGuild
will be loaded on for the given amount of shards.Discord determines which guilds a shard is connect to using the following format:
shardId == (guildId >>> 22) % totalShards
Source for formula: Discord Documentation- Parameters:
guild
- The guild.shards
- The amount of shards.- Returns:
- The shard id for the guild.
-
newLongMap
Generates a new thread-safeTLongObjectMap
- Type Parameters:
T
- The Object type- Returns:
- a new thread-safe
TLongObjectMap
-
parseLong
-
parseSnowflake
-
locked
-
locked
-
tryLock
Tries to acquire the provided lock in a 10 second timeframe.- Parameters:
lock
- The lock to acquire- Throws:
IllegalStateException
- If the lock could not be acquired
-
appendTo
public static void appendTo(Formatter formatter, int width, int precision, boolean leftJustified, String out) Can be used to append a String to a formatter.- Parameters:
formatter
- TheFormatter
width
- Minimum width to meet, filled with space if neededprecision
- Maximum amount of characters to appendleftJustified
- Whether or not to left-justify the valueout
- The String to append
-