Class CompatibleProfile
- java.lang.Object
-
- com.github.crashdemons.playerheads.compatibility.CompatibleProfile
-
public abstract class CompatibleProfile extends Object
Utility class that may be used by compatibility providers to handle head profile information. A profile is defined as a username,id, and optional properties such as a texture. Using this class is currently optional except where required in CompatibilityProvider Implementations should treat a null or empty value for any field as not existing/not present.- Since:
- 5.2.13-SNAPSHOT
- Author:
- crashdemons (crashenator at gmail.com)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CompatibleProfile()
Internal constructor only be used for blank objects by child classes.CompatibleProfile(Object internalProfile)
Constructs a profile object from some implementation-defined representation of profiles.CompatibleProfile(UUID id, String name)
Constructs an object containing information about a head.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description UUID
getId()
Get the UUID associated with the head profile.String
getName()
The username associated with the head profile.String
getOwner()
Get the owner username.OfflinePlayer
getOwningPlayer()
Gets the OfflinePlayer associated with the profile.String
getTextures()
Get the texture Base64 textures tag string associated with the profile.protected static boolean
hasField(String obj)
Utility method for checking if the username argument is presentprotected static boolean
hasField(UUID obj)
Utility method for checking if the UUID argument is presentboolean
hasId()
whether the id is present (not null)boolean
hasName()
whether the username is present (not null)boolean
hasOwner()
Whether the owner username is present equivalent to hasName() but provided for Bukkit similarity.boolean
hasRequiredFields()
Checks if the required profile fields are filled in this profileprotected static boolean
hasRequiredFields(UUID id, String name)
Utility method for checking if the required profile fields are filled.boolean
hasTextures()
whether the texture string is present (not null)static boolean
isValid(CompatibleProfile profile)
Determines if a CompatibleProfile is valid.abstract void
setFromInternalObject(Object internalProfile)
Sets fields/values of the profile object from an implementation-defined representation of profiles.void
setId(UUID id)
Set the UUID associated with the head profile.void
setName(String name)
Set the username associated with the head profile.void
setTextures(String texture)
Set the texture Base64 textures tag string associated with the profile.abstract Object
toInternalObject()
Gets an implementation-defined representation for the profile information.
-
-
-
Field Detail
-
id
protected UUID id
The head/profile owner's UUID. Can be null if 'name' is not null.
-
name
protected String name
The head/profile owner's username. Can be null if 'id' is not null. For custom-textured heads that are not tied to a player - this should be null.
-
textures
protected String textures
The Base64-encoded Texture URL tags associated with the profile. can be null.
-
-
Constructor Detail
-
CompatibleProfile
protected CompatibleProfile()
Internal constructor only be used for blank objects by child classes.
-
CompatibleProfile
public CompatibleProfile(@Nullable UUID id, @Nullable String name)
Constructs an object containing information about a head.- Parameters:
id
- the UUID of the head (either a player's or a unique one for each head type)name
- the username of the head (custom heads should be null)
-
CompatibleProfile
public CompatibleProfile(Object internalProfile)
Constructs a profile object from some implementation-defined representation of profiles. This method should be overridden to prevent exceptions- Parameters:
internalProfile
- the implementation-defined representation of a profile.
-
-
Method Detail
-
hasField
protected static boolean hasField(UUID obj)
Utility method for checking if the UUID argument is present- Parameters:
obj
- the UUID object- Returns:
- whether it is present
-
hasField
protected static boolean hasField(String obj)
Utility method for checking if the username argument is present- Parameters:
obj
- the username object- Returns:
- whether it is present (not null and not empty)
-
hasRequiredFields
protected static boolean hasRequiredFields(UUID id, String name)
Utility method for checking if the required profile fields are filled. This checks that either an ID, Name, or both are present. At least one is requiired.- Parameters:
id
- the UUID argument for a profile, or nullname
- the username argument for a profile, or null- Returns:
- whether the preconditions are filled for a profile.
-
isValid
public static boolean isValid(CompatibleProfile profile)
Determines if a CompatibleProfile is valid. This checks that the profile is not null and has the required fields (at least a UUID or a username). If the profile is invalid, it can be considered a dummy profile or empty, similar to being null.- Parameters:
profile
- the profile to check- Returns:
- whether the profile is considered valid
-
setFromInternalObject
public abstract void setFromInternalObject(Object internalProfile) throws IllegalArgumentException
Sets fields/values of the profile object from an implementation-defined representation of profiles. This method is overridden by each implementation. If no internal implementation is available, providers should take CompatibleProfile itself instead of an exception. An IllegalArgumentException may be thrown if the object type is incorrect.- Parameters:
internalProfile
- implementation-defined profile representation.- Throws:
IllegalArgumentException
- when the parameter was not an internal type used by the current provider.
-
toInternalObject
public abstract Object toInternalObject()
Gets an implementation-defined representation for the profile information. If no internal implementation is available, providers should return CompatibleProfile itself instead of null/exception- Returns:
- the implementation-defined profile object.
-
hasId
public boolean hasId()
whether the id is present (not null)- Returns:
- whether the id is present (not null)
-
hasName
public boolean hasName()
whether the username is present (not null)- Returns:
- whether the username is present (not null)
-
hasTextures
public boolean hasTextures()
whether the texture string is present (not null)- Returns:
- whether the texture string is present (not null)
-
hasRequiredFields
public boolean hasRequiredFields()
Checks if the required profile fields are filled in this profile- Returns:
- whether the required fields are filled for the profile.
- Since:
- 5.2.14-SNAPSHOT
-
setId
public void setId(UUID id)
Set the UUID associated with the head profile. This should be either the UUID of a player or a unique ID for each head type.- Parameters:
id
- the ID to set
-
getName
@Nullable public String getName()
The username associated with the head profile.- Returns:
- the username
-
setName
public void setName(String name)
Set the username associated with the head profile.- Parameters:
name
- the username
-
getTextures
@Nullable public String getTextures()
Get the texture Base64 textures tag string associated with the profile.- Returns:
- textures string
-
setTextures
public void setTextures(@Nullable String texture)
Set the texture Base64 textures tag string associated with the profile.- Parameters:
texture
- textures string
-
hasOwner
public boolean hasOwner()
Whether the owner username is present equivalent to hasName() but provided for Bukkit similarity.- Returns:
- whether the owner username exists
-
getOwner
public String getOwner()
Get the owner username. equivalent to getName() but provided for Bukkit similarity.- Returns:
- the owner username
-
getOwningPlayer
public OfflinePlayer getOwningPlayer()
Gets the OfflinePlayer associated with the profile. Uses the same logic order that bukkit does: returns the ID-based Player if a player exists, OR the name-based player if a username exists, but only one will be checked.- Returns:
- the player, or null
-
-