API Documentation/Example 02: Working with heads

Assuming you've completed the previous example and you've gotten an instance to the PlayerHeads API object, we can begin working with heads.  The following are [non-exhaustive] examples of head operations.

Spawning a head

For an entity

ItemStack stack = ph_api.getHeadDrop(entity);

For a mob in the current server verson

HeadType type = ph_api.getHeadOf(EntityType.ZOMBIE);
if(type==null) throw new IllegalArgumentException("Head not supported by PH");
ItemStack stack = ph_api.getHeadItem(type,1);

For a user

ItemStack stack = ph_api.getHeadItem(player, 1, false); // get head of specific player - OR
ItemStack stack = ph_api.getBoringPlayerheadItem(1); // get generic Player head

Determining the type of a head

HeadType type = ph_api.getHeadFrom(itemstack_or_blockstate);//get comparable type
if(type==null) throw new IllegalArgumentException("Head not supported by PH");

//Comparing to another head
HeadType type2 = ph_api.getHeadOf(EntityType.ZOMBIE);
if(type.equals(type2)) getLogger().info("Zombie head detected!");

//Getting the type name (Entity Type) of a head (for newest server version)
String typename = type.toEnum().name();//get internal head name. v5.0+
//String typename = ((Enum) type).name();//get internal head name. v4.10+
getLogger().info("PlayerHeads head: "+typename);

 

 

(currently being written - check back soon!)