Package net.dv8tion.jda.core.entities
Class Game
- java.lang.Object
-
- net.dv8tion.jda.core.entities.Game
-
- Direct Known Subclasses:
RichPresence
public class Game extends java.lang.Object
Represents a DiscordGame
.
This should contain all information provided from Discord about a Game.- Since:
- 2.1
- Author:
- John A. Grosh
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Game.GameType
The type game being played, differentiating between a game and stream types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RichPresence
asRichPresence()
RichPresence
representation of this Game.boolean
equals(java.lang.Object o)
java.lang.String
getName()
The displayed name of theGame
.RichPresence.Timestamps
getTimestamps()
Information on the match duration, start, and end.Game.GameType
getType()
The type ofGame
.java.lang.String
getUrl()
The URL of theGame
if the game is actually a Stream.int
hashCode()
boolean
isRich()
static boolean
isValidStreamingUrl(java.lang.String url)
Checks if a given String is a valid Twitch url (ie, one that will display "Streaming" on the Discord client).static Game
listening(java.lang.String name)
Creates a new Game instance with the specified name.static Game
of(Game.GameType type, java.lang.String name)
Creates a new Game instance with the specified name and url.static Game
of(Game.GameType type, java.lang.String name, java.lang.String url)
Creates a new Game instance with the specified name and url.static Game
playing(java.lang.String name)
Creates a new Game instance with the specified name.static Game
streaming(java.lang.String name, java.lang.String url)
Creates a new Game instance with the specified name and url.java.lang.String
toString()
static Game
watching(java.lang.String name)
Creates a new Game instance with the specified name.
-
-
-
Method Detail
-
isRich
public boolean isRich()
- Returns:
true
if this is aRichPresence
-
asRichPresence
public RichPresence asRichPresence()
RichPresence
representation of this Game.- Returns:
- RichPresence or
null
ifisRich()
returnsfalse
-
getName
public java.lang.String getName()
The displayed name of theGame
. If no name has been set, this returns null.- Returns:
- Possibly-null String containing the Game's name.
-
getUrl
public java.lang.String getUrl()
The URL of theGame
if the game is actually a Stream.
This will return null for regular games.- Returns:
- Possibly-null String containing the Game's URL.
-
getType
public Game.GameType getType()
The type ofGame
.- Returns:
- Never-null
GameType
representing the type of Game
-
getTimestamps
@Nullable public RichPresence.Timestamps getTimestamps()
Information on the match duration, start, and end.- Returns:
Timestamps
wrapper ofnull
if unset
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
playing
public static Game playing(java.lang.String name)
Creates a new Game instance with the specified name.
In order to appear as "streaming" in the official client you must provide a valid (see documentation of method) streaming URL inGame.streaming(String, String)
.- Parameters:
name
- The not-null name of the newly created game- Returns:
- A valid Game instance with the provided name with
Game.GameType.DEFAULT
- Throws:
java.lang.IllegalArgumentException
- if the specified name is null, empty or blank
-
streaming
public static Game streaming(java.lang.String name, java.lang.String url)
Creates a new Game instance with the specified name and url.
The specified URL must be valid according to discord standards in order to display as "streaming" in the official client. A valid streaming URL must be derived fromhttps://twitch.tv/
and can be verified usingisValidStreamingUrl(String)
. (see documentation)- Parameters:
name
- The not-null name of the newly created gameurl
- The streaming url to use, required to display as "streaming"- Returns:
- A valid Game instance with the provided name and url
- Throws:
java.lang.IllegalArgumentException
- If the specified name is null or empty- See Also:
isValidStreamingUrl(String)
-
listening
public static Game listening(java.lang.String name)
Creates a new Game instance with the specified name.
This will display asListening name
in the official client- Parameters:
name
- The not-null name of the newly created game- Returns:
- A valid Game instance with the provided name with
Game.GameType.LISTENING
- Throws:
java.lang.IllegalArgumentException
- if the specified name is null, empty or blank
-
watching
@Incubating public static Game watching(java.lang.String name)
Creates a new Game instance with the specified name.
This will display asWatching name
in the official client- Parameters:
name
- The not-null name of the newly created game- Returns:
- A valid Game instance with the provided name with
Game.GameType.WATCHING
- Throws:
java.lang.IllegalArgumentException
- if the specified name is null, empty or blank- Incubating:
- This feature is not yet confirmed for the official bot API
-
of
public static Game of(Game.GameType type, java.lang.String name)
Creates a new Game instance with the specified name and url.- Parameters:
type
- TheGameType
to usename
- The not-null name of the newly created game- Returns:
- A valid Game instance with the provided name and url
- Throws:
java.lang.IllegalArgumentException
- If the specified name is null or empty
-
of
public static Game of(Game.GameType type, java.lang.String name, java.lang.String url)
Creates a new Game instance with the specified name and url.
The provided url would only be used forGameType.STREAMING
and should be a twitch url.- Parameters:
type
- TheGameType
to usename
- The not-null name of the newly created gameurl
- The streaming url to use, required to display as "streaming".- Returns:
- A valid Game instance with the provided name and url
- Throws:
java.lang.IllegalArgumentException
- If the specified name is null or empty- See Also:
isValidStreamingUrl(String)
-
isValidStreamingUrl
public static boolean isValidStreamingUrl(java.lang.String url)
Checks if a given String is a valid Twitch url (ie, one that will display "Streaming" on the Discord client).- Parameters:
url
- The url to check.- Returns:
- True if the provided url is valid for triggering Discord's streaming status
-
-