PlayerData

Struct PlayerData 

Source
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

Source

pub fn uuid(&self) -> Uuid

Returns the player’s UUID.

Source

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:\

  1. if "displayname" is present, return it
  2. else if "knownAliases" is present, return the last element of this list (most recent name)
  3. else if "playername" is present, return it
  4. else if "username" is present, return it
  5. else no username could be returned
Source

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.

Source

pub fn network_level(&self) -> f64

Returns the player’s precise network level, including their progress to the next level.

Source

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.

Source

pub fn first_login(&self) -> Option<DateTime<Local>>

Returns the date when the player first connected to Hypixel.

Source

pub fn last_login(&self) -> Option<DateTime<Local>>

Returns the last known time when the player connected to the main Hypixel network.

Source

pub fn last_logout(&self) -> Option<DateTime<Local>>

Returns the last known time when the player disconnected from the main Hypixel network.

Source

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.

Source

pub fn superstar_tag_color(&self) -> ColorCodes

Returns the color of the player’s name tag if they have MVP++.

Defaults to ColorCodes::Gold.

Source

pub fn staff_level(&self) -> &StaffLevel

Returns the special rank of players if present.

Defaults to StaffLevel::Normal.

Source

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.

Source

pub fn has_rank(&self) -> bool

Returns true if the player has either a special StaffLevel rank or a PackageRank rank.

Defaults to false.

Source

pub fn on_build_team(&self) -> bool

Returns true if the player is part of the Hypixel Build Team

Defaults to false.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> PlayerData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PlayerData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PlayerData

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,