Removing bow from skeleton on spawn

Discussion in 'Plugin Development' started by Signatured, Feb 25, 2015.

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

    Signatured

    I'm trying to remove an item from a skeletons hand, but the way I'm doing it isn't working. Here is my code:
    Code:java
    1.  
    2. Skeleton skele = (Skeleton) player.getWorld().spawnEntity(loc, EntityType.SKELETON);
    3. skele.setCustomName(name);
    4. skele.setCustomNameVisible(true);
    5.  
    6. skele.getEquipment().setHelmet(null);
    7. skele.getEquipment().setChestplate(null);
    8. skele.getEquipment().setLeggings(null);
    9. skele.getEquipment().setBoots(null);
    10.  
    11. ItemStack air = new ItemStack(Material.AIR);
    12. if (player.getEquipment().getItemInHand() != null || player.getEquipment().getItemInHand() != air) skele.getEquipment().setItemInHand(hand);
    13. if (player.getEquipment().getHelmet() != null || player.getEquipment().getItemInHand() != air) skele.getEquipment().setHelmet(helm);
    14. if (player.getEquipment().getHelmet() != null || player.getEquipment().getItemInHand() != air) skele.getEquipment().setChestplate(chest);
    15. if (player.getEquipment().getHelmet() != null || player.getEquipment().getItemInHand() != air) skele.getEquipment().setLeggings(legs);
    16. if (player.getEquipment().getHelmet() != null || player.getEquipment().getItemInHand() != air) skele.getEquipment().setBoots(boots);
    17.  
    However, even with this, the skeleton still has a bow in its hand. Any ideas?
     
  2. maybe you could create your own skeleton with nms?
     
  3. Offline

    Gingerbreadman

  4. Offline

    AlphaRLee

    It's possible to use an NMS skelly, though I'm sure there's an easier bukkit answer...quite ironically though, when you use an ingame command like /summon, skeletons don't get bows.

    And maybe it's just me, but between lines 6-9, I only read helmet, chestplate, leggings, and boots...can you point to me where you set the equipment to be null?
     
  5. Code:
    if (player.getEquipment().getItemInHand() != null || player.getEquipment().getItemInHand() != air)
    this if will always be executed. if iteminhand!=null fits always if iteminhand is something. so it also fits when iteminhand == air. your relationship is || (or). so if it is not null it is executed. if it is null it also isnt air (!= air) so it will be executed anyway. you could also write if(true) or just leave the if :D think you trolled yourself there dude
     
  6. Offline

    AlphaRLee

    Building off of what Shmobi said, you're always executing that statement. If you're unsure and you're covering all possible grounds, I recommend just doing a trial and error: test removing the if(null) half and see if it still works. If yes, congrats. If not, insert the null and only the null side.

    And I think you need this line in the beginning, I haven't seen it yet:
    Code:
    skele.getEquipment().setItemInHand(null);
    //Or, if that doesn't work,
    skele.getEquipment().setItemInHand(new Itemstack (Material.AIR));
     
Thread Status:
Not open for further replies.

Share This Page