pub struct PlayerData { /* private fields */ }Expand description
The response data corresponding to this endpoint.
§This struct implements some convenience functions to parse hypixel api data:
§Player name
The player name is spread out over multiple fields, use PlayerData::name
to get a correct one (like the api does).
§Network xp and lvl
Hypixel Network XP and Level are stored in two separate fields in a specific format.
Use PlayerData::network_xp and PlayerData::network_level for these values.
§Ranks
Ranks are spread out over 5 fields!
Always use PlayerData::staff_level and PlayerData::package_rank to get
the correct precedence. See this FAQ
for more information.
§Game stats
All game stats are captured generically. To get a specific one,
use PlayerData::stat_value or define a corresponding struct
and use PlayerData::stat_json.
§Other properties
You can get any property that the functions in this struct don’t cover
by using PlayerData::property_value or defining a corresponding struct
and use PlayerData::property_json.
Implementations§
Source§impl PlayerData
impl PlayerData
Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
Returns the player’s name.
This follows the implementation in PlayerReply.java
in the official java implementation of the Hypixel Public API.
In this Rust implementation, currently it does the following:\
- if
"displayname"is present, return it - else if
"knownAliases"is present, return the last element of this list (most recent name) - else if
"playername"is present, return it - else if
"username"is present, return it - else no username could be returned
Sourcepub fn network_xp(&self) -> u64
pub fn network_xp(&self) -> u64
Returns the total amount of network experience the player has earned.
If no experience or level field was included, 0 will be used instead.
Sourcepub fn network_level(&self) -> f64
pub fn network_level(&self) -> f64
Returns the player’s precise network level, including their progress to the next level.
Sourcepub fn karma(&self) -> u64
pub fn karma(&self) -> u64
Returns the total amount of karma points earned by the player.
If this field is not present, 0 is returned.
Sourcepub fn first_login(&self) -> Option<DateTime<Local>>
pub fn first_login(&self) -> Option<DateTime<Local>>
Returns the date when the player first connected to Hypixel.
Sourcepub fn last_login(&self) -> Option<DateTime<Local>>
pub fn last_login(&self) -> Option<DateTime<Local>>
Returns the last known time when the player connected to the main Hypixel network.
Sourcepub fn last_logout(&self) -> Option<DateTime<Local>>
pub fn last_logout(&self) -> Option<DateTime<Local>>
Returns the last known time when the player disconnected from the main Hypixel network.
Sourcepub fn selected_plus_color(&self) -> ColorCodes
pub fn selected_plus_color(&self) -> ColorCodes
Returns the color of the player’s "+"s if they have MVP+ or MVP++.
If they do not have either rank, or if they have not selected a color, "RED" is returned as the default.
Sourcepub fn superstar_tag_color(&self) -> ColorCodes
pub fn superstar_tag_color(&self) -> ColorCodes
Returns the color of the player’s name tag if they have MVP++.
Defaults to ColorCodes::Gold.
Sourcepub fn staff_level(&self) -> &StaffLevel
pub fn staff_level(&self) -> &StaffLevel
Returns the special rank of players if present.
Defaults to StaffLevel::Normal.
Sourcepub fn package_rank(&self) -> PackageRank
pub fn package_rank(&self) -> PackageRank
Returns the highest in precedence rank that the player has.
See this FAQ.
This function only considers values in PackageRank.
Sourcepub fn has_rank(&self) -> bool
pub fn has_rank(&self) -> bool
Returns true if the player has either a special StaffLevel rank
or a PackageRank rank.
Defaults to false.
Sourcepub fn on_build_team(&self) -> bool
pub fn on_build_team(&self) -> bool
Returns true if the player is part of the Hypixel Build Team
Defaults to false.
Sourcepub fn stat_value(&self, name: &str) -> Option<&Value>
pub fn stat_value(&self, name: &str) -> Option<&Value>
Returns the json entry corresponding to name, if present.
See PlayerData::stat_json for a possibly more convenient function.
Sourcepub fn stat_json<T: DeserializeOwned>(
&self,
name: &str,
) -> Option<Result<T, HypixelApiError>>
pub fn stat_json<T: DeserializeOwned>( &self, name: &str, ) -> Option<Result<T, HypixelApiError>>
Returns the json entry corresponding to name, if present,
and automatically deserialized into T.
§Note
This function clones the data in order to deserialize it. In the future this could be updated to automatically deserialize stable games.
Sourcepub fn property_value(&self, name: &str) -> Option<&Value>
pub fn property_value(&self, name: &str) -> Option<&Value>
Returns any other property this struct does not capture explicitly already, if present.
See PlayerData::property_json for a possibly more convenient function.
Sourcepub fn property_json<T: DeserializeOwned>(
&self,
name: &str,
) -> Option<Result<T, HypixelApiError>>
pub fn property_json<T: DeserializeOwned>( &self, name: &str, ) -> Option<Result<T, HypixelApiError>>
Returns any other property this struct does not capture
explicitly already, if present, and automatically deserializes
it into T.
§Note
This function clones the data in order to deserialize it. For maximum efficiency, always consider contributing stable fields to the repository, thank you!
Trait Implementations§
Source§impl Clone for PlayerData
impl Clone for PlayerData
Source§fn clone(&self) -> PlayerData
fn clone(&self) -> PlayerData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more