Checking Sheeps Dye Colour

Discussion in 'Plugin Development' started by DatCookiez, May 30, 2013.

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

    DatCookiez

    Hey guys!
    I was just wondering if there was a way to check a sheeps colour. I am wanting to give the player a certain drop when they kill a red sheep.

    Thanks!
     
  2. Offline

    xize

    you can do this:)

    Code:java
    1.  
    2. @EventHandler
    3. public void test(EntityDeathEvent e) {
    4. if(e.getEntity() instanceof Sheep) {
    5. Sheep sheep = (Sheep) e.getEntity();
    6. if(sheep.getColor() == DyeColor.RED) {
    7. ItemStack item = new ItemStack(Material.CAKE);
    8. item.setAmount(1);
    9. sheep.getLocation().getWorld().dropItemNaturally(sheep.getLocation(), item);
    10. } else {
    11. return;
    12. }
    13. } else {
    14. return;
    15. }
    16. }
    17.  
     
  3. Offline

    DatCookiez

    xize Thank you. Also, how would I be able to remove the wool that drops from the sheep too?
     
  4. realiez
    Clear the drops list from the event, e.getDrops().clear();
     
  5. Offline

    DatCookiez

    Digi It dosent have the getDrops() for me. Its a shear event btw
     
  6. Offline

    DatCookiez

    sheared.getWorld().dropItemNaturally(sheared.getLocation(),newItemStack(Material.IRON_LEGGINGS));
    e.setCancelled(true);
     
  7. Offline

    xize

    you can do this like:

    Code:java
    1.  
    2. @EventHandler
    3. public void test(EntityDeathEvent e) {
    4. if(e.getEntity() instanceof Sheep) {
    5. Sheep sheep = (Sheep) e.getEntity();
    6. if(sheep.getColor() == DyeColor.RED) {
    7. ItemStack item = new ItemStack(Material.CAKE);
    8. item.setAmount(1);
    9. sheep.getLocation().getWorld().dropItemNaturally(sheep.getLocation(), item);
    10. for(ItemStack drop : e.getDrops()) {
    11. if(drop.getType() == Material.WOOL) {
    12. drop.setType(Material.AIR);
    13. }
    14. }
    15. } else {
    16. return;
    17. }
    18. } else {
    19. return;
    20. }
    21. }
    22.  


    edit I'm ninja'ed digi is correct, you can try the for each loop but that's not needed if you can clear it.
     
  8. Offline

    DatCookiez

  9. Offline

    xize

    just use this:

    Code:java
    1.  
    2. @EventHandler
    3. public void test(EntityDeathEvent e) {
    4. if(e.getEntity() instanceof Sheep) {
    5. Sheep sheep = (Sheep) e.getEntity();
    6. if(sheep.getColor() == DyeColor.RED) {
    7. ItemStack item = new ItemStack(Material.CAKE);
    8. item.setAmount(1);
    9. sheep.getLocation().getWorld().dropItemNaturally(sheep.getLocation(), item);
    10. e.getDrops().clear();
    11. } else {
    12. return;
    13. }
    14. } else {
    15. return;
    16. }
    17. }
    18.  


    you don't have to need to stop the event ;)
     
  10. xize
    You don't have e.getDrops() in shear event.

    realiez
    You already posted a code where you cancel it... what more do you want ?
     
Thread Status:
Not open for further replies.

Share This Page