Skip to content

Instantly share code, notes, and snippets.

@jamezrin jamezrin/EntityUtils.java
Last active Jun 28, 2016

Embed
What would you like to do?
Method utility to get the skull of an entity
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Skeleton;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class EntityUtils {
public static ItemStack getSkull(Entity entity) {
EntityType type = entity.getType();
ItemStack item = new ItemStack(Material.SKULL_ITEM);
switch (type) {
case SKELETON: {
if (((Skeleton) entity).getSkeletonType() == Skeleton.SkeletonType.NORMAL) {
item.setDurability((short) 0);
} else {
item.setDurability((short) 1);
}
break;
}
case ZOMBIE: {
item.setDurability((short) 2);
break;
}
case CREEPER: {
item.setDurability((short) 4);
break;
}
default: {
item.setDurability((short) 3);
SkullMeta meta = (SkullMeta) item.getItemMeta();
switch (type) {
case BLAZE: {
meta.setOwner("MHF_Blaze");
break;
}
case CAVE_SPIDER: {
meta.setOwner("MHF_CaveSpider");
break;
}
case CHICKEN: {
meta.setOwner("MHF_Chicken");
break;
}
case COW: {
meta.setOwner("MHF_Cow");
break;
}
case ENDERMAN: {
meta.setOwner("MHF_Enderman");
break;
}
case GHAST: {
meta.setOwner("MHF_Ghast");
break;
}
case IRON_GOLEM: {
meta.setOwner("MHF_Golem");
break;
}
case MAGMA_CUBE: {
meta.setOwner("MHF_LavaSlime");
break;
}
case MUSHROOM_COW: {
meta.setOwner("MHF_MushroomCow");
break;
}
case OCELOT: {
meta.setOwner("MHF_Ocelot");
break;
}
case PIG: {
meta.setOwner("MHF_Pig");
break;
}
case PIG_ZOMBIE: {
meta.setOwner("MHF_PigZombie");
break;
}
case SHEEP: {
meta.setOwner("MHF_Sheep");
break;
}
case SLIME: {
meta.setOwner("MHF_Slime");
break;
}
case SPIDER: {
meta.setOwner("MHF_Spider");
break;
}
case SQUID: {
meta.setOwner("MHF_Squid");
break;
}
case VILLAGER: {
meta.setOwner("MHF_Villager");
break;
}
default: {
meta.setOwner(entity.getName());
}
}
item.setItemMeta(meta);
}
}
return item;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.