Checking for Wither Skeleton

Discussion in 'Resources' started by chasechocolate, Jan 12, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    chasechocolate

    So you are probably wondering, "How do I check if this skeleton is a Wither Skeleton?" Here is how you solve that. If you are using this in a specific event here is how you should do it (for the sake of this tutorial, I will be using PlayerInteractEntityEvent to check when a player clicks a Wither Skeleton):
    Code:java
    1. @EventHandler
    2. public void onPlayerInteractEntity(PlayerInteractEntityEvent event){
    3. //Initialize the variables
    4. Player player = event.getPlayer();
    5. Entity entity = event.getRightClicked();
    6. //Check if the entity is a skeleton
    7. if(entity instanceof Skeleton){
    8. //Skeleton variable
    9. Skeleton skeleton = (Skeleton) entity;
    10. //Check if the skeleton is a Wither Skeleton
    11. if(skeleton.getSkeletonType() == SkeletonType.WITHER){
    12. //The skeleton is a Wither Skeleton
    13. player.sendMessage(ChatColor.GREEN + "You just right-clicked a wither skeleton!");
    14. }
    15. }
    16. }

    But basically the method is the same for anything else.
    Code:java
    1. if(<yourEntity> instanceof Skeleton){
    2. //Skeleton variable
    3. Skeleton skeleton = (Skeleton) <yourEntity>;
    4. //Check if the skeleton is a Wither Skeleton
    5. if(skeleton.getSkeletonType() == SkeletonType.WITHER){
    6. //The skeleton is a Wither Skeleton
    7. }
    8. }
     
    redside100 likes this.
  2. I fucking love you.
     
    redside100 and chasechocolate like this.
Thread Status:
Not open for further replies.

Share This Page