Class OfflinePlayer
- Direct Known Subclasses:
ChatPluginProxyPlayer
,ChatPluginServerPlayer
This object contains just two values: a UUID
and a name.
You can manually create offline players to interact with the plugin's code
(for example with the punishment system) from an online player or just a
UUID and a name. They may also be used to interact with the storage.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOfflinePlayer
(String name) Gets an offline player by their name.OfflinePlayer
(UUID uuid) Gets an offline player by their UUID.OfflinePlayer
(UUID uuid, String name) Constructs an offline player using given UUID and name.OfflinePlayer
(PlayerAdapter player) Constructs an offline player using an existingPlayerAdapter
's UUID and name.OfflinePlayer
(CommandSenderAdapter sender) Constructs an offline player using an existingCommandSenderAdapter
's UUID and name. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if another object is an instance ofOfflinePlayer
and if this player'sgetUUID()
(if running on online mode) orgetName()
(if running on offline mode) value is equal to the other object's one.Gets this player's IP address.getName()
Gets this player's name.getUUID()
Gets this player's UUID.int
hashCode()
Gets this player's hash code.boolean
hasPermission
(String permission) Checks if this player has the specified permission.boolean
Checks if this player is contained in theDataContainer.PLAYERS
data container usingStorageConnector.isPlayerStored(OfflinePlayer)
.boolean
isLoaded()
Checks if this player is loaded.boolean
isOnline()
Checks if this player is online.boolean
Checks if the specified player corresponds to a registered premium username.Gets this player's correspondingPlayerAdapter
object.Gets this player's correspondingChatPluginProxyPlayer
object.Gets this player's correspondingChatPluginServerPlayer
object.
-
Constructor Details
-
OfflinePlayer
Constructs an offline player using an existingPlayerAdapter
's UUID and name.- Parameters:
player
- Online player
-
OfflinePlayer
Constructs an offline player using an existingCommandSenderAdapter
's UUID and name.- Parameters:
sender
- Command sender
-
OfflinePlayer
Constructs an offline player using given UUID and name.Note: this constructor is not checked and you should use it only if you are sure that the specified UUID and name corresponds to an existing account, which could be either premium or unauthenticated.
- Parameters:
uuid
- Player's UUIDname
- Player's name
-
OfflinePlayer
Gets an offline player by their UUID.In order to obtain their name, the following operations will be performed:
- if they are online, use the online player's name
- check if they are saved in
DataContainer.PLAYERS
- check the
UUID.version()
:
if == 3, throwUnsupportedOperationException
if == 4, check if the UUID belongs to a premium account:
if true, fetch the name from Mojang's servers
if false, set name tonull
and UUID toUtils.NIL_UUID
Note: this constructor may take some time to be executed when
ChatPlugin.isOnlineMode()
: async calls are recommended.- Parameters:
uuid
- Player's UUID- Throws:
UnsupportedOperationException
- When trying to obtain the name using an offline UUIDSQLException
- If a database error occurrs (StorageMethod.isDatabase()
)IOException
- If name fetching is required and could not be completed
-
OfflinePlayer
Gets an offline player by their name.In order to obtain their UUID, the following operations will be performed:
- if specified name
!
Utils.isValidUsername(String)
, throwIllegalArgumentException
- if they are online, use the online player's UUID and name
- check if they are saved in
DataContainer.PLAYERS
:
if true, use the UUID and name stored in the storage
if false, check ifChatPlugin.isOnlineMode()
:
if false, useUUIDFetcher.getOfflineUUID(String)
if true, check if the name belongs to a premium account:
if true, fetch the name from Mojang's servers
if false, set name tonull
and UUID toUtils.NIL_UUID
Note: this constructor may take some time to be executed when
ChatPlugin.isOnlineMode()
: async calls are recommended.- Parameters:
name
- Player's name- Throws:
IllegalArgumentException
- If specified name!
Utils.isValidUsername(String)
SQLException
- If a database error occurrs (StorageMethod.isDatabase()
)IOException
- If name or UUID fetching is required and could not be completed
- if specified name
-
-
Method Details
-
isPremiumAccount
public boolean isPremiumAccount()Checks if the specified player corresponds to a registered premium username.- Returns:
- Whether this player is premium
-
equals
Checks if another object is an instance ofOfflinePlayer
and if this player'sgetUUID()
(if running on online mode) orgetName()
(if running on offline mode) value is equal to the other object's one.- Overrides:
equals
in classObject
- Parameters:
obj
- Object to compare- Returns:
- Whether the two objects are equal
- Throws:
IllegalStateException
- IfChatPlugin.isOnlineMode()
cannot be run yet
-
hashCode
public int hashCode()Gets this player's hash code.Will return
getUUID()
's (if running on online mode) orgetName()
's (if running on offline mode) hash code or -1 if the name isnull
.- Overrides:
hashCode
in classObject
- Returns:
- Player's hash code
- Throws:
IllegalStateException
- IfChatPlugin.isOnlineMode()
cannot be run yet
-
getUUID
Gets this player's UUID.Will return
Utils.NIL_UUID
ifChatPlugin.isOnlineMode()
and the UUID or the name specified at construction did not belong to a premium player.- Returns:
- Player's UUID
-
getName
Gets this player's name.Will return
null
ifChatPlugin.isOnlineMode()
and the UUID or the name specified at construction did not belong to a premium player.- Returns:
- Player's name
-
getIPAddress
Gets this player's IP address.Will grab it from the storage if they are offline, but it will return
null
if they have never joined the server before.Note: BungeeCord supports connections via Unix domain sockets. If this method is called on a player connected through a Unix domain socket, "127.0.0.1" is returned.
- Returns:
- Player's IP address
-
isOnline
public boolean isOnline()Checks if this player is online.- Returns:
- Whether this player is online
-
isLoaded
public boolean isLoaded()Checks if this player is loaded.- Returns:
- Whether this player is loaded
- See Also:
-
hasPlayedBefore
public boolean hasPlayedBefore()Checks if this player is contained in theDataContainer.PLAYERS
data container usingStorageConnector.isPlayerStored(OfflinePlayer)
.- Returns:
- Whether this player has played before
-
hasPermission
Checks if this player has the specified permission.Will always return
false
unlessisOnline()
or aPermissionIntegration
is enabled: in those cases, it will be actually checked.Note: this method might take some time to be executed: async calls are recommended.
- Parameters:
permission
- Permission to check- Returns:
- Whether this player has the permission
-
toAdapter
Gets this player's correspondingPlayerAdapter
object.Will return
null
if!
isOnline()
.- Returns:
- Corresponding
PlayerAdapter
-
toServerPlayer
Gets this player's correspondingChatPluginServerPlayer
object.Will return
null
if!
isLoaded()
.- Returns:
- Corresponding
ChatPluginServerPlayer
- Throws:
UnsupportedOperationException
- IfEnvironment.isProxy()
-
toProxyPlayer
Gets this player's correspondingChatPluginProxyPlayer
object.Will return
null
if!
isLoaded()
.- Returns:
- Corresponding
ChatPluginProxyPlayer
- Throws:
UnsupportedOperationException
- If!
Environment.isProxy()
-